之前有介紹《centos7下部署Cobbler實現PXE+Kickstart自動化安裝》
本周對上面步驟進行了腳本化
具體腳本如下
cobbler_onekey_install.sh--------------一鍵安裝cobbler腳本
#!/bin/bash
sed -i '$aIPADDR1=192.168.31.200' /etc/sysconfig/network-scripts/ifcfg-en*
sed -i '$aPREFIX1=24' /etc/sysconfig/network-scripts/ifcfg-en*
service network restart
cd /opt
tar -zxvf cobbler_rpmpackage.tar.gz -C /opt
mkdir -p /opt/yum_repobackup
mv /etc/yum.repos.d/*.repo /opt/yum_repobackup/
cp -rf /opt/cobblerlocal.repo /etc/yum.repos.d/
yum clean all
yum makecache
yum install -y httpd dhcp cobbler tftp-server pykickstart
systemctl start httpd
systemctl enable httpd
systemctl enable cobblerd
systemctl restart cobblerd
sleep 5
cobbler check
cobbler sync
sleep 5
sed -i "s/server: 127.0.0.1/server: 192.168.31.200/g" /etc/cobbler/settings
sed -i "s/^next_server: 127.0.0.1/ next_server: 192.168.31.200/g" /etc/cobbler/settings
sed -i 's/^.*disable.*$/ disable = no/g' /etc/xinetd.d/tftp
systemctl restart tftp.service
#cobbler get-loaders
tar -zxvf /opt/cobbler_loaders.tar.gz -C /var/lib/cobbler/
systemctl start rsyncd
systemctl enable rsyncd
sleep 2
#password admin@2020
sed -i 's/^default_password_crypted.*$/default_password_crypted: "$1$root$afc2RZysD6SOx07LLBnwB0"/g' /etc/cobbler/settings
sed -i "s/manage_dhcp: 0/manage_dhcp: 1/g" /etc/cobbler/settings
sed -i "s/192.168.1./192.168.31./g" /etc/cobbler/dhcp.template
systemctl restart cobblerd
sleep 5
cobbler sync
sleep 5
cobbler check
具體操作步驟如下
將上圖中四個文件傳到CentOS7服務器上/opt目錄
注意,必須是/opt目錄
1).cobbler_loaders.tar.gz --------------cobbler所需的loaders文件
2).cobbler_rpmpackage.tar.gz--------------cobbler服務器所需的rpm包以及對應的本地倉庫repository
3).cobblerlocal.repo --------------cobbler本地yum源repo文件
4).cobbler_onekey_install.sh--------------一鍵安裝cobbler腳本
2、chmod 755 cobbler_onekey_install.sh
./cobbler_onekey_install.sh 安裝cobbler
該腳本會給網卡添加一個192.168.31.200/24的IP地址
執行該腳本即可立即搭建起cobbler服務器