cobbler离线安装脚本

配套离线安装cobbler教程

需要手动上传镜像包和离线安装包

#!/bin/bash
#上传cobbler离线安装包和centos镜像包
# 解压离线安装包
setenforce 0
systemctl stop  firewalld 
tar -xvf /tmp/offline-cobbler.tar.gz -C /tmp/
# 配置yum源,需要上传iso镜像
mount /dev/sr0 /mnt
mkdir /etc/yum.repos.d/bak
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak
echo '[cobbler]
name=cobbler local repo
baseurl=file:///tmp/offline-cobbler/
gpgcheck=0
enalbed=1' >  /etc/yum.repos.d/cobbler.repo

echo '[centos]
name=centos
baseurl=file:///mnt/
gpgcheck=0
enalbed=1
' >  /etc/yum.repos.d/Centos.repo

yum clean all
yum makecache

yum install cobbler -y 
# 移除cobbler源
mv  /etc/yum.repos.d/cobbler.repo /etc/yum.repos.d/bak
yum install dhcp -y

systemctl enable httpd.service tftp.socket cobblerd.service 
systemctl start httpd.service tftp.socket cobblerd.service

cobbler check

自动修复cobbler问题

#!/bin/bash
localIp=192.168.87.204
cp /etc/cobbler/settings{,.bak}
sed -i "s/server: 127.0.0.1/server: $localIp/" /etc/cobbler/settings
# 修改/etc/cobbler/settings文件中的next_server参数的值为提供PXE服务的主机相应的IP地址,如next_server: 192.168.222.129
sed -i "s/next_server: 127.0.0.1/next_server: $localIp/" /etc/cobbler/settings

# 修改/etc/xinetd.d/tftp文件中的disable参数修改为 disable = no
# 备份源文件
cp /etc/xinetd.d/tftp{,.bak}
sed -i 's/disable.*= yes/disable                 = no/g' /etc/xinetd.d/tftp
# 执行 cobbler get-loaders 命令即可;否则,需要安装syslinux程序包,而后复制/usr/share/syslinux/{pxelinux.,memu.c32}等文件至/var/lib/cobbler/loaders/目录中
#cobbler get-loaders
# 密码加密
newpasswd=`openssl passwd -1 123456`
sed -i s/"default_password_crypted:.*"/"default_password_crypted: "$newpasswd""/g /etc/cobbler/settings

# 配置dhcp服务
cat > /etc/dhcp/dhcpd.conf <<EOF
subnet 192.168.87.0 netmask 255.255.255.0 {
option routers 192.168.87.1;
range dynamic-bootp 192.168.87.100 192.168.87.250;
option subnet-mask 255.255.255.0;
next-server 192.168.87.204;
default-lease-time ;
max-lease-time ;
}
EOF

cobbler sync
systemctl enable dhcpd.service
systemctl enable tftp.service
systemctl enable httpd.service
systemctl enable cobblerd.service

systemctl restart dhcpd.service
systemctl restart tftp.service
systemctl restart httpd.service
systemctl restart cobblerd.service
posted @ 2022-07-19 16:17  小李叭叭叭  阅读(187)  评论(0编辑  收藏  举报