2021-05-12 14:32:11
Cobbler自動批次部署CentOS 6和CentOS 7
Cobbler簡介
使用PXE批次部署時,有一個缺陷,即只能安裝單一的作業系統(同一個版本,僅用一個kickstart檔案)。但是在實際環境中,不同功能的伺服器需要部署不同的環境,而cobbler正好滿足了這一需求。cobbler基於Python開發,是對PXE的二次封裝,且提供了CLI和Web的管理形式,使得操作和管理更加簡便。cobbler的實現與PXE類似,也需要tftp,httpd,dhcp這些服務。使用yum即可完成cobbler的安裝,在安裝的同時也會自動安裝tftp和httpd服務,dhcp服務需要自行安裝。
cobbler的部署非常簡單,首先新增distro,或直接匯入光碟映象,然後為某一個distro新增kickstart檔案,一個distro可有多個kickstart檔案,以實現同一版本的作業系統部署多個不一樣的環境。
實現過程
實驗環境:所有的服務均部署在同一台伺服器上(192.168.3.10)
安裝cobbler
[root@node1 ~]# yum install cobbler
這個過程會自動安裝tftp,httpd。
自行安裝dhcp。
[root@node1 ~]# yum install dhcp
tftp,httpd,dhcp,還包括DNS這些服務都可以由cobbler代為管理,也可以獨立管理。這裡都將這些服務設定為單獨管理。
[root@node1 ~]# vim /etc/cobbler/settings
manage_dhcp: 0
manage_dns: 0
.....
manage_tftpd: 0
manage_rsync: 0
設定dhcp服務
[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伺服器
filename "pxelinux.0";
}
檢查設定,啟動服務:
[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服務
在啟動cobbler之前首先需要啟動httpd服務。
[root@node1 ~]# service httpd start
[root@node1 ~]# service cobblerd start
然後使用cobbler check檢查cobbler的執行環境,第一次執行可能會存在如下錯誤():
[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)設定server引數為cobbler伺服器的IP地址
# vim /etc/cobbler/settings
# server: 192.168.3.10
2)設定next_server為pxe伺服器的IP地址
# vim /etc/cobbler/settings
# next_server: 192.168.3.10
3)若僅為x86/x86_64架構的伺服器提供服務,安裝syslinux即可
# yum install syslinux
4)這一項可以忽略
5)安裝ksvalidator
# yum install -y pykickstart
6)為default_password_crypted引數設定新密碼
# openssl passwd -1 -salt `openssl rand -hex 6`
# default_password_crypted: "passwd"
7)install cman or fence-agents(可不裝)
修改完成後,重新啟動服務:
[root@node1 ~]# cobbler sync
[root@node1 ~]# service cobblerd restart
新增distro
掛載光碟映象
[root@node3 ~]# mount /dev/cdrom /mnt/flash/
新增一個distro(若有光碟映象,推薦直接匯入光碟映象)
[root@node1 ~]# cobbler import --name=CentOS-6.5-x86_64 --path=/mnt/flash/
[root@node1 ~]# cobbler distro list
centos-6.5-x86_64
若映象檔案很大,匯入過程會很長。匯入完成後,在/var/www/cobbler/ks_mirror目錄下會生成一個--name指定的名稱的目錄,這個目錄與掛載在原生的光碟映象目錄一致。
製作kickstart檔案
kickstart檔案的製作非常簡單。
首先安裝system-config-kickstart。
[root@node1 ~]# yum install system-config-kickstart
執行system-config-kickstart啟用圖形介面進行設定(使用xmanager之類的連線程式)
[root@node1 ~]# system-config-kickstart
設定的過程與安裝作業系統差不多,按照提示一個一個設定即可。在設定之前需要先掛載光碟映象,並且將該光碟映象作為原生的yum源,在Package Selection這一項即會顯示該光碟映象中可安裝的軟體包。
若設定的是其他版本作業系統的ks檔案,將對應的光碟映象檔案作為原生的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檔案中手動進行修改。
為distro新增profile
即為某個distro提供kickstart檔案來生成一個特定的系統安裝設定。例如為剛才新增的distro( centos-6.5-x86_64)新增一個kickstart檔案。
首先驗證ks檔案是否存在語法錯誤,然後複製到指定目錄下新增:
[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
新增完成之後執行cobbler sync,然後就可以使用了。
[root@node3 ~]# cobbler sync
測試過程
新新增一台虛擬機器,不安裝作業系統。
選擇需要的版本,開始安裝
cobbler的部署已實現.................^_^
更多詳情見請繼續閱讀下一頁的精彩內容: http://www.linuxidc.com/Linux/2015-09/122945p2.htm
- CentOS 6.5 安裝和設定Cobbler http://www.linuxidc.com/Linux/2015-02/113043.htm
- Cobbler遠端安裝CentOS系統 http://www.linuxidc.com/Linux/2015-02/113163.htm
- Cobbler批次安裝Ubuntu/CentOS系統 http://www.linuxidc.com/Linux/2015-02/113167.htm
相關文章