从事网游运维的兄弟们应该深有感触,往往在开新服的时候需要大批量的布署新的服务器,时间紧迫而且量大,装系统、初始化,枯燥而又乏味,有时还容易出错,为了解放我们的双手,所以要实现自动化,Red Hat 最新发布了网络安装服务器套件 Cobbler(补鞋匠)集成了PXE、DHCP、DNS、Kickstart服务管理和yum仓库管理工具,相对之前的 Kickstart 更加快捷、方便的批量布署red hat、centos类系统
一、安装软件
1、安装cobbler
[root@node1 ~]# yum install cobbler pykickstart debmirror
2、 其他服务的安装
额外需要的服务还有dhcp tftp,rsync,xinetd,httpd,syslinux。所以如果安装系统的时候如果这几个包没装上,请手动安装。
二、启动服务并检测cobbler
1、启动httpd和cobblerd服务
[root@node1 ~]# /etc/init.d/httpd start Starting httpd: httpd: apr_sockaddr_info_get() failed for node1 [ OK ] [root@node1 ~]# /etc/init.d/cobblerd start Starting cobbler daemon: [ OK ]
2、执行“cobbler check命令检查存的问题,逐一按提示解决:
[root@node1 ~]# 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 : comment out 'dists' on /etc/debmirror.conf for proper debian support 6 : comment out 'arches' on /etc/debmirror.conf for proper debian support 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 themRestart cobblerd and then run 'cobbler sync' to apply changes. 如上各问题的解决方法如下所示: 1、修改/etc/cobbler/settings文件中,server: 172.16.22.6; 2、修改/etc/cobbler/settings文件中,next_server: 172.16.22.6; 3、如果当前节点可以访问互联网,执行“cobbler get-loaders”命令即可;否则,需要安装syslinux程序包,执行: [root@node1 ~]# cp /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/cobbler/loaders/ 4、执行[root@node1 ~]# chkconfig rsync on 5、注释/etc/debmirror.conf文件中的“@dists="sid";”一行; 6、注释/etc/debmirror.conf文件中的“@arches="i386";”一行; 7、执行“openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'”生成密码,并用替换/etc/cobbler/settings文件中default_password_crypted参数的值,如default_password_crypted: "$1$random-p$AOw9RDIWQm6tfUo9Ediu/0"; 8、执行“yum -y install cman fence-agents”命令安装相应的程序包即可;
3、重启cobblerd服务,同步新的配置至cobbler,再次检测
[root@node1 ~]# /etc/init.d/cobblerd restart Stopping cobbler daemon: [ OK ] Starting cobbler daemon: [ OK ] [root@node1 ~]# cobbler sync task started: 2014-10-05_172520_sync task started (id=Sync, time=Sun Oct 5 17:25:20 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/images copying bootloaders trying hardlink /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: /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk copying distros to tftpboot copying images 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 *** [root@node1 ~]# cobbler check
三、配置及启动cobbler所依赖的各服务
cobbler的运行依赖于dhcp、tftp、rsync及dns服务。cobbler可自行管理这些服务中的部分甚至是全部,但需要配置/etc/cobbler/settings文件中的“manage_dhcp”、“manage_tftpd”、“manage_rsync”和“manage_dns”分别进行定义。另外,由于每种服务都有着不同的实现方式,如若需要进行自定义,需要通过修改/etc/cobbler/modules.conf配置文件中各服务的模块参数的值来实现。
本文采用了独立管理的方式,即不通过cobbler来管理这些服务。
1、配置dhcp服务
[root@node1 syslinux]# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf cp: overwrite `/etc/dhcp/dhcpd.conf'? y [root@node1 syslinux]# vim /etc/dhcp/dhcpd.conf option domain-name "whb.com"; option domain-name-servers 172.16.22.1; default-lease-time 43200; max-lease-time 86400; log-facility local7; subnet 172.16.0.0 netmask 255.255.0.0 { range 172.16.22.20 172.16.22.25; option routers 172.16.22.1; next-server 172.16.22.6; filename="pxelinux.0"; }
检查配置文件并重启服务
[root@node1 ~]# /etc/init.d/dhcpd configtest Syntax: OK [root@node1 ~]# /etc/init.d/dhcpd restart Shutting down dhcpd: [ OK ] Starting dhcpd: [ OK ]
2、配置tftp服务
[root@node1 ~]# chkconfig tftp on [root@node1 ~]# service xinetd restart Stopping xinetd: [FAILED] Starting xinetd: [ OK ]
四、配置cobbler
1、管理distro
挂载ISO镜像,并定义distro,可以通过为其指定外部的安装引导内核及ramdisk文件的方式实现。而如果已经有完整的系统安装树(如CentOS6的安装镜像)则推荐使用import直接导入的方式进行。本文为直接导入
[root@node1 ~]# mount /dev/cdrom /mnt/ mount: block device /dev/sr0 is write-protected, mounting read-only [root@node1 ~]# cobbler import --name=centos-6.5-x86_64 --path=/mnt/ task started: 2014-10-05_181334_import task started (id=Media import, time=Sun Oct 5 18:13:34 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: 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: createrepo -c cache -s sha --groupfile /var/www/cobbler/ks_mirror/centos-6.5-x86_64/repodata/0dae8d32824acd9dbdf7ed72f628152dd00b85e4bd802e6b46e4d7b78c1042a3-c6-x86_64-comps.xml /var/www/cobbler/ks_mirror/centos-6.5-x86_64 received on stdout: Spawning worker 0 with 3887 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 *** 列出所有的distro: [root@node1 ~]# cobbler distro list centos-6.5-x86_64
2、管理profile
cobbler使用profile来为特定的需求类别提供所需要安装配置,即在distro的基础上通过提供kickstart文件来生成一个特定的系统安装配置。distro的profile可以出现在PXE的引导菜单中作为安装的选择之一。
因此,如果需要为前面创建的centos-6.5-x86_64这个distro提供一个可引导安装条目,其用到的kickstart文件为/tmp/centos-6.5-x86_64.cfg(只提供了最基本的程序包),则可通过如下命令实现。
[root@node1 ~]# cobbler profile add --name=centos-6.5-x86_64-basic --distro=centos-6.5-x86_64 --kickstart=/tmp/centos6.x86_64.cfg 列出所有的profile: [root@node1 tmp]# cobbler profile list centos-6.5-x86_64 centos-6.5-x86_64-basic
五、测试
新建虚拟机,网络启动
看到这个图就大功告成了!!!!!