Cobbler自动化部署

Cobbler是一个Linux 配置服务器,可以使用诸如DHCPTFTPDNS等服务从中心点简化和自动化多个计算机操作系统的基于网络的系统安装。可以使用XenKVMVMware配置PXE,重新安装和虚拟化guest 虚拟机。Cobbler与程序进行交互以重新安装和虚拟化支持。和Cobbler使用libvirtkoankoan整合不同的虚拟化软件。Cobbler能够管理复杂的网络场景,如绑定以太网链路上的桥接

安装cobbler

1
2
3
4
5
6
7
yum install cobbler cobbler-web dhcp tftp-server pykickstart httpd xinetd -y
systemctl start xinetd
systemctl enable xinetd
systemctl start httpd
systemctl enable httpd
systemctl start cobblerd
systemctl enable cobblerd

配置cobbler

使用openssl对密码加密(前面的admin是加密随机值,后面的admin是密码)

1
2
3
4
5
6
sed -i "s/^next_server:.*/next_server: 192.168.3.10/" /etc/cobbler/settings
sed -i "s/^server:.*/server: 192.168.3.10/" /etc/cobbler/settings
sed -i "s/^server:.*/server: 192.168.3.10/" /etc/cobbler/settings
sed -i "s/^manage_dhcp:.*/manage_dhcp: 1/" /etc/cobbler/settings
pass=$(openssl passwd -1 -salt 'admin' 'admin')
sed -i "s@^default_password_crypted:.*@default_password_crypted: $pass@" /etc/cobbler/settings

配置tftp

1
sed -i "/disable/s/yes/no/" /etc/xinetd.d/tftp

启动rsync服务设置开机启动

1
2
systemctl start rsyncd
systemctl enable rsyncd

下载cobbler相关的包;配置

1
2
3
cobbler get-loaders
systemctl restart cobblerd
cobbler check

配置DHCP主要修改网段,DNS,网关等信息

1
2
3
4
5
6
sed -i "21,25s/^/#/" /etc/cobbler/dhcp.template
sed -i "25a subnet 192.168.3.0 netmask 255.255.255.0 {" /etc/cobbler/dhcp.template
sed -i "26a\ option routers 192.168.3.1;" /etc/cobbler/dhcp.template
sed -i "27a\ option domain-name-servers 192.168.0.5;" /etc/cobbler/dhcp.template
sed -i "28a\ option subnet-mask 255.255.255.0;" /etc/cobbler/dhcp.template
sed -i "29a\ range dynamic-bootp 192.168.3.30 192.168.3.50;" /etc/cobbler/dhcp.template

挂载并导入数据

导入镜像需要等待一会;cobbler导入的镜像路径:/var/www/cobbler/ks_mirror

1
2
3
4
mkdir /mnt/centos7.4
mount /dev/cdrom /mnt/centos7.4
cobbler import --path=/mnt/centos7.4 --name=CentOS-7.4 --arch=x86_64
ls /var/www/cobbler/ks_mirror

查看导入的镜像信息

1
2
3
cobbler list
cobbler profile report
cobbler profile edit --help

指定无人值守文件;修改内核网卡名称

1
2
3
4
cp -a /var/lib/cobbler/kickstarts/sample_end.ks /var/lib/cobbler/kickstarts/CentOS-7.4-x86_64.cfg
cobbler profile edit --name=CentOS-7.4-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7.4-x86_64.cfg
cobbler profile edit --name=CentOS-7.4-x86_64 --kopts='net.ifnames=0 biosdevname=0'
cobbler profile report

重新启动服务

1
2
3
systemctl restart cobblerd
cobbler sync
systemctl restart xinetd

web管理

https://192.168.3.10/cobbler_web
默认username: cobblerd
默认password: cobblerd

客户端使用koan重装系统

--list=profiles 查看服务器镜像列表
--profile=CentOS-7.4-x86_64使用此镜像重装系统

1
2
3
yum install koan
koan --server=192.168.3.10 --list=profiles
koan --server=192.168.3.10 --profile=CentOS-7.4-x86_64 --replace-self