Cobbler是免費(fèi)的開源Linux安裝服務(wù)器,可以快速設(shè)置網(wǎng)絡(luò)安裝環(huán)境。您可以使用Cobbler通過網(wǎng)絡(luò)在多個系統(tǒng)上自動安裝操作系統(tǒng)。Cobbler可以幫助配置,管理DNS和DHCP,軟件包更新,電源管理,配置管理編排等等。Cobbler中的操作系統(tǒng)安裝基于Kickstart文件,并在客戶端或系統(tǒng)上使用開始安裝。
部署cobbler實(shí)現(xiàn)系統(tǒng)的安裝
確保已完成如下工作
- 已關(guān)閉iptables,firewalld
- 已關(guān)閉SELinux
- 已配置固定的IP地址
- 以設(shè)置好合理的主機(jī)名
- 擴(kuò)展根分區(qū)
- 使用隔離網(wǎng)絡(luò),可以添加兩塊網(wǎng)卡,一塊為nat模式用于上外網(wǎng),一塊隔離模式用于提供安裝源
一、配置yum源,裝包
首先配置epel源
yum install -y epel-release
在服務(wù)器上安裝Cobbler之前,您需要安裝Apache Web服務(wù)器并執(zhí)行以下命令。
yum -y install httpd
接下來,運(yùn)行以下命令以安裝Cobbler及其所需的依賴包。
yum -y install cobbler cobbler-web dnsmasq syslinux dhcp tftp-server xinetd
二、啟動服務(wù)設(shè)置開機(jī)自啟動
接下來,您需要啟動Cobbler和Apache Web服務(wù)器并使它們在引導(dǎo)時(shí)運(yùn)行。運(yùn)行以下命令來執(zhí)行此操作。
systemctl start cobblerd
systemctl enable cobblerd
systemctl start httpd
systemctl enable httpd
三、配置Cobbler
我們已經(jīng)在您的CentOS 7服務(wù)器上成功安裝了Cobbler,現(xiàn)在讓我們配置它。
首先運(yùn)行cobbler check檢測cobbler配置
[root@cobbler ~]# cobbler check
通過該命令可以查看cobbler的服務(wù)是否正常,需要解決哪些問題
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 : change 'disable' to 'no' in /etc/xinetd.d/tftp
4 : 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.
5 : enable and start rsyncd.service with systemctl
6 : debmirror package is not installed, it will be required to manage debian deployments and repositories
7 : ksvalidator was not found, install pykickstart
8 : 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
9 : 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.
上文加粗的是問題所在根據(jù)對應(yīng)的問題進(jìn)行解決
如上各問題的解決辦法為:
1.修改/etc/cobbler/settings文件的server參數(shù)的值為提供cobbler服務(wù)的主機(jī)對應(yīng)的ip地址,可以寫ip,也可以寫主機(jī)名,若寫主機(jī)名要求再hosts文件中做解析
2.修改/etc/cobbler/settings文件的next_server參數(shù)的值為提供PXE服務(wù)的主機(jī)的對應(yīng)IP地址
3.將/etc/xinetd.d/tftp中的disable改為no
4.如果當(dāng)前節(jié)點(diǎn)可以訪問互聯(lián)網(wǎng),執(zhí)行“cobbler get-loaders”命令下載pxelinux.0,menu.c32,elilo.efi, 或yaboot文件,否則,需要安裝syslinux程序包,而后復(fù)制/usr/share/syslinux/中的 pxelinux.0,menu.c32等文件至/var/lib/cobbler/loaders目錄中
5.啟動rsyncd.service服務(wù)
6.安裝debmirror的包
7.安裝 pykickstart的包
8.執(zhí)行“openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'生成密碼,并用其替換/etc/cobbler/settings文件中default_password_crypted參數(shù)。這個密碼是客戶端主機(jī)裝完系統(tǒng)之后管理員的密碼。9.安裝cman或者是fence-agents來實(shí)現(xiàn)電源管理,集群中解決腦裂的軟件,centos6裝cman,centos7裝fence-agents
問題1和2: 配置 讓客戶端主機(jī)尋找的ip地址
[root@server cobbler]# cd /etc/cobbler
[root@server cobbler]# vim settings
next_server: 10.10.10.1
server: 10.10.10.1
問題3.設(shè)置xinetd
[root@pxe cobbler]# vim /etc/xinetd.d/tftp
disabled = no
問題4.下載文件
[root@pxe loaders]# cobbler get-loaders
[root@pxe loaders]# ls /var/lib/cobbler/loaders
COPYING.elilo COPYING.yaboot grub-x86_64.efi menu.c32 README
COPYING.syslinux elilo-ia64.efi grub-x86.efi pxelinux.0 yaboot
問題5.啟動服務(wù)設(shè)置開機(jī)自啟動
[root@pxe ~]# systemctl restart rsyncd.service
[root@pxe loaders]# systemctl enable rsyncd.service
問題6.安裝debmirror包,但是我們用不到,不用裝,如果是debian系統(tǒng)需要裝這個包
問題7.安裝pykickstart包
[root@pxe ~]# yum -y install pykickstart
問題8.生成密碼
[root@pxe loaders]# openssl passwd -1 -salt 'qwer1234!@#$.' 'uplooking'
$1$qwer1234$eW8Yzsiu2SpULLBwFAnbT/
-1:使用md5的加密算法
salt:是一個函數(shù),后面加一段隨機(jī)的字符串,通過這段隨機(jī)字符串生成最終的密碼
[root@pxe loaders]# vim /etc/cobbler/settings
default_password_crypted: "$1$qwer1234$eW8Yzsiu2SpULLBwFAnbT/"
問題9.安裝缺失的軟件包
[root@pxe loaders]# yum -y install fence-agents
按照上述提示進(jìn)行cobbler的配置,重啟cobblerd服務(wù),并使用cobbler sync保存配置
[root@pxe 7]# systemctl restart cobblerd
[root@pxe 7]# cobbler sync
四、配置DHCP服務(wù)給客戶端分配ip
設(shè)置cobbler的模板,由cobbler來修改dhcp的配置文件,啟動服務(wù)。
[root@pxe ~]# vim /etc/cobbler/settings //將0改為1,允許配置dhcp
manage_dhcp: 1
[root@pxe ~]# vim /etc/cobbler/dhcp.template //修改subnet一段,網(wǎng)關(guān)和dns可刪掉,其余不要動
subnet 192.168.87.0 netmask 255.255.255.0 {
range dynamic-bootp 192.168.87.10 192.168.87.20;
[root@pxe ~]# systemctl restart cobblerd
[root@pxe ~]# cobbler sync
[root@pxe ~]# ss -anup |grep :67
UNCONN 0 0 *:67 *:* users:(("dhcpd",pid=11679,fd=7))
UNCONN 0 0 *%virbr0:67 *:* users:(("dnsmasq",pid=1499,fd=3))
五、啟動tftp服務(wù) 讓客戶端能都找到 pxelinux.0文件
[root@pxe ~]# systemctl restart xinetd
[root@pxe ~]# systemctl enable xinetd
[root@pxe ~]# ss -anup | grep :69
UNCONN 0 0 *:69 *:* users:(("xinetd",pid=6032,fd=5))
六、接下來,您需要創(chuàng)建一個目錄并復(fù)制CentOS 7的ISO文件并運(yùn)行以下命令將ISO導(dǎo)入Cobbler。
[root@pxe ~]# mkdir /mnt/centos7
[root@pxe ~]# mount CentOS-7.3-x86_64-DVD-1611.iso /mnt/centos7/
mount: /dev/loop0 寫保護(hù),將以只讀方式掛載
[root@pxe ~]# cobbler import --path=/mnt/centos7 --name=centos7.3 --arch=x86_64
--path:指定光盤的掛載點(diǎn)
--name:自定義的一個名字
--arch:指定操作系統(tǒng)的平臺
您也可以導(dǎo)入其他Linux風(fēng)格的ISO文件。如果您在導(dǎo)入時(shí)遇到簽名錯誤,請運(yùn)行以下命令來解決問題。
cobbler signature update
接下來,您需要驗(yàn)證Distro列表并運(yùn)行以下命令以查看Distro列表。
[root@pxe ~]# cobbler list
distros: 分發(fā)板,就是剛才導(dǎo)入鏡像文件生成的分發(fā)板,存放的centos7的光盤
centos7.3-x86_64
profiles: 生成的配置文件(菜單),名字和分發(fā)板相同
centos7.3-x86_64
配置cobbler使用自定義的ks文件
[root@cobbler kickstarts]# pwd
/var/lib/cobbler/kickstarts
默認(rèn)使用的sample_end.ks文件是最小化的方式安裝系統(tǒng)
準(zhǔn)備自定義ks文件
[root@cobbler kickstarts]# cp sample_end.ks centos7.ks
[root@cobbler kickstarts]# vim centos7.ks //文件中使用了setting中設(shè)置的一些變量,不要動
手動添加裝系統(tǒng)的時(shí)候需要額外裝什么包
%packages
$SNIPPET('func_install_if_enabled')
httpd
mariadb-server
bash-completion
vim*
%end
修改菜單關(guān)聯(lián)的模板
[root@cobbler kickstarts]# cobbler profile edit --name=centos7.3-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.ks
查看菜單關(guān)聯(lián)的模板
[root@pxe kickstarts]# cobbler profile report |grep Kickstart |grep 7
Kickstart : /var/lib/cobbler/kickstarts/centos7.ks
Web界面
打開您喜歡的Web瀏覽器并訪問http:// YourServerIP / cobbler_web /使用Cobbler作為用戶名和密碼。
使用PXE引導(dǎo)客戶端
Cobbler的基本配置現(xiàn)已完成,現(xiàn)在使用pxe啟動系統(tǒng),您要在其上執(zhí)行自動操作系統(tǒng)安裝。
最后選擇CentOS 7作為操作系統(tǒng)并按回車鍵,您將看到操作系統(tǒng)安裝已啟動。