一 、Cobbler簡介
Cobbler是一個快速網絡安裝linux的服務,而且在經過調整也可以支援網絡安裝windows。該工具使用python開發,小巧輕便(才15k行python代碼),使用簡單的指令即可完成PXE網絡安裝環境的配置,同時還可以管理DHCP、DNS、yum倉庫、構造系統ISO鏡像。
Cobbler支援指令行管理,web界面管理,還提供了API接口,友善二次開發
Cobbler用戶端Koan支援虛拟機安裝和作業系統重新安裝,使重裝系統更便捷。
Cobbler提供的功能
使用Cobbler,您無需進行人工幹預即可安裝機器。Cobbler設定一個PXE引導環境(它還可以使用yaboot支援PowerPC),并控制與安裝相關的所有方面,比如網絡引導服務(DHCP和TFTP)與存儲庫鏡像。當希望安裝一台新機器時,Cobbler可以:
1)使用一個以前定義的模闆來配置DHCP服務(如果啟用了管理DHCP)
2)将一個存儲庫(yum或rsync)建立鏡像或解壓縮一個媒介,以注冊一個新作業系統
3)在DHCP配置檔案中為需要安裝的機器建立一個條目,并使用指定的參數(IP和MAC)
4)在TFTP服務目錄下建立适當的PXE檔案
5)重新啟動DHCP服務以反應更改
6)重新啟動機器以開始安裝(如果電源管理已啟動)
Cobbler支援衆多的發行版:RedHat、Fedora、CentOS、Debian、Ubuntu和SuSE。當添加一個作業系統(通常通過使用ISO檔案)時,Cobbler知道如何解壓縮合适的檔案并調整網絡服務,以正确引導機器。
Cobbler可以使用kickstart模闆。基于Red Hat或Fedora的系統使用kickstart檔案來自動化安裝流程。通過使用模闆,就會擁有基本的kickstart模闆,然後定義如何針對一種配置檔案或機器配置而替換其中的變量。例如,一個模闆可能包含兩個變量$domain和$machine_name.在Cobbler配置中,一個配置檔案指定domain=mydomain.com,并且每台使用該配置檔案的機器在machine_name變量中指定其名稱。該配置檔案的所有機器都使用相同的kickstart安裝且針對domain=mydomain.com進行配置,但每台機器擁有其自己的機器名稱。您仍然可以使用kickstart模闆在不同的域中安裝其他機器并使用不同的機器名稱。
為了協助管理系統,Cobbler可通過fence scripts連接配接到各個電源管理環境。Cobbler支援apc_snmp、bladecenter、bullpap、drac、ether_wake、ilo、integrity、ipmilan、ipmitool、lpar、rsa、virsh和wti。要重新安裝一台機器,可運作reboot system foo指令,而且Cobbler會使用必要的 和資訊來為您運作恰當的fence scripts(比如機器插槽數)。
除了這些特性,還可以使用一個配置管理系統(CMS)。你有兩種選擇:該工具内的一個内部系統,或者現成的外部CMS,比如Chef或Puppet。借助内部系統,你可以指定檔案模闆,這些模闆會依據配置參數進行處理(與kickstart模闆的處理方式一樣),然後複制到你指定的位置。如果必須自動将配置檔案部署到特定機器,那麼此功能很有用
使用koan用戶端,Cobbler可從用戶端配置虛拟機并重新安裝系統。
二、Cobbler的設計方式
Cobbler的配置結構基于一組注冊的對象。每個對象表示一個與另一個實體相關聯的實體(該對象指向另一個對象,或者另一個對象指向該對象)。當一個對象指向另一個對象時,它就繼承了被指向對象的資料,并可覆寫或添加更多特定資訊。以下對象類型的定義
Distros(發行版):表示一個作業系統,它承載了核心和initrd的資訊,以及核心參數等其他資料
Profile(配置檔案):包含一個發行版、一個kickstart檔案以及可能的存儲庫,還包含更多特定的核心參數等其他資料
Systems(系統):表示要配給的額機器。它包含一個配置檔案或一個景象,還包含IP和MAC位址、電源管理(位址、憑據、類型)、(網卡綁定、設定valn等)
Repository(鏡像):儲存一個yum或rsync存儲庫的鏡像資訊
Image(存儲庫):可替換一個包含不屬于此類比的額檔案的發行版對象(例如,無法分為核心和initrd的對象)。
基于注冊的對象以及各個對象之間的關聯,Cobbler知道如何更改檔案系統以反應具體配置。因為系統配置的内部是抽象的,是以您可以僅關注想要執行的操作。

