Cobbler介紹
Cobbler是一款自動化操作系統安裝的實現,與PXE安裝系統的區別就是可以同時部署多個版本的系統,而PXE只能選擇一種系統。而如今的架構動輒就是上千臺的服務器。而存在一些操作系統不統一的現象,例如最初的架構採用的是CentOS5系列的系統,而新出現了一些技術後,需要新的操作系統的支持,一方面是需要批量部署裝機,而另一方面還需要考慮到如果老版本的服務器出現故障後還需要重新去部署。並且提供Web配置頁面,可以只需要一些點擊就可以完成一些操作。
Cobbler的實現和PXE的方法大同小異,例如都需要安裝tftp,dhcp,http等,但是使用yum安裝Cobbler的時候,會自動把需要的全部安裝上,而不需要去手動一個個的安裝。
Cobbler 子命令介紹
cobbler check #檢查cobbler配置
cobbler sync #步配置到dhcp pxe和數據目錄
cobbler list #列出所有的cobbler元素
cobbler import #導入安裝的系統光盤鏡像
cobbler report #列出各元素的詳細信息
cobbler distro #查看導入的發行版系統信息
cobbler profile #查看配置信息
cobbler system #查看添加的系統信息
cobbler reposync #同步yum倉庫到本地
以下將實現Centos6 和Centos7的安裝
(1)Cobbler的安裝
yum -y install cobbler cobbler-web pykickstart debmirrorhttpd syslinux dhcp tftp-server
(2)更改settings配置文件
vi /etc/cobbler/settings next_server: dhcp服務器地址,本機地址 server: cobbler服務器地址,本機地址 manage_dhcp: 1 #0自己管理,1 Cobbler管理,自己選擇,不同的選擇要對dhcp做不同的配置,下面會講解 manage_rsync: 1 manage_tftpd:1
(3)啓用dhcp、tftp、rsync、httpd
httpd
service httpd start
rsync、tftp
vim /etc/xinetd.d/tftp
修改disable yes => disable no
vim /etc/xinetd.d/rsync
修改disable yes => disable no
service xined start
dhcp
dhcp的使用有兩種方法,一是自行管理,自己編寫配置文件,網段要和現有的一致
vim /etc/dhcp/dhcpd.conf subnet 192.168.61.0 netmask 255.255.255.0 { option routers 192.168.61.2; option domain-name-servers 192.168.61.2; option subnet-mask 255.255.255.0; range dynamic-bootp 192.168.61.221 192.168.61.225; #dhcp分配的網絡地址 filename "/pxelinux.0"; #啓動文件 default-lease-time 21600; max-lease-time 43200; next-server 192.168.61.160; #tftp服務器地址,本機 }
二是由cobbler來管理,它會使用/etc/cobbler/dhcp.template來配置dhcp,所以直接修改這個文件即可
vim /etc/cobbler/dhcp.template subnet 192.168.61.0 netmask 255.255.255.0 { option routers 192.168.61.2; option domain-name-servers 192.168.61.2; option subnet-mask 255.255.255.0; range dynamic-bootp 192.168.61.100 192.168.61.254; default-lease-time 21600; max-lease-time 43200; next-server $next_server; class "pxeclients" { match if substring (option vendor-class-identifier, 0, 9) ="PXEClient"; if option pxe-system-type = 00:02 { filename"ia64/elilo.efi"; } else if option pxe-system-type = 00:06 { filename"grub/grub-x86.efi"; } else if option pxe-system-type = 00:07 { filename"grub/grub-x86_64.efi"; } else { filename"pxelinux.0"; } } }
(4)編輯/etc/debmirror.conf文件,把 dists 和 arches 兩行註釋掉
(5)如有需要可以修改/etc/cobbler/settings 默認的密碼(安裝好的系統root密碼)
把新密碼填到裏面default_password_crypted:"xxxxxxxxxxxx"
這樣生成新密碼 openssl passwd -1 -salt '隨機碼' '新密碼'
openssl passwd -1 -salt `openssl rand -hex4` '123456'
(6)確保iptables是關閉或開放80/443 和25151
(7)啓動並檢查配置
service cobbler start cobbler check
以上完成後 cobbler sync 同步一下
(8)導入安裝鏡像文件
#先掛載鏡像到某個目錄 mount /dev/cdrom /mnt #導入 cobbler import --name=centos6 --path=/mnt cobbler import --name=centos7 --path=/mnt --path=xxx 導入的路徑 --name=xxx 導入後的名字 service httpd restart cobbler sync
(導入完成後,會自動在/var/www 下生成一個cobbler目錄,下面的ks_mirror目錄下會有剛纔--name指定名字的目錄,光盤的文件都導入這裏了,而且自動生成一個yum源。如果打開/etc/httpd/conf.d目錄,會發現有一個cobbler.conf,定義了alias /cobbler /var/www/cobbler,可以通過cobbler訪問到/var/www/cobbler上。
導入資源後一般都要重啓httpd和cobbler sync才能生效)
(9)導入後的檢查
cobbler profile list
會發現自動添加了一個以--name命名的profile
cobbler distro list
會發現自動添加了一個以--name命名的distro
cobbler repo list
沒有顯示,原因不明
(10)添加自定義的profile
cobbler profile add --help
只需關注:
--distro=DISTRO NAME
--kickstart=KICKSTART
--name=NAME 當前對應的profile名字,即要起的profile名字
repo不用指,會自動映射合適的
注意:kickstart文件應該放在/var/lib/cobbler/kickstarts 下,可以手動拷貝合適的文件過去用
例:添加centos6-web profile
cobblerprofile add --name="centos6-web" --distro=centos6-x86_64--kickstart=/var/lib/cobbler/kickstarts/centos6-web-x86_64.cfg
cobbler sync
(當編輯或增加了一個profile同步後會在/var/lib/tftpboot/pxelinux.cfg/default 文件上新添加一個LABEL
例:
LABEL centos6-web-x86_64
kernel /p_w_picpaths/centos6.6-x86_64/vmlinux
MENU LABEL centos6-web-x86_64
append initrd=/p_w_picpaths/ centos6-web-x86_64/initrd.imgksdevice=bootif text ks=xxxxxxx
)
至此,配置已經全部完成,只要啓動要安裝系統的電腦,用PXE啓動即可看到安裝選擇界面
使用cobbler_web進行管理
(1)編輯/etc/cobbler/modules.conf 設置認證的方式
[authentication]
module = authn_configfile
看上面的註釋,默認authn_configfile 使用的是/etc/cobbler/users.digest文件來認證
users.digest文件的生成:
htdigest /etc/cobbler/users.digest"cobbler title message" cobbler
cobbler title message 是認證提示信息,clbbler爲用戶名,再輸入密碼即可
最後cobbler sync
http://192.168.61.160/cobbler_web就可以正常登陸使用了
(2)使用authn_pam的認證方法登陸
a、編輯/etc/cobbler/modules.conf,更改驗證方式
[authentication]
module = authn_pam
b、添加用戶
useradd cobblerweb
c、修改用戶配置文件,把用戶添加到cobbler管理組
vim /etc/cobbler/user.conf
[admins]
admin = " cobblerweb "
cobbler = ""
最後重啓http、cobbler服務,一定要重啓cobbler服務纔可以哦
service httpd restart
service cobblerd restart
http://192.168.61.160/cobbler_web就可以正常登陸使用了,圖形界面的使用非常方便和簡單就不一一介紹了