Cobbler簡介
使用PXE批量部署時灵疮,有一個缺陷织阅,即只能安裝單一的操作系統(tǒng)(同一個版本,僅用一個kickstart文件)始藕。但是在實(shí)際環(huán)境中蒲稳,不同功能的服務(wù)器需要部署不同的環(huán)境,而cobbler正好滿足了這一需求伍派。cobbler基于python開發(fā)江耀,是對PXE的二次封裝,且提供了CLI和Web的管理形式诉植,使得操作和管理更加簡便祥国。cobbler的實(shí)現(xiàn)與PXE類似,也需要tftp晾腔,httpd舌稀,dhcp這些服務(wù)。使用yum即可完成cobbler的安裝灼擂,在安裝的同時也會自動安裝tftp和httpd服務(wù)壁查,dhcp服務(wù)需要自行安裝。
cobbler的部署非常簡單剔应,首先添加distro睡腿,或直接導(dǎo)入光盤鏡像语御,然后為某一個distro添加kickstart文件,一個distro可有多個kickstart文件席怪,以實(shí)現(xiàn)同一版本的操作系統(tǒng)部署多個不一樣的環(huán)境应闯。
實(shí)現(xiàn)過程
實(shí)驗(yàn)環(huán)境:所有的服務(wù)均部署在同一臺服務(wù)器上(192.168.3.10)
安裝cobbler
[root@node1 ~]# yum install cobbler
這個過程會自動安裝tftp,httpd挂捻。
自行安裝dhcp碉纺。
[root@node1 ~]# yum install dhcp
tftp,httpd刻撒,dhcp骨田,還包括DNS這些服務(wù)都可以由cobbler代為管理,也可以獨(dú)立管理疫赎。這里都將這些服務(wù)設(shè)置為單獨(dú)管理盛撑。
[root@node1 ~]# vim /etc/cobbler/settings
manage_dhcp: 0
manage_dns: 0
.....
manage_tftpd: 0
manage_rsync: 0
配置dhcp服務(wù)
[root@node1 ~]# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
[root@node1 ~]# vim /etc/dhcp/dhcpd.conf
......
......
subnet 192.168.3.0 netmask 255.255.255.0 {
range 192.168.3.10 192.168.3.254;
option routers 192.168.3.1;
option broadcast-address 192.168.3.31;
default-lease-time 3600;
max-lease-time 7200;
next-server 192.168.3.10;? ? ? #指向pxe服務(wù)器
filename "pxelinux.0";
}
檢查配置,啟動服務(wù):
[root@node1 ~]# service dhcpd configtest
Syntax: OK
[root@node1 ~]# service dhcpd start
Starting dhcpd:? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? [? OK? ]
[root@node1 ~]# ss -tunl | grep 67
udp? ? UNCONN? ? 0? ? ? 0? ? ? ? ? ? ? ? ? ? ? *:67? ? ? ? ? ? ? ? ? ? *:*
啟動tftp和rsync
[root@node1 ~]# chkconfig tftp on
[root@node1 ~]# chkconfig rsync on
[root@node1 ~]# service xinetd start
[root@node1 ~]# ss -tunl | grep 69
udp? ? UNCONN? ? 0? ? ? 0? ? ? ? ? ? ? ? ? ? ? *:69? ? ? ? ? ? ? ? ? ? *:*
啟動cobbler服務(wù)
在啟動cobbler之前首先需要啟動httpd服務(wù)捧搞。
[root@node1 ~]# service httpd start
[root@node1 ~]# service cobblerd start
然后使用cobbler check檢查cobbler的運(yùn)行環(huán)境抵卫,第一次運(yùn)行可能會存在如下錯誤():
[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 : debmirror package is not installed, it will be required to manage debian deployments and repositories
5 : ksvalidator was not found, install pykickstart
6 : 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
7 : 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.
依次解決以上錯誤:
1)設(shè)置server參數(shù)為cobbler服務(wù)器的IP地址
# vim /etc/cobbler/settings
# server: 192.168.3.10
2)設(shè)置next_server為pxe服務(wù)器的IP地址
# vim /etc/cobbler/settings
# next_server: 192.168.3.10
3)若僅為x86/x86_64架構(gòu)的服務(wù)器提供服務(wù),安裝syslinux即可
# yum install syslinux
4)這一項(xiàng)可以忽略
5)安裝ksvalidator
# yum install -y pykickstart
6)為default_password_crypted參數(shù)設(shè)置新密碼
# openssl passwd -1 -salt `openssl rand -hex 6`
# default_password_crypted: "passwd"
7)install cman or fence-agents(可不裝)
修改完成后胎撇,重啟服務(wù):
[root@node1 ~]# cobbler sync
[root@node1 ~]# service cobblerd restart
添加distro
掛載光盤鏡像
[root@node3 ~]# mount /dev/cdrom /mnt/flash/
添加一個distro(若有光盤鏡像介粘,推薦直接導(dǎo)入光盤鏡像)
[root@node1 ~]# cobbler import --name=CentOS-6.5-x86_64 --path=/mnt/flash/
[root@node1 ~]# cobbler distro list
centos-6.5-x86_64
若鏡像文件很大,導(dǎo)入過程會很長晚树。導(dǎo)入完成后姻采,在/var/www/cobbler/ks_mirror目錄下會生成一個--name指定的名稱的目錄,這個目錄與掛載在本地的光盤鏡像目錄一致爵憎。
制作kickstart文件
kickstart文件的制作非常簡單慨亲。
首先安裝system-config-kickstart。
[root@node1 ~]# yum install system-config-kickstart
執(zhí)行system-config-kickstart啟用圖形界面進(jìn)行配置(使用xmanager之類的連接程序)
[root@node1 ~]# system-config-kickstart
配置的過程與安裝操作系統(tǒng)差不多宝鼓,按照提示一個一個配置即可刑棵。在配置之前需要先掛載光盤鏡像,并且將該光盤鏡像作為本地的yum源愚铡,在Package Selection這一項(xiàng)即會顯示該光盤鏡像中可安裝的軟件包蛉签。
若配置的是其他版本操作系統(tǒng)的ks文件,將對應(yīng)的光盤鏡像文件作為本地的yum源即可沥寥,例如需要為centOS7制作ks文件碍舍。
換成centOS7的ISO文件。
在/etc/yum.repos.d目錄下添加本地的repo文件邑雅,清理之前的緩存片橡,然后掛載。
[root@CentOS-6 ~]# yum clean all
Loaded plugins: fastestmirror, security
Cleaning repos:
Cleaning up Everything
Cleaning up list of fastest mirrors
[root@CentOS-6 ~]# mount /dev/cdrom /mnt/flash/
mount: block device /dev/sr0 is write-protected, mounting read-only
############################
Package Selection即為centOS7鏡像光盤上的軟件包淮野。需要注意的是system-config-kickstart不支持LVM锻全,若需要添加LVM還需要在ks文件中手動進(jìn)行修改狂塘。
為distro添加profile
即為某個distro提供kickstart文件來生成一個特定的系統(tǒng)安裝配置录煤。例如為剛才添加的distro( centos-6.5-x86_64)添加一個kickstart文件鳄厌。
首先驗(yàn)證ks文件是否存在語法錯誤,然后復(fù)制到指定目錄下添加:
[root@node1 ~]# ksvalidator ks.cfg
[root@node1 ~]# cp /root/ks.cfg /var/lib/cobbler/kickstarts/
[root@node1 ~]# cobbler profile add --name=centos-6.5-base --distro=centos-6.5-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks.cfg
#####添加第二個profile
[root@node1 ~]# cp /root/ks-mysql.cfg /var/lib/cobbler/kickstarts/
[root@node1 ~]# cobbler profile add --name=centos-6.5-mysql --distro=centos-6.5-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks-mysql.cfg
list查看添加的profile:
[root@node1 kickstarts]# cobbler profile list
centos-6.5-base
centos-6.5-mysql
centos-6.5-x86_64
添加完成之后執(zhí)行cobbler sync妈踊,然后就可以使用了了嚎。
[root@node3 ~]# cobbler sync
測試過程
新添加一臺虛擬機(jī),不安裝操作系統(tǒng)廊营。
選擇需要的版本歪泳,開始安裝
cobbler的部署已實(shí)現(xiàn).................^_^