三、Cobbler各個元件的關系
通過cobbler管理的或者手動管理的服務
TFTP
rsync
DHCP
DNS
四、安裝配置Cobbler
1、安裝方式
cobbler可以手動編譯安裝,也可以基于yum源的安裝,如果使用yum源安裝,則需要配置epel源epel源可以通過下載下傳官網的epel源的目錄來實作https://fedoraproject.org/wiki/EPEL
# yum -y install cobbler cobbler-web pykickstart debmirror
2、檢查配置檔案,需要在啟動cobblerd和httpd服務的前提下檢查
[root@c3 ~]# service httpd start
[root@c3 ~]# service cobblerd start
[root@c3 ~]# 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 them
Restart cobblerd and then run 'cobbler sync' to apply changes.
以上8個問題的解決方法
1.修改/etc/cobbler/settings檔案中的server參數的值為提供cobbler服務的主機對應的ip位址
server: 192.168.13.8
2.修改/etc/cobbler/settings檔案的next_server參數的值為提供PXE服務的主機的ip
next_server: 192.168.13.8
3.如果目前節點可以通路網際網路,執行“cobbler get-loaders”指令下載下傳pxelinux.0,menu.c32,elibo.efi,yaboot檔案,否則則需要安裝syslinux程式包,複制/usr/share/syslinux/中的pxelinux.0,menu.c32等檔案至/var/lib/cobbler/loaders目錄中
4.将/etc/xinetd.d/rsync 中的disable改為no,或者執行 chkconfig rsync on
5.注釋/etc/debmirror.conf檔案中的“@dists="sid";”一行
6.注釋/etc/debmirror.conf檔案中的“@arches="i386";”一行
7.執行“openssl passwd -1 -salt `pensshl rand -hex 4`”生成密碼,并将密碼串替換掉/etc/cobbler/settings中的default_password_crypted
default_password_crypted: "$1$6a385fbf$iOHgbfJ0BJRQh78yAMA2L1"
8.安裝cam和fence-agents來實作電源管理
同步資料
[root@c3 cobbler]# cobbler sync
task started: 2014-04-06_224909_sync
task started (id=Sync, time=Sun Apr 6 22:49:09 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
trying hardlink /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依賴的服務
cobbler的運作以來dhcp、tftp、rsync、dns服務
cobbler可行管理這些服務中的部分甚至全部,但需要配置/etc/cobbler/settings檔案中的“manager_dhcp”、“manage_tftpd”、“manage_rsync”、“manage_dns”來定義,同時各種服務都有着不同的實作方式,如果進行自定義,需要通過修改/etc/cobbler/modules.conf配置檔案中各個服務的子產品參數的值來實作
我們通過獨立管理,不通過cobbler管理這些服務。
1、配置dhcp服務
[root@c3 ~]# yum -y install dhcp
[root@c3 ~]# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
[root@c3 ~]# vim /etc/dhcp/dhcpd.conf
option domain-name "jungege.com";
option domain-name-servers 192.168.13.8;
default-lease-time 43200;
max-lease-time 86400;
log-facility local7;
subnet 192.168.13.0 netmask 255.255.255.0 {
range 192.168.13.2 192.168.13.100;
option routers 192.168.13.8;
}
filename "pxelinux.0";
next-server 192.168.13.8;
啟動服務測試
# service dhcpd start
# ss -ntlup | grep 67
udp UNCONN 0 0 *:67 *:* users:(("dhcpd",2766,7))
2、配置tftpd服務
[root@c3 ~]# yum -y install tftp-server
[root@c3 ~]# chkconfig tftp on
六、配置Cobbler
1、定義distro
實作coobler的第一步就是定義distro,可以通過其指定外部的安裝引導核心及ramdisk檔案的方式實作。而如果已經有現成的安裝樹(如OS的安裝鏡像)則使用import導入的方式
挂載安裝CD光牒
# mount /dev/cdrom /media
導入系統鏡像
# cobbler import --name=centos6.5-x86-64 --path=/media/
導入過程如下
task started: 2014-04-06_230831_import
task started (id=Media import, time=Sun Apr 6 23:08:31 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/centos6.5-x86-64:
creating new distro: centos6.5-64-x86_64
trying symlink: /var/www/cobbler/ks_mirror/centos6.5-x86-64 -> /var/www/cobbler/links/centos6.5-64-x86_64
creating new profile: centos6.5-64-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/centos6.5-x86-64 for centos6.5-64-x86_64
processing repo at : /var/www/cobbler/ks_mirror/centos6.5-x86-64
need to process repo/comps: /var/www/cobbler/ks_mirror/centos6.5-x86-64
looking for /var/www/cobbler/ks_mirror/centos6.5-x86-64/repodata/*comps*.xml
running: createrepo -c cache -s sha --groupfile /var/www/cobbler/ks_mirror/centos6.5-x86-64/repodata/b4e0b9342ef85d3059ff095fa7f140f654c2cb492837de689a58c581207d9632-c6-x86_64-comps.xml /var/www/cobbler/ks_mirror/centos6.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 ***
列出所有的distro
[root@c3 ~]# cobbler distro list
centos6.5-64-x86_64
2、管理profile
cobbler使用profile來為特定的需求類别提供所需要安裝的配置,即在distro的基礎上通過提供kickstart檔案來生成一個特定的系統安裝配置。distro的profile可以出現在pxe的引導菜單中作為安裝的選擇之一。
關于kickstart的檔案制作請參照我的上篇部落格
添加profile
# cobbler profile add --name=centos6.5-x86_64 --distro=centos6.5-64-x86_64 --kickstart=/root/anaconda-ks.cfg
列出目前系統上的profile
# cobbler profile list
centos6.5-64-x86_64
centos6.5-x86_64
删除掉一個profile
# cobbler profile remove --name=centos6.5-64-x86_64
# cobbler profile list
centos6.5-x86_64
3、重新開機cobblerd服務并同步資料到相應目錄
# service cobblerd restart
# cobbler sync
4、系統安裝測試
開始安裝。。。
七、配置cobbler_web
cobbler_web支援多種認證方式,如authn_configfil、authn_ldap或 authn_pam等,預設為authn_denyall拒接所有。
下面我們使用authn_pam子產品認證cobbler_web使用者
# vim /etc/cobbler/modules.conf
module = authn_pam
# useradd zxj
# passwd zxj
輸入密碼
# vim /etc/cobbler/users.conf
[admins]
admin = "zxj"
通路:https://172.16.13.8/cobbler_web (注意我使用的虛拟機是雙網卡172.16.13.8與192.168.13.8兩個ip位址)
此時我們可以手動的添加删除配置,更靈活的對distro 、profile等元件的管理!
PS: 水準有限,有錯誤請指出!