從事網遊運維的兄弟們應該深有感觸,每每在開新服的時候須要大批量的佈署新的服務器,時間緊迫並且量大,裝系統、初始化,枯燥而又乏味,有時還容易出錯,爲了解放咱們的雙手,因此要實現自動化,Red Hat 最新發布了網絡安裝服務器套件 Cobbler(補鞋匠)集成了PXE、DHCP、DNS、Kickstart服務管理和yum倉庫管理工具,相對以前的 Kickstart 更加快捷、方便的批量佈署red hat、centos類系統node
1、安裝軟件python
一、安裝cobblerlinux
[root@node1 ~]# yum install cobbler pykickstart debmirror
二、 其餘服務的安裝sql
額外須要的服務還有dhcp tftp,rsync,xinetd,httpd,syslinux。因此若是安裝系統的時候若是這幾個包沒裝上,請手動安裝。shell
2、啓動服務並檢測cobblervim
一、啓動httpd和cobblerd服務centos
[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 ]
二、執行「cobbler check命令檢查存的問題,逐一按提示解決:bash
[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. 如上各問題的解決方法以下所示: 一、修改/etc/cobbler/settings文件中,server: 172.16.22.6; 二、修改/etc/cobbler/settings文件中,next_server: 172.16.22.6; 三、若是當前節點能夠訪問互聯網,執行「cobbler get-loaders」命令便可;不然,須要安裝syslinux程序包,執行: [root@node1 ~]# cp /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/cobbler/loaders/ 四、執行[root@node1 ~]# chkconfig rsync on 五、註釋/etc/debmirror.conf文件中的「@dists="sid";」一行; 六、註釋/etc/debmirror.conf文件中的「@arches="i386";」一行; 七、執行「openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'」生成密碼,並用替換/etc/cobbler/settings文件中default_password_crypted參數的值,如default_password_crypted: "$1$random-p$AOw9RDIWQm6tfUo9Ediu/0"; 八、執行「yum -y install cman fence-agents」命令安裝相應的程序包便可;
三、重啓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/p_w_picpaths 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 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 *** [root@node1 ~]# cobbler check
3、配置及啓動cobbler所依賴的各服務
網絡
cobbler的運行依賴於dhcp、tftp、rsync及dns服務。cobbler可自行管理這些服務中的部分甚至是所有,但須要配置/etc/cobbler/settings文件中的「manage_dhcp」、「manage_tftpd」、「manage_rsync」和「manage_dns」分別進行定義。另外,因爲每種服務都有着不一樣的實現方式,如若須要進行自定義,須要經過修改/etc/cobbler/modules.conf配置文件中各服務的模塊參數的值來實現。
本文采用了獨立管理的方式,即不經過cobbler來管理這些服務。
一、配置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 ]
二、配置tftp服務
[root@node1 ~]# chkconfig tftp on [root@node1 ~]# service xinetd restart Stopping xinetd: [FAILED] Starting xinetd: [ OK ]
4、配置cobbler
一、管理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
二、管理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
5、測試
新建虛擬機,網絡啓動
看到這個圖就大功告成了!!!!!