概述:
cobbler 实现自动化安装OS,是依赖于:网卡的PXE技术(dhcp client、tftp client ) + anaconda(linux上安装操作系统的程序) + dhcp(为需要安装操作系统的主机分配IP) + tftp(提供基于网卡引导时所需要的启动文件) + httpd(os install tree 的存放位置 ) 实现的。
使用 cobbler 的命令能够自动化地实现:
在tftp server 上提供基于网卡引导时所需要的程序文件
能够在 httpd 服务器的文档根目录下,自动生成安装操作OS时,所需要的install tree.
所以,使用cobbler 实现自动化安装OS,要安装:httpd、tftp、dhcp服务,还有rsync服务(cobbler可以从远程镜像install tree的)。
自动化安装OS原理如下图:
工作原理:
1、首先基于网卡的PXE技术引导启动目标机(需要安装OS的服务器):
(1)、支持PXE技术的网卡上的芯片的dhcp client 客户端,请求dhcp server分配IP地址.
(2)、dhcp server 会告诉客户端,Bootloader所在的服务器,以及引导文件是什么?
这样tftp client就知道了Bootloader的URL了。
(3)、需要安装OS的主机配置好IP后,tftp client 就联系tftp server 服务器请求基于
网卡引导启动OS所需要的文件。
(4)、在目标机(需要安装OS的服务器)启动内核,从而能够驱动目标机的磁盘,
就可以访问磁盘了。
2、启动完成以后,在用户空间启动anaconda 程序,该程序负责安装OS
当内核启动完成,通过/sbin/loader 启动anaconda系统安装程序,该程序就会读取
ks.cfg文件,ks.cfg文件中定义有安装源(install tree)所在的
位置和安装OS时的配置数据。这样就实现了自动化给服务器安装操作系统了。
cobbloer的安装树(install tree)的位置在httpd服务器上的。所以,ks.cfg文件中指定
安装源的URL就是httpd服务器的地址。
配置使用cobbler实现自动化安装OS所需要的程序包:
cobbler-2.4.0-1.el6.noarch cobbler服务程序包 cobbler-web.2.4.0-1.el6.noarch cobbler 提供的web gui 配置接口。
一、配置cobbler服务
1、启动cobbler和httpd服务
启动cobbler 服务
[root@localhost ~]# service cobblerd start Starting cobbler daemon: [ OK ]
查看cobbler 服务监听的端口
[root@localhost ~]# netstat -anptul | grep python tcp 0 0 127.0.0.1:25151 0.0.0.0:* LISTEN 1784/python
启动httpd服务
[root@localhost ~]# service httpd start Starting httpd: [ OK ]
2、cobbler正常工作所必须的条件:
(1)、使用cobbler提供的测试命令【cobbler check】测试cobbler 的环境
[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 : 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. 4 : change 'disable' to 'no' in /etc/xinetd.d/rsync 5 : debmirror package is not installed, it will be required to manage debian deployments and repositories 6 : ksvalidator was not found, install pykickstart 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.
(2)、解决测试出来的问题
解决第1个问题:设置cobbler server的地址/etc/cobbler/settings 文件中的【server】指令定义的
[root@localhost ~]# vim /etc/cobbler/settings server: 192.168.60.134
解决第2个问题:在cobbler的/etc/cobbler/settings配置文件指定tftp server 地址。
next_server: 192.168.60.134
解决第3个问题:缺少一些网络引导所需要的文件,如果只引导x86/x86_64。保证安装了syslinux 程序包就可以了。
[root@localhost ~]# yum install syslinux
解决第4个问题:要开启rsync服务
[root@localhost ~]# chkconfig rsync on [root@localhost ~]# chkconfig --list rsync rsync on
解决第5个问题:如果安装的是 debian 操作系统的话,需要把debmirrot包安装好。
[root@localhost admin]# yum install debmirror-2.14-2.el6.noarch.rpm perl-LockFile-Simple-0.207-2.el6.noarch.rpm
解决第6个问题:需要安装pykickstart程序
[root@localhost ~]# yum install pykickstart
解决第7个问题:因为安装系统时,要求设置管理员(root)密码。这里就是设置安装操作系统时,设置的管理员密码的。
[root@localhost ~]# openssl passwd -1 -salt 'abc' Password: $1$abc$FEGY5dR6AYgowx6hkRl2d/ [root@localhost ~]# vim /etc/cobbler/settings default_password_crypted: "$1$abc$FEGY5dR6AYgowx6hkRl2d/"
第8个问题,是可忽略的。
(3)、重新启动cobblerd服务
[root@localhost ~]# service cobblerd restart Stopping cobbler daemon: [ OK ] Starting cobbler daemon: [ OK ]
(4)、同步一下,让cobbler check 检测的环境是修改后的。
[root@localhost ~]# cobbler sync task started: 2014-10-05_214230_sync task started (id=Sync, time=Sun Oct 5 21:42:30 2014) running pre-sync triggers cleaning trees mkdir: /var/lib/tftpboot/pxelinux.cfg mkdir: /var/lib/tftpboot/grub mkdir: /var/lib/tftpboot/s390x mkdir: /var/lib/tftpboot/ppc mkdir: /var/lib/tftpboot/etc removing: /var/lib/tftpboot/grub/p_w_picpaths copying bootloaders --------> 自动复制基于网卡引导所需要的文件到tftp server的共享文件目录中。 copying: /usr/share/syslinux/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0 copying: /usr/share/syslinux/menu.c32 -> /var/lib/tftpboot/menu.c32 copying: /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk copying distros to tftpboot copying p_w_picpaths generating PXE configuration files -----> 自动产生基于PXE引导的配置文件 generating PXE menu structure rendering TFTPD files generating /etc/xinetd.d/tftp cleaning link caches running post-sync triggers running python triggers from /var/lib/cobbler/triggers/sync/post/* running python trigger cobbler.modules.sync_post_restart_services running shell triggers from /var/lib/cobbler/triggers/sync/post/* running python triggers from /var/lib/cobbler/triggers/change/* running python trigger cobbler.modules.scm_track running shell triggers from /var/lib/cobbler/triggers/change/* *** TASK COMPLETE ***
(5)、再检测是否满足cobbler工作所需要的环境
[root@localhost admin]# 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 : comment out 'dists' on /etc/debmirror.conf for proper debian support 3 : comment out 'arches' on /etc/debmirror.conf for proper debian support 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.
(6)、解决上述的问题:
[root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /usr/share/syslinux/menu.c32 /var/lib/cobbler/loaders/ [root@localhost ~]# ll /var/lib/cobbler/loaders/ total 88 -rw-r--r-- 1 root root 60928 Oct 5 22:14 menu.c32 -rw-r--r-- 1 root root 26828 Oct 5 22:14 pxelinux.0
注释掉debmirror.conf文件中指定配置选项
[root@localhost admin]# vim /etc/debmirror.conf #@arches="i386"; #@dists="sid";
(7)、再次检测
重新cobblerd 服务
[root@localhost admin]# service cobblerd restart Stopping cobbler daemon: [ OK ] Starting cobbler daemon: [ OK ] [root@localhost ~]# cobbler sync task started: 2014-10-05_221901_sync task started (id=Sync, time=Sun Oct 5 22:19:01 2014) running pre-sync triggers cleaning trees removing: /var/lib/tftpboot/pxelinux.cfg/default removing: /var/lib/tftpboot/grub/p_w_picpaths removing: /var/lib/tftpboot/grub/efidefault removing: /var/lib/tftpboot/s390x/profile_list copying bootloaders ------------------> 复制基于网卡启动的引导文件 trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0 copying: /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0 trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32 copying: /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32 copying: /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk copying distros to tftpboot copying p_w_picpaths generating PXE configuration files generating PXE menu structure rendering TFTPD files generating /etc/xinetd.d/tftp cleaning link caches running post-sync triggers running python triggers from /var/lib/cobbler/triggers/sync/post/* running python trigger cobbler.modules.sync_post_restart_services running shell triggers from /var/lib/cobbler/triggers/sync/post/* running python triggers from /var/lib/cobbler/triggers/change/* running python trigger cobbler.modules.scm_track running shell triggers from /var/lib/cobbler/triggers/change/* *** TASK COMPLETE ***
再次使用【cobbler check】命令检测,是否已经符合cabbler工作的环境
[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 : 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.
说明:
上述这两个问题可以忽略的。
二、配置dhcp server
1、复制样例配置文件到dhcp的配置文件目录下
[root@localhost ~]# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf cp: overwrite `/etc/dhcp/dhcpd.conf'? y
2、编辑dhcp的配置文件,让dhcp服务器为:192.168.60.0/32网络分配地址并且告诉dhcp 的客户端tftp server的IP地址以及从tftp server下载什么文件,
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf option domain-name "9527du.com"; option domain-name-servers www.9527du.com; default-lease-time 600; max-lease-time 7200; ----------> IP地址的租约时长 subnet 192.168.60.0 netmask 255.255.255.0 { range 192.168.60.78 192.168.60.167; --------->只负责分配这个段的IP option routers 192.168.60.134; } next_server 192.168.60.134; -----------> 指明tftp server 的地址 filename="pxelinux.0"; -----------> 联系 tftp server 服务器时,请求的文件。其实该文件就是基于网卡PXE技术引导启动OS的引导文件。
3、启动dhcp 服务
[root@localhost ~]# service dhcpd start Starting dhcpd: [ OK ]
4、查看dhcp 是否工作OK?
(1)、查看dhcp server 监听的端口
[root@localhost ~]# netstat -anptul | grep dhcpd udp 0 0 0.0.0.0:67 0.0.0.0:* 3193/dhcpd
(2)、查看dhcp输出的日志信息
[root@localhost ~]# tail -3 /var/log/messages Oct 5 22:39:24 localhost dhcpd: Listening on LPF/eth0/00:0c:29:59:35:18/192.168.60.0/24 Oct 5 22:39:24 localhost dhcpd: Sending on LPF/eth0/00:0c:29:59:35:18/192.168.60.0/24 Oct 5 22:39:24 localhost dhcpd: Sending on Socket/fallback/fallback-net
说明:
从上述,可以判断dhcp工作是OK的。
三、生成安装树(install tree)以及配置profile文件
1、查看tftp server 服务器的共享目录下是否有引导OS所需要的文件
[root@localhost ~]# cat /var/lib/tftpboot/pxelinux.cfg/default DEFAULT menu PROMPT 0 MENU TITLE Cobbler | http://www.cobblerd.org/ TIMEOUT 200 TOTALTIMEOUT 6000 ONTIMEOUT local LABEL local MENU LABEL (local) MENU DEFAULT LOCALBOOT -1 MENU end
是否有启用Linux所需要的:initrd和vmlinuz文件的。
[root@localhost ~]# ll /var/lib/tftpboot/p_w_picpaths/ total 0
2、为安装OS提供install tree
cobbler可以使用两种方式获取install tree:
A、使用sync 服务从远程同步install tree 到本地;
B、从OS安装光盘中导入安装源(install tree)
这里选择从OS安装光盘导入安装源
(1)、以只读方式挂载OS安装光盘
[root@localhost ~]# mount -ro /dev/cdrom /mnt/cdrom/ [root@localhost ~]# mount | grep cdrom /dev/sr0 on /mnt/cdrom type iso9660 (ro)
(2)、使用cobbler的import命令从OS安装光盘中导入(复制)install tree(安装OS所需要的程序包)
[root@localhost ~]# cobbler import --path=/mnt/cdrom/ --name=centos-6.5-x86_64 task started: 2014-10-05_223311_import task started (id=Media import, time=Sun Oct 5 22:33:11 2014) Found a candidate signature: breed=redhat, version=rhel6 Found a matching signature: breed=redhat, version=rhel6 Adding distros from path /var/www/cobbler/ks_mirror/centos-6.5-x86_64: ---------> 生成的OS镜像文件的目录 creating new distro: centos-6.5-x86_64 trying symlink: /var/www/cobbler/ks_mirror/centos-6.5-x86_64 -> /var/www/cobbler/links/centos-6.5-x86_64 creating new profile: centos-6.5-x86_64 associating repos checking for rsync repo(s) checking for rhn repo(s) checking for yum repo(s) starting descent into /var/www/cobbler/ks_mirror/centos-6.5-x86_64 for centos-6.5-x86_64 processing repo at : /var/www/cobbler/ks_mirror/centos-6.5-x86_64 need to process repo/comps: /var/www/cobbler/ks_mirror/centos-6.5-x86_64 looking for /var/www/cobbler/ks_mirror/centos-6.5-x86_64/repodata/*comps*.xml running: ceatererpo -c cache -s sha --groupfile /var/www/cobbler/ks_mirror/centos-6.5-x86_64/repodata/b4e0b9342ef85d3059ff095fa7f140f654c2cb492837de689a58c581207d9632-c6-x86_64-comps.xml /var/www/cobbler/ks_mirror/centos-6.5-x86_64 received on stdout: Spawning worker 0 with 3995 pkgs Workers Finished ---------------------------> 导入完成 Gathering worker results Saving Primary metadata Saving file lists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete received on stderr: *** TASK COMPLETE ***
说明:
其实,就是复制光盘中的的程序包到/var/www/cobbler目录下,
还生成一个配置文件/etc/httpd/conf.d/cobbler.conf。
如下图:
(3)、查看导入的安装树,也就是cabbler提供可安装的OS发行版。
[root@localhost ~]# cobbler distro list centos-6.5-x86_64
(4)、查看tftp 服务器的共享目录是否有了引导启动Linux所需要的文件
从OS安装光盘光盘导入时,同时会把内核vimlinuz和initrd.img复制到tftp server 共享目录下
[root@localhost ~]# tree /var/lib/tftpboot/p_w_picpaths/ /var/lib/tftpboot/p_w_picpaths/ └── centos-6.5-x86_64 ├── initrd.img └── vmlinuz 1 directory, 2 files
查看引导文件
[root@localhost ~]# cat /var/lib/tftpboot/pxelinux.cfg/default DEFAULT menu PROMPT 0 MENU TITLE Cobbler | http://www.cobblerd.org/ TIMEOUT 200 TOTALTIMEOUT 6000 ONTIMEOUT local LABEL local MENU LABEL (local) MENU DEFAULT LOCALBOOT -1 LABEL centos-6.5-x86_64 kernel /p_w_picpaths/centos-6.5-x86_64/vmlinuz MENU LABEL centos-6.5-x86_64 append initrd=/p_w_picpaths/centos-6.5-x86_64/initrd.img ksdevice=bootif lang= kssendmac text ks=http://192.168.60.134/cblr/svc/op/ks/profile/centos-6.5-x86_64 ipappend 2 MENU end
说明:
把kickstart文件做为参数传递给内核.
3、配置profile 文件,目的是让kickstarts文件与安装树install tree 关联起来。
由于安装OS时,会自动在/etc/ 目录下生成以.cfg结尾的文件,这就是kickstart文件。该文件保存了安装OS时,配置的所有参数。anaconda 程序就是根据该文件完成OS的自动化安装的。
(1)、提供kickstart文件:把kickstart文件复制到cobbler默认的kickstart文件存放目录。
[root@localhost ~]# cp anaconda-ks.cfg /var/lib/cobbler/kickstarts/
(2)、生成profile文件
[root@localhost ~]# cobbler profile add --name=centos-6.5-x86_64-basic --distro=centos-6.5-x86_64 --kickstart=/var/lib/cobbler/kickstarts/anaconda-ks.cfg
说明:
--distro 指定该kickstat文件关联的安装树install tree(也就是那个发行版的OS)是什么
--kickstart 指定kickstat文件
说白了,这个kickstat是为安装那个发行版使用的文件。
其实,就是在/var/lib/tftpboot/pxelinux.cfg/default 文件中加入一个条目:LABEL 。
(3)、列出cobbler有哪些profile文件。
[root@localhost ~]# cobbler profile list centos-6.5-x86_64 centos-6.5-x86_64-basic
查看default配置文件
[root@localhost ~]# cat /var/lib/tftpboot/pxelinux.cfg/default DEFAULT menu PROMPT 0 MENU TITLE Cobbler | http://www.cobblerd.org/ TIMEOUT 200 TOTALTIMEOUT 6000 ONTIMEOUT local LABEL local MENU LABEL (local) MENU DEFAULT LOCALBOOT -1 LABEL centos-6.5-x86_64 kernel /p_w_picpaths/centos-6.5-x86_64/vmlinuz MENU LABEL centos-6.5-x86_64 append initrd=/p_w_picpaths/centos-6.5-x86_64/initrd.img ksdevice=bootif lang= kssendmac text ks=http://192.168.60.134/cblr/svc/op/ks/profile/centos-6.5-x86_64 ipappend 2 LABEL centos-6.5-x86_64-basic kernel /p_w_picpaths/centos-6.5-x86_64/vmlinuz MENU LABEL centos-6.5-x86_64-basic append initrd=/p_w_picpaths/centos-6.5-x86_64/initrd.img ksdevice=bootif lang= kssendmac text ks=http://192.168.60.134/cblr/svc/op/ks/profile/centos-6.5-x86_64-baic ipappend 2 MENU end
说明:
从上述输出信息可分析,该cobbler提供了两个kickstart文件,也就是说安装OS时,要以选择安装:centos-6.5-x86_64 还是 centos-6.5-x86_64-basic
四、查看cobbler依赖的服务是否准备好?
[root@www ~]# chkconfig tftp on [root@www ~]# chkconfig --list tftp tftp on
查看
[root@localhost ~]# netstat -anptul | grep -e 'dhcpd' -e 'xinetd' -e 'httpd' tcp 0 0 :::80 :::* LISTEN 2209/httpd tcp 0 0 :::873 :::* LISTEN 1651/xinetd -----> rsync服务监听的端口 udp 0 0 0.0.0.0:67 0.0.0.0:* 3334/dhcpd udp 0 0 0.0.0.0:69 0.0.0.0:* 1651/xinetd ------> tftp server 监听的端口
五、测试cobbler
1、目标机的dhcp client 端连系 dhcp server分配IP地址
2、选择安装的发行版;
3、开始基于网卡引导启动OS
4、运行anaconda系统安装程序,安装OS
5、分区格式化硬盘:
5、检测安装的程序包的依赖关系;
5、从httpd服务器下载安装的程序包,进行安装
OK!!!