Cobbler简介
Cobbler is a Linux installation server that allows for rapid setup of network installation environments. It glues together and automates many associated Linux tasks so you do not have to hop between many various commands and applications when deploying new systems, and, in some cases, changing existing ones. Cobbler can help with provisioning, managing DNS and DHCP, package updates, power management, configuration management orchestration, and much more.——不一样的补鞋匠
首先来看看补鞋匠的宣言,补鞋匠是一个基于linux系统的网络安装服务器,通过简单的配置就能轻松的完成系统和服务的自动化部署,避免了繁琐的命令行操作,同时还可实现DNS、DHCP、TFTP、版本仓库,电源管理等服务的集中管理,实则是装机必备的神器,一句话概括,哥就是不一样的补鞋匠。
安装步骤
原理上篇讲得很详细,直接开战吧!
1.环境准备
查看系统版本内核及IP
[root@linux-node1 ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) [root@linux-node1 ~]# uname -r 3.10.0-327.18.2.el7.x86_64 [root@linux-node1 ~]# ifconfig eth0|awk -F "[ :]+" 'NR==2{print $3}' 192.168.56.11
关闭SELINUX及防火墙
[root@linux-node1 ~]# getenforce Enforcing [root@linux-node1 ~]# setenforce 0 [root@linux-node1 ~]# sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config //改完重启生效 [root@linux-node1 ~]# systemctl stop firewalld [root@linux-node1 ~]# systemctl disable firewalld
2.安装Cobbler
[root@linux-node1 ~]# yum install cobbler cobbler-web dhcp tftp-server pykickstart httpd rsync xinetd –y cobbler #cobbler程序包 cobbler-web #cobbler的web服务包 pykickstart #cobbler检查kickstart语法错误 httpd #Apache web服务 tftp #tftp服务 dhcp #dhcp服务 /etc/cobbler # 配置文件目录 /etc/cobbler/settings # cobbler主配置文件 /etc/cobbler/dhcp.template # DHCP服务的配置模板 /etc/cobbler/tftpd.template # tftp服务的配置模板 /etc/cobbler/rsync.template # rsync服务的配置模板 /etc/cobbler/iso # iso模板配置文件目录 /etc/cobbler/pxe # pxe模板文件目录 /etc/cobbler/power # 电源的配置文件目录 /etc/cobbler/users.conf # Web服务授权配置文件 /etc/cobbler/users.digest # web访问的用户名密码配置文件 /etc/cobbler/dnsmasq.template # DNS服务的配置模板 /etc/cobbler/modules.conf # Cobbler模块配置文件 /var/lib/cobbler # Cobbler数据目录 /var/lib/cobbler/config # 配置文件 /var/lib/cobbler/kickstarts # 默认存放kickstart文件 /var/lib/cobbler/loaders # 存放的各种引导程序 /var/www/cobbler # 系统安装镜像目录 /var/www/cobbler/ks_mirror # 导入的系统镜像列表 /var/www/cobbler/images # 导入的系统镜像启动文件 /var/www/cobbler/repo_mirror # yum源存储目录 /var/log/cobbler # 日志目录 /var/log/cobbler/install.log # 客户端系统安装日志 /var/log/cobbler/cobbler.log # cobbler日志 [root@linux-node1 ~]# systemctl start httpd [root@linux-node1 ~]# systemctl start cobblerd [root@linux-node1 ~]# cobbler check //安装成功后运行检查命令 1 : The 'server' field in /etc/cobbler/settings must be set to something other than localhost, or kickstarting features will not work. This should be a resolvable hostname or IP for the boot server as reachable by all machines that will use it. 2 : For PXE to be functional, the 'next_server' field in /etc/cobbler/settings must be set to something other than 127.0.0.1, and should match the IP of the boot server on the PXE network. 3 : SELinux is enabled. Please review the following wiki page for details on ensuring cobbler works correctly in your SELinux environment: https://github.com/cobbler/cobbler/wiki/Selinux 4 : change 'disable' to 'no' in /etc/xinetd.d/tftp 5 : some network boot-loaders are missing from /var/lib/cobbler/loaders, you may run 'cobbler get-loaders' to download them, or, if you only want to handle x86/x86_64 netbooting, you may ensure that you have installed a *recent* version of the syslinux package installed and can ignore this message entirely. Files in this directory, should you want to support all architectures, should include pxelinux.0, menu.c32, elilo.efi, and yaboot. The 'cobbler get-loaders' command is the easiest way to resolve these requirements. 6 : enable and start rsyncd.service with systemctl 7 : debmirror package is not installed, it will be required to manage debian deployments and repositories 8 : The default password used by the sample templates for newly installed machines (default_password_crypted in /etc/cobbler/settings) is still set to 'cobbler' and should be changed, try: "openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'" to generate new one 9 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them Restart cobblerd and then run 'cobbler sync' to apply changes. 出现了N多问题,没关系我们来个个击破,治众如治寡,分数是也
3.更改配置文件
[root@linux-node1 ~]# vim /etc/cobbler/settings
384 server: 127.0.0.1 ==> server: 192.168.56.11 //①
272 next_server: 127.0.0.1 ==> next_server: 192.168.56.11 //②
242 manage_dhcp: 0 ==> manage_dhcp: 1 //让cobbler管理dhcp
[root@linux-node1 ~]# vi /etc/xinetd.d/tftp //④ change 'disable' to 'no' in /etc/xinetd.d/tftp
[root@linux-node1 ~]# cobbler get-loaders //⑤下载文件
[root@linux-node1 ~]# systemctl enable rsyncd.service //⑥ enable and start rsyncd.service with systemctl
[root@linux-node1 ~]# openssl passwd -1 -salt 'cobbler' 'cobbler' //⑧生成加盐密码
101 default_password_crypted: "$1$cobbler$M6SE55xZodWc9.vAKLJs6."//更改默认密码
[root@linux-node1 ~]# cobbler check
The following are potential configuration items that you may want to fix:
1 : debmirror package is not installed, it will be required to manage debian deployments and repositories
2 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them
Restart cobblerd and then run 'cobbler sync' to apply changes.
//1和2无关痛痒,略过,提示我们用cobbler sync来同步更新,不过我们还得先配置DHCP
4.配置DHCP
[root@linux-node1 ~]# sed -i 's#manage_dhcp: 0#manage_dhcp: 1#g' /etc/cobbler/settings //让cobbler管理dhcp [root@linux-node1 ~]# vim /etc/cobbler/dhcp.template subnet 192.168.56.0 netmask 255.255.255.0 { option routers 192.168.56.2; option domain-name-servers 192.168.56.2; option subnet-mask 255.255.255.0; range dynamic-bootp 192.168.56.100 192.168.56.254; default-lease-time 21600; max-lease-time 43200; next-server $next_server;
5.同步更新cobbler
[root@linux-node1 ~]# systemctl restart xinetd.service [root@linux-node1 ~]# systemctl restart cobblerd.service [root@linux-node1 ~]# cobbler sync //同步更新cobbler,会显示更改了哪些操作 [root@linux-node1 ~]# cat /etc/dhcp/dhcpd.conf //查看DHCP配置,已经同步过来了 subnet 192.168.56.0 netmask 255.255.255.0 { option routers 192.168.56.2; option domain-name-servers 192.168.56.2; option subnet-mask 255.255.255.0; range dynamic-bootp 192.168.56.100 192.168.56.254; default-lease-time 21600; max-lease-time 43200; next-server 192.168.56.11; //next-server也同步了过来
6.管理镜像
[root@linux-node1 ~]# mount /dev/cdrom /mnt //将系统镜像文件挂载到服务器 mount: /dev/sr0 is write-protected, mounting read-only [root@linux-node1 ~]# cobbler import --path=/mnt --name=CentOS-7.2-x86_64 --arch=x86_64 //导入文件 --path 镜像路径 --name 命名镜像 --arch 指定安装源是32位、64位、ia64, 目前支持的选项有: x86│x86_64│ia64 //镜像会拷贝到/var/www/cobbler/ks_mirror/CentOS-7.2-x86_64下,所以此目录要有足够的空间 [root@linux-node1 CentOS-7.2-x86_64]# ll /var/www/cobbler/ks_mirror/CentOS-7.2-x86_64/ total 296 -r--r--r--. 1 root root 14 Dec 10 06:35 CentOS_BuildTag dr-xr-xr-x. 3 root root 33 Dec 10 06:33 EFI -r--r--r--. 1 root root 215 Dec 10 06:35 EULA -r--r--r--. 1 root root 18009 Dec 10 06:35 GPL dr-xr-xr-x. 3 root root 54 Dec 10 06:33 images dr-xr-xr-x. 2 root root 4096 Dec 10 06:33 isolinux dr-xr-xr-x. 2 root root 41 Dec 10 06:33 LiveOS dr-xr-xr-x. 2 root root 204800 Dec 10 07:13 Packages dr-xr-xr-x. 2 root root 4096 Dec 10 07:14 repodata -r--r--r--. 1 root root 1690 Dec 10 06:35 RPM-GPG-KEY-CentOS-7 -r--r--r--. 1 root root 1690 Dec 10 06:35 RPM-GPG-KEY-CentOS-Testing-7 -r--r--r--. 1 root root 2883 Dec 10 07:14 TRANS.TBL //列出所有的镜像distros和配置文件profiles [root@linux-node1 ~]# cobbler list distros: CentOS-7.2-x86_64 profiles: CentOS-7.2-x86_64
7.配置profile
//更改默认的kickstart文件,首先将配置文件CentOS-7-x86_64.cfg上传到kickstarts配置文件目录 然后执行更改路径命令同时修改安装系统内核命令 [root@linux-node1 CentOS-7.2-x86_64]# cobbler profile edit --name=CentOS-7.2-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg [root@linux-node1 CentOS-7.2-x86_64]# cobbler profile edit --name=CentOS-7.2-x86_64 --kopts='net.ifnames=0 biosdevname=0' //查看更改后的profile信息 root@linux-node1 CentOS-7.2-x86_64]# cobbler profile report Name : CentOS-7.2-x86_64 TFTP Boot Files : {} Comment : DHCP Tag : default Distribution : CentOS-7.2-x86_64 Enable gPXE? : 0 Enable PXE Menu? : 1 Fetchable Files : {} Kernel Options : {'biosdevname': '0', 'net.ifnames': '0'} Kernel Options (Post Install) : {} Kickstart : /var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg 1.添加repo为所安装系统配置本地openstack的yum源,为后续学习做准备 [root@linux-node1 CentOS-7.2-x86_64]# cobbler repo add --name=openstack-mitaka --mirror=http://mirrors.aliyun.com/centos/7.2.1511/cloud/x86_64/openstack-mitaka/ --arch=x86_64 --breed=yum 2.同步repo,会远程下载yum源,会发费些许时间,等待,永远的等待,差不多下了15分钟,都快睡着了 [root@linux-node1 CentOS-7.2-x86_64]# cobbler reposync task started: 2016-06-02_082045_reposync task started (id=Reposync, time=Thu Jun 2 08:20:45 2016) hello, reposync run, reposync, run! creating: /var/www/cobbler/repo_mirror/openstack-mitaka/config.repo creating: /var/www/cobbler/repo_mirror/openstack-mitaka/.origin/openstack-mitaka.repo running: /usr/bin/reposync -l -n -d --config=/var/www/cobbler/repo_mirror/openstack-mitaka/.origin/openstack-mitaka.repo --repoid=openstack-mitaka --download_path=/var/www/cobbler/repo_mirror -a x86_64 3.添加repo到对应的profile [root@linux-node1 CentOS-7.2-x86_64]# cobbler profile edit --name=CentOS-7-x86_64 --repos=http://mirrors.aliyun.com/centos/7.2.1511/cloud/x86_64/openstack-mitaka/ //用cobbler profile report命令可以查看已经添加repo到profile Repos : ['http://mirrors.aliyun.com/centos/7.2.1511/cloud/x86_64/openstack-mitaka/'] 4.修改kickstart文件,添加启动或关闭服务的命令到%post %end中间 %post systemctl disable postfix.service $yum_config_stanza %end 想装机自动安装的软件写在%packages和%end之间 %packages @ base @ core sysstat iptraf ntp lrzsz ncurses-devel openssl-devel zlib-devel OpenIPMI-tools mysql nmap screen %end 5.添加定时任务,定期同步repo echo "1 3 * * * /usr/bin/cobbler reposync --tries=3 --no-fail" >> /var/spool/cron/root [root@linux-node1 CentOS-7.2-x86_64]# cobbler sync //配置完别忘了同步更新,很重要
8.自定义系统安装
用虚拟机模拟,使用NAT模式网络启动,关闭虚拟机网络DHCP功能,配置信息如下 测试虚拟机的MAC地址:00:0C:29:96:6F:80 IP:192.168.56.13 主机名:linux-node2.example.com 子网掩码:255.255.255.0 网关:192.168.56.2 DNS:192.168.56.2 root@linux-node1 ~]# cobbler system add --name=linux-node2.example.com --mac=00:0C:29:96:6F:80 --profile=CentOS-7.2-x86_64 \ --ip-address=192.168.56.13 --subnet=255.255.255.0 --gateway=192.168.56.2 --interface=eth0 \ --static=1 --hostname=linux-node2.example.com --name-servers="192.168.56.2" \ --kickstart=/var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg 启动虚拟机=========>自动安装,等待,永远的等待。。。。。。20分钟解决战斗,果断上图
效果图--获取MAC地址
效果图--开始自动化安装系统
效果图--安装系统软件及自定义软件
效果图--无需手动配置,一台自动配置好的服务器就诞生了,牛不牛
9.Koan重装系统和Cobbler_web
自动重装系统:<一定要在需要重装的机器上运行> [root@linux-node2 ~]# yum install -y koan [root@linux-node2 ~]# koan --server=192.168.56.11 --list=profiles - looking for Cobbler at http://192.168.56.11:80/cobbler_api CentOS-7-x86_64 CentOS-6-x86_64 指定要重装的系统 [root@linux-node2 ~]# koan --replace-self --server=192.168.56.11 --profile=CentOS-6-x86_64 如果把生产环境中现有的系统重装的话,估计老板会Kill you那么如何解决koan安装错误机器,或者cobbler自动化安装错误机器。 Cobbler是通过网络来进行系统安装的所有我们可以设定==>装机Vlan来防错。 Cobbler web操作很简单,就不演示了 Cobbler web修改密码: [root@linux-node1 cobbler]# htdigest /etc/cobbler/users.digest "Cobbler" cobbler
总结:
1.配置需要细心,总体来说没什么难度
2.事先做好安装规划,会大大提高效率
3.防止出错,做好措施
4.写脚本调用Cobber_api,可以将Cobber集成到别的工具上,那就威力更猛啦
15K python代码量的Cobbler能给你干这么多活,不得不服,果然是不一样的补鞋匠,看来得赶快去学学python啦!
参考:http://www.xuliangwei.com/xubusi/446.html