一、簡介
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 可以:
使用一個以前定義的模闆來配置 DHCP 服務(如果啟用了管理 DHCP)
将一個存儲庫(yum 或 rsync)建立鏡像或解壓縮一個媒介,以注冊一個新作業系統
在 DHCP 配置檔案中為需要安裝的機器建立一個條目,并使用您指定的參數(IP 和 MAC 位址)
在 TFTFP 服務目錄下建立适當的 PXE 檔案
重新啟動 DHCP 服務以反映更改
重新啟動機器以開始安裝(如果電源管理已啟用)
Cobbler 支援衆多的發行版:Red Hat、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 可從用戶端配置虛拟機并重新安裝系統。我不會讨論配置管理和koan 特性,因為它們不屬于本文的介紹範疇。但是,它們是值得研究的有用特性
三、安裝配置
1.安裝方式
cobbler可以手動編譯安裝,也可以基于yum源的安裝, 如果需要通過yum源安裝,則需要配置epel源,epel源可以通過下載下傳官方給的epel源的目錄來實作安裝https://fedoraproject.org/wiki/EPEL
[root@node1 ~]# yum install cobbler cobbler-web pykickstart debmirror -y
2.檢查配置檔案,需要在cobblerd和httpd啟動的情況下檢查
[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 them
如上個問題的解決辦法為
1.修改/etc/cobbler/settings檔案的server參數的值為提供cobbler服務的主機對應的ip位址
2.修改/etc/cobbler/settings檔案的next_server參數的值為提供PXE服務的主機的對應IP位址
3.如果目前節點可以通路網際網路,執行“cobbler get-loader”指令下載下傳pxelinux.0,menu.c32,elilo.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/dedmirror.conf檔案中的“@dists=”sid”;”一行
6.注釋/etc/dedmirror.conf檔案中的“@arches=”i386”;”一行
7.執行“openssl passwd -1 -salt $(openssl rand -hex 4)”生成密碼,并用其替換/etc/cobbler/settings檔案中default_password_crypted參數
8.安裝cam和fance-agents來實作電源管理
通過cobbler get-loaders同步檔案
[root@node1 ~]# cobbler get-loaders
task started: 2014-04-23_212251_get_loaders
task started (id=Download Bootloader Content, time=Wed Apr 23 21:22:51 2014)
downloading http://www.cobblerd.org/loaders/README to /var/lib/cobbler/loaders/README
downloading http://www.cobblerd.org/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo
downloading http://www.cobblerd.org/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot
downloading http://www.cobblerd.org/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux
downloading http://www.cobblerd.org/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi
downloading http://www.cobblerd.org/loaders/yaboot-1.3.14-12 to /var/lib/cobbler/loaders/yaboot
downloading http://www.cobblerd.org/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0
downloading http://www.cobblerd.org/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32
downloading http://www.cobblerd.org/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi
downloading http://www.cobblerd.org/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi
四、配置及啟動cobbler所依賴的各服務
cobbler的運作依賴于dhcp、tftp、rsync及dns服務,其中dhcp可由dhcpd(isc)提供,也可由dnsmasq提供;tftp可由tftp-server程式包提供,也可由cobbler功能提供,rsync有rsync程式包提供,dns可由bind提供,也可由dnsmasq提供
cobbler可自行管理這些服務中的部分甚至是全部,但需要配置/etc/cobbler/settings檔案中的“manange_dhcp”、“manager_tftpd”、“manager_rsync”、“manager_dns”分别來進行定義,另外,由于各種服務都有着不同的實作方式,如若需要進行自定義,需要通過修改
/etc/cobbler/modules.conf
配置檔案中各服務的子產品參數的值來實作
本處通過獨立管理。即不通過cobbler來管理這些服務
1.配置dhcp服務
定義好所需的“subnet”及其他參數,本處的配置如下
[root@node1 ~]# cp /usr/share/doc/dhcp*/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
編輯配置檔案
option domain-name "wangfeng7399";
option domain-name-servers 192.168.1.201;
default-lease-time 43200;
max-lease-time 86400;
log-facility local7;
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.210 192.168.1.230
option routers 192.168.1.253
}
next-server 192.168.1.210;
filename="pxelinux.0";
2.配置tftpd服務
[root@node1 ~]# chkconfig tftp on
五、配置cobbler
cobbler的各主要元件間的關系如下圖所示

