原博主:http://xiaoshuaigege.blog.51cto.com/6217242/1967134linux
Cobbler项目是在2008年由RedHat发布的网络安装服务器套件。是一种快速网络安装linux操做系统的服务,支持众多的Linux发行版:Red Hat、Fedora、CentOS、Debian、Ubuntu和SuSE,也能够支持网络安装windows。git
PXE 是由Intel开发的技术,基于Client/Server的网络模式,支持远程主机经过网络从远端服务器下载映像,并由此支持经过网络启动操做系统。也能够实现经过网络批量的安装操做系统。github
Cobbler 正是基于PXE的二次封装,将多种安装参数封装到一个菜单当中。Cobbller提供了CLI和WEB两种安装方式,使用起来更加的友好。web
关于Cobbler的工做流程,能够用下面的图进行归纳。redis
由于咱们正在搭建的是网络服务,因此须要有至少两台主机,其中一台主机承担服务器的角色。我在在这个实验中,使用的CentOS 7 搭建的网络服务,承担Server角色。windows
防火墙和SELinux 在实验过程当中有可能会致使意想不到的问题,因此咱们这里将其关闭,实际生产中,请根据本身的实际状况进行调整。至于关闭防火墙和SELinux就不列出了,这很简单。centos
Cobbler 默认不在附带在光盘中,因此要经过EPEL源进行下载安装。 配置好epel源之后,执行
yum install cobbler
就能够安装Cobbler了。
在安装好Cobbler以后,咱们就会发现,Cobbler还附带安装了不少其余的服务,以下图所示 。这也就是解释了在Cobbler的工做流程中为何可以用到那么多服务,从图中能够看出,还缺乏DHCP服务,因此接下里咱们也要安装一下。其中,syslinux 就是安装的就是PXE服务。服务器
将Cobbler服务设为开机启动网络
systemctl enable cobblerd systemctl start cobblerd
将tftp 设为开机启动app
systemctl enable tftp systemctl start tftp
将http 设为开机启动
systemctl enable httpd systemctl start httpd
安装DHCP服务 为稍后使用Cobbler来管理DHCP作准备
在稍后,咱们会利用Cobbler来自动管理DHCP。
yum install dhcp
Cobbler Check
命令可以很是迅速的帮助咱们找到目前环境中还缺乏的配置,而后咱们根据这里的提示进行相应的配置调整。 这里出现了不少的问题,看到以后不要惊慌,根据提示一点一点去处理就行了。另外,由于实际生产环境中,全部的主机都会有所不一样,因此这里的提示信息应该也会有所不一样,咱们这里只是根据实验环境进行解决,其他的问题,能够留言一块儿讨论。
# 执行Cobbler check 检查目前环境还缺乏哪些东西 [root@localhost ~]#cobbler check The following are potential configuration items that you may want to fix: 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 : change 'disable' to 'no' in /etc/xinetd.d/tftp 4 : 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. 5 : enable and start rsyncd.service with systemctl 6 : debmirror package is not installed, it will be required to manage debian deployments and repositories 7 : 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 8 : 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.
首先咱们来看第一个问题。信息提示,在
/etc/cobbler/settings
这个配置文件中的server 字段必定要有一个其余主机可以访问到的主机名或者IP地址,不然KickStart的一些特性将没法使用。其实也很好理解,咱们目前的主机是用来提供网络服务的。其余主机经过访问咱们的Cobbler服务,进行下载安装操做系统,若是咱们的Server字段别人不能访问,那怎么能够呢! 因此打开该配置文件,修改server字段为本机的IP地址。
修改完成以后,咱们注意到,以前的提示信息末尾有一段提示信息
Restart cobblerd and then run 'cobbler sync' to apply changes.
,因此咱们运行一下这两个命令。
#重启服务 [root@localhost ~]#systemctl restart cobblerd #同步信息 [root@localhost ~]#cobbler sync ........... # 中间省略输出信息 # 从新检查一遍,看看还缺乏哪些东西。 [root@localhost ~]#cobbler check The following are potential configuration items that you may want to fix: 1 : 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. 2 : 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. 3 : enable and start rsyncd.service with systemctl 4 : debmirror package is not installed, it will be required to manage debian deployments and repositories 5 : 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 6 : 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.
从新检查以后,咱们发现解决了2个问题。而后咱们接着来看第一个问题。这个问题是说,next_server 字段也应该是一个具体的地址,而不该该是127.0.0.1.其实这个问题和上面咱们修改过的问题是同样的。因此咱们从新将next_server的地址修改成咱们本机的地址。
修改以后,从新启动服务,并进行同步。
#重启服务 [root@localhost ~]#systemctl restart cobblerd #同步信息[root@localhost ~]#cobbler sync ........... # 中间省略输出信息 # 从新检查一遍,看看还缺乏哪些东西。 [root@localhost ~]#cobbler check The following are potential configuration items that you may want to fix: 1 : 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. 2 : enable and start rsyncd.service with systemctl 3 : debmirror package is not installed, it will be required to manage debian deployments and repositories 4 : 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 5 : 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.
出现的问题继续减小了。咱们接着来看第一个信息。这个信息是说,在
/var/lib/cobbler/loaders
路径下,少了一些必须的文件,可使用cobbler get-loaders
命令从网络中下载相关的文件。因此,接下来咱们运行一下cobbler get-loaders
# 能够看到 /var/lib/cobbler/loaders 目录下没有任何内容 [root@localhost ~]#ls /var/lib/cobbler/loaders [root@localhost ~]#cobbler get-loaders task started: 2017-09-20_084605_get_loaders task started (id=Download Bootloader Content, time=Wed Sep 20 08:46:05 2017)downloading https://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/README downloading https://cobbler.github.io/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo downloading https://cobbler.github.io/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot downloading https://cobbler.github.io/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux downloading https://cobbler.github.io/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi downloading https://cobbler.github.io/loaders/yaboot-1.3.17 to /var/lib/cobbler/loaders/yaboot downloading https://cobbler.github.io/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0 downloading https://cobbler.github.io/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32 downloading https://cobbler.github.io/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi downloading https://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi *** TASK COMPLETE ***
此时查看
/var/lib/cobbler/loaders
目录下,会发现,已经下载了不少的内容。而后重启和同步服务,并运行cobbler check
查看还剩下一些什么问题,咱们接着一个个去解决。
#这个目录下最关键的文件就是 menu.c32 pxelinux.0 [root@localhost ~]#ls /var/lib/cobbler/loaders COPYING.elilo COPYING.yaboot grub-x86_64.efi menu.c32 README COPYING.syslinux elilo-ia64.efi grub-x86.efi pxelinux.0 yaboot [root@localhost ~]#cobbler check The following are potential configuration items that you may want to fix: 1 : enable and start rsyncd.service with systemctl 2 : debmirror package is not installed, it will be required to manage debian deployments and repositories 3 : 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 4 : 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.
接下来,我来看剩下的问题。前两个问题不是很重要,咱们先忽略过去。来看第三个问题,这个问题是说,应该为每个新安装的主机设置一个默认的用户口令。而且信息中提示了使用
openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'
命令来生成加密的用户口令。 若是不设置,默认的用户口令就是
cobbler
。
#生成密码是123456 的用户口令 [root@localhost ~] openssl passwd -1 123456$1$wuX5VyFf$a0Y/HdzHRCbVWhSFnbV8n/
而后将生成的口令替换到
/etc/cobbler/settings
中default_password_crypted
字段中。
从新启用并同步服务,而后看看还有什么问题。
[root@localhost ~]#cobbler check The following are potential configuration items that you may want to fix: 1 : enable and start rsyncd.service with systemctl 2 : debmirror package is not installed, it will be required to manage debian deployments and repositories 3 : 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.
fencing tools
是在集群环境中才会使用到的工具,咱们暂且先不用管。这样一来,关于Cobbler的check
工做咱们就完成了。
咱们利用DHCP的cobbler 功能来自动管理DHCP,修改
/etc/cobbler/settings
配置文件中的manage_dhcp
字段。 设置为1,则由Cobbler 来管理DHCP
/etc/cobbler/dhcp.template
模板文件
/etc/cobbler/dhcp.template
这个文件是配置DHCP的内容的。可是这个文件是Cobbler来提供的。也就是说,配置好了这个文件,从新启动Cobbler 服务,Cobbler就会自动地替咱们管理DHCP。
# 在/etc/cobbler/dhcp.template 找到下面地这段内容进行修改整理。 # 按照本身地要求进行DHCP地配置。 subnet 172.18.2.0 netmask 255.255.255.0 { option subnet-mask 255.255.255.0; range dynamic-bootp 172.18.2.100 172.18.2.254; default-lease-time 21600; max-lease-time 43200; next-server $next_server; class "pxeclients" { match if substring (option vendor-class-identifier, 0, 9) = "PXEClient"; if option pxe-system-type = 00:02 { filename "ia64/elilo.efi"; } else if option pxe-system-type = 00:06 { filename "grub/grub-x86.efi"; } else if option pxe-system-type = 00:07 { filename "grub/grub-x86_64.efi"; } else { filename "pxelinux.0"; } }}
从新启动和同步Cobbler 服务。
# 从新启动服务 [root@localhost ~]#systemctl restart cobblerd [root@localhost ~]#cobbler sync ........#中间省略不少输出 #查看DHCP的配置文件 [root@localhost ~]#cat /etc/dhcp/dhcpd.conf # ****************************************************************** # Cobbler managed dhcpd.conf file # generated from cobbler dhcp.conf template (Wed Sep 20 01:36:15 2017) # Do NOT make changes to /etc/dhcpd.conf. Instead, make your changes # in /etc/cobbler/dhcp.template, as /etc/dhcpd.conf will be # overwritten. # ****************************************************************** ddns-update-style interim; allow booting; allow bootp; ignore client-updates;set vendorclass = option vendor-class-identifier; option pxe-system-type code 93 = unsigned integer 16; subnet 172.18.2.0 netmask 255.255.255.0 { option subnet-mask 255.255.255.0; range dynamic-bootp 172.18.2.100 172.18.2.254; default-lease-time 21600; max-lease-time 43200; next-server 172.18.2.77; class "pxeclients" { match if substring (option vendor-class-identifier, 0, 9) = "PXEClient"; if option pxe-system-type = 00:02 { filename "ia64/elilo.efi"; } else if option pxe-system-type = 00:06 { filename "grub/grub-x86.efi"; } else if option pxe-system-type = 00:07 { filename "grub/grub-x86_64.efi"; } else { filename "pxelinux.0"; } }} # group for Cobbler DHCP tag: default group { }
与PXE不一样,Cobbler能够自动帮助咱们生成系统安装的yum 源,而不须要咱们本身去制做,咱们只要指定光盘路径就行了
# 执行下面的命令制做 CentOS 7.3 的启动光盘 [root@localhost ~]#cobbler import --path=/misc/cd --name=centos7.3 # 而后更换ISO镜像,制做6.9的光盘内容 [root@localhost ~]#cobbler import --path=/misc/cd --name=centos6.9
#进入到下面的这个路径下,能够看到这里生成了两个源,其实也就是将光盘里的内容复制过来了而已。 [root@localhost ~]#cd /var/www/cobbler/ks_mirror/ [root@localhost ks_mirror]#ls centos6.9 centos7.3 config # 执行下面的命令能够看到,这里已经成功的制做了两个系统yum源。 [root@localhost ks_mirror]#cobbler distro list centos6.9-x86_64 centos7.3-x86_64
yum 源文件建立成功以后,能够进行自定义的配置修改。
# 查看生成的启动菜单文件 [root@localhost tftpboot]#cat /var/lib/tftpboot/pxelinux.cfg/default DEFAULT menu PROMPT 0 MENU TITLE Cobbler | http://cobbler.github.io/ #能够修改成本身的标签。 TIMEOUT 200 TOTALTIMEOUT 6000 ONTIMEOUT local LABEL local MENU LABEL (local) MENU DEFAULT LOCALBOOT -1 LABEL centos6.9-x86_64 kernel /p_w_picpaths/centos6.9-x86_64/vmlinuz MENU LABEL centos6.9-x86_64 append initrd=/p_w_picpaths/centos6.9-x86_64/initrd.img ksdevice=bootif lang= kssendmac text ks=http://172.18.2.77/cblr/svc/op/ks/profile/centos6.9-x86_64 ipappend 2 LABEL centos7.3-x86_64 kernel /p_w_picpaths/centos7.3-x86_64/vmlinuz MENU LABEL centos7.3-x86_64 append initrd=/p_w_picpaths/centos7.3-x86_64/initrd.img ksdevice=bootif lang= kssendmac text ks=http://172.18.2.77/cblr/svc/op/ks/profile/centos7.3-x86_64 ipappend 2 MENU end
从新新建一个虚拟机,做为客户端,而后启动网络安装,就能够看到咱们刚刚制做的界面了。
在上面的实验中,咱们没有进行任何的安装配置,所有都是Cobbler帮助咱们完成的。但是在实际生产中,咱们对每台主机的硬盘分区,安装的软件都有相应的要求,因此咱们须要本身来定制KickStart文件,这样咱们就可以定制地批量安装操做系统了。
咱们就利用实验环境(CentOS 7.3)中的KickStart文件来定制咱们本身的KickStart文件。
# 首先进入到Cobbler 的KickStart 目录下 [root@localhost] cd /var/lib/cobbler/kickstarts/ # 将根目录下的ks 文件复制到当前目录下 [root@localhost kickstarts]cp /root/anaconda-ks.cfg centos7.cfg [root@localhost kickstarts]#cat centos7.cfg #version=DEVEL # System authorization information auth --enableshadow --passalgo=sha512 # Use CDROM installation mediaurl --url=$tree # url能够指定详细路径也可使用$tree变量来进行替代 # Use graphical install reboot #安装成功以后能够重启 text #采用字符界面进行安装 # Run the Setup Agent on first boot firstboot --enable ignoredisk --only-use=sda # Keyboard layouts keyboard --vckeymap=us --xlayouts='us' # System language lang en_US.UTF-8 # Network information #修改网络环境 network --bootproto=dhcp --device=ens33 --onboot=yes --ipv6=auto --activate network --hostname=localhost.localdomain selinux --disabled #禁用SElinux 也能够禁用防火墙 # Root password #设置root用户的初始密码rootpw --iscrypted $6$BlwRFg7fgO1i8eQa$F9yjtePt1aOnsIwmNO7mexdnBOsJTVSSyTnwp2hS2lSY87thmNylXw43.Ycj6lfY1wk2NmoQjO/WzEEGBUlZt. # System services services --disabled="chronyd" # System timezone timezone Asia/Shanghai --isUtc --nontp # X Window System configuration information xconfig --startxonboot # System bootloader configuration bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda # Partition clearing information zerombr #清楚MBR分区 clearpart --all #清楚系统中原有分区 # Disk partitioning information part / --fstype="xfs" --ondisk=sda --size=56320 part swap --fstype="swap" --ondisk=sda --size=2000 part /app --fstype="xfs" --ondisk=sda --size=51200 part /boot --fstype="xfs" --ondisk=sda --size=1024 %packages @^graphical-server-environment @base @core @desktop-debugging @dial-up @fonts @gnome-desktop @guest-agents @guest-desktop-agents @hardware-monitoring @input-methods @internet-browser @multimedia @print-client @x11 kexec-tools %end %post #删除旧的yum仓库#可根据实际状况稍做调整。 rm -rf /etc/yum.repos.d/* cat > /etc/yum.repos.d/base.repo <<EOF [base] name=base baseurl=file:///misc/cd gpgcheck=0 EOF %end
在Cobbler 自动建立了yum源以后,会自动有一个ks文件与该源相对应。如今咱们须要将本身制做的KS文件与原有的yum源进行关联。
# --name 咱们须要添加的启动菜单的名字 # --distro 咱们自定制的ks文件关联的yum库 # --kickstart 咱们自定制的ks文件的路径 [root@localhost kickstarts]#cobbler profile add --name=centos7.3-x86_64-desktop --distro=centos7.3-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.cfg # 查看Cobbler中如今还有多少个启动项 [root@localhost kickstarts]#cobbler profile list centos6.9-x86_64 centos7.3-x86_64 centos7.3-x86_64-desktop
在执行Cobbler sync 同步操做以后,Cobbler会自动的将
/var/lib/tftpboot/pxelinux.cfg/default
文件从新生成,因此,最好从新按照本身的需求修改一下这个文件。而后就能够开始进行网络安装操做系统了。
从图中能够清楚地看到咱们新增地一个启动选项。至此,咱们搭建Cobbler 的环境就成功了。
在实际生产中,通常是局域网环境,因此在配置DHCP服务的时候,要注意局域网的工做环境。
Cobbler实际上就是对PXE的封装,它帮助咱们实现了不少的内容,免去了咱们不少的手动配置,可是这样的话,咱们也不能清楚的了解底层的运行机制,出了问题,不便于处理,因此最好仍是尝试手动配置一下PXE来搭建网络操做系统安装环境,以便了解的更详细一下其中的运行机制。
最好手动配置ks文件,这样可以最大限度上定制本身的集群操做系统。
Cobbler 其实还支持基于Web的管理方式。在配置好Cobbler 服务环境以后,安装一个
cobbler-web
的软件包,而后就能够进行相应的配置管理了,这里咱们不作详细介绍,感兴趣的朋友能够去查阅一下资料。 Cobbler_web 的图形管理界面以下图所示,从图中咱们可以看到咱们本身指定的菜单和系统yum源。
经过上面的操做,咱们已经可以彻底搭建一个基于Cobbler的网络服务,用来给生产环境中批量的安装操做系统了。