1.管理distro
是cobbler變得可用的第一步為定義distro,其可以通過為其指定外部的安裝引導核心及ramdisk檔案的方式實作。而如果已經有完成的安裝樹(如os的安裝鏡像)則推薦使用improt之間導入的方式進行
[root@node1 ~]# mount /dev/cdrom /media
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@node1 ~]# cobbler import --name=centos6.5-x86-64 --path=/media/
task started: 2014-04-23_214916_import
task started (id=Media import, time=Wed Apr 23 21:49:16 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
Keeping repodata as-is :/var/www/cobbler/ks_mirror/centos6.5-x86-64/repodata
*** TASK COMPLETE ***
列出所有的distro
[root@node1 ~]# cobbler distro list
centos6.5-64-x86_64
如果有kickstart檔案,也可以使用—kickstart=/path/to/kickstart_file進行導入,是以import會自動為導入的distro生成一個profile
2.管理profile
cobbler使用profile來為特定的需求類别提供鎖需要安裝的配置,即在distro的基礎上通過提供kiskstart檔案來生成一個特定的系統安裝配置。distro的profile可以出現在pxe的引導菜單中作為安裝的選擇之一.
[root@node1 ~]# cobbler profile add --name=centos6.5-x86_64 --distro=centos6.5-64-x86_64 kickstart=/root/anaconda-ks.cfg
列出目前系統上的profile
[root@node1 ~]# cobbler profile list
centos6.5-64-x86_64
centos6.5-x86_64
删除一個profile
[root@node1 ~]# cobbler profile remove --name=centos6.5-64-x86_64
3.重新開機服務及同步資料到響應的目錄
[root@node1 ~]# service cobblerd restart
Stopping cobbler daemon: [ OK ]
Starting cobbler daemon: [ OK ]
[root@node1 ~]# cobbler sync
task started: 2014-04-23_220652_sync
task started (id=Sync, time=Wed Apr 23 22:06:52 2014)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/centos6.5-64-x86_64
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/images/centos6.5-64-x86_64
removing: /var/lib/tftpboot/s390x/profile_list
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 /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot
中間省去N行
received on stderr:
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 ***
4.測試
可以看到我們定制的系統啟動頁面,開始安裝系統
系統安裝成功,登陸系統
六、使用cobbler_web
cobbler_web支援多種認證方式,如
authn_configfil
、
authn_ldap
或
authn_pam
等,預設為
authn_denyall
,即拒絕所有使用者登陸。下面說明兩種能認證使用者登入
cobbler_web
的方式
1.使用
authn_pam
子產品認證
cobbler_web
使用者
首先修改modules中的
[authentication]
段中的module參數的值為
authn_pam
接着設定系統使用者,并為使用者設定密碼
而後将設定的系統使用者添加至
cobbler_web
的admin組中,修改
/etc/cobbler/users.conf
檔案,将設定的使用者添加為admin參數的值即可
2.使用
authn_configfile
cobbler_web
首先修改modules中的[authentication]段中的module參數的值為
authn_configfile
接着建立其認證檔案
/etc/cobbler/users.digest
,并添加所需要的使用者即可。需要注意的是,添加第一使用者時,需要為htdigest指令使用“-c”選項,後續添加其他使用者則不能再使用
本處使用的為authn_pam
[root@node1 ~]# vi /etc/cobbler/modules.conf
[authentication]
module = authn_pam
[root@node1 ~]# useradd wangfeng7399
[root@node1 ~]# passwd wangfeng7399
Changing password for user wangfeng7399.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@node1 ~]# vi /etc/cobbler/users.conf
[admins]
admin = "wangfeng7399"