一、cobbler简介
cobbler是一款自动化操作系统安装的实现,与PXE安装系统的区别是可以同时部署多个版本的系统,而PXE只能选择一种系统。
二、安装cobbler
安装yum源
yum install epel-release -y
yum install dhcp tftp-server xinetd httpd cobbler cobbler-web pykickstart debmirror -y
修改配置文件
vim /etc/cobbler/settings
设置server和next_serverIP为服务端IP
生成加密密码,根据配置文件中的提示直接复制命令生成即可
openssl passwd -1 123456
修改tftp配置文件,开启tftp服务
vim /etc/xinetd.d/tftp
配置dhcp服务
vim /etc/dhcp/dhcpd.conf
subnet 10.10.10.0 netmask 255.255.255.0 {
option routers 10.10.10.11;
range 10.10.10.100 10.10.10.200;
}
next-server 10.10.10.11;
filename="pxelinux.0";
禁用非标准化操作系统
vim /etc/debmirror.conf
安装cman和fence-agents把安装好的操作系统隔离出去
yum isntall cman fence-agents -y
启动服务,并加入开机自启动
systemctl start dhcpd
systemctl start httpd
systemctl start cobblerd
systemctl start xinetd
systemctl start rsyncd
systemctl enable httpd cobblerd xinetd rsyncd dhcpd #加入开机自启
加载并验证配置文件
cobbler sync #加载配置文件
cobbler check #验证配置文件
#由于cobbler取消了get-loaders命令,所以需要手动添加启动文件
cp /usr/share/syslinux/pxelinux.0 /var/lib/cobbler/loaders/
cp /usr/share/syslinux/menu.c32 /var/lib/cobbler/loaders/
若执行cobbler check后出现以下提示表示正常
三、导入镜像文件
将镜像文件挂载到本地.虚拟机中挂载一定要提前连接好CD设备,否则会挂载失败。
mount -t iso9660 /dev/cdrom /mnt/
挂载完毕后导入到cobbler
cobbler import --name="centos7.5.1804" --path=/mnt
默认的ks配置文件在/var/lib/cobbler/kickstarts,也可以自己生成一份配置文件上传至该目录下即可
#查看上传的镜像
cobbler distro list
#查看ks配置文件
cobbler profile list
#查看配置的镜像信息
cobbler distro report
#上传自定义ks配置文件前,需要将自动生成的文件删除掉
cobbler profile remove --name=centos7.5.1804-x86_64
#添加配置文件
cobbler profile add --name=centos7.5 --distro=centos7.5.1804-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.cfg
四、新建虚拟机测试
通过system-config-kickstart 软件生成的cfg文件需要删掉首行的前两句,否则会报错。
客户机通过网卡启动时会弹出一个可选菜单,选择需要安装的系统即可全自动进行安装
五、cobbler环境部署脚本
此脚本能够自动部署cobbler所需运行环境,并生成两个ks文件分别是最小化安装和图形化安装。可根据自己需要进行导入
由于此脚本实在虚拟机中执行部署,如需用于生产环境请根据需要自行修改。
#!/bin/bash
#获取当前主机IP
IPADD=$(hostname -I|awk '{print $1}')
#提取IP地址前三段
ip_range=$(hostname -I|awk '{print $1}'|head -c 9)
#生成随机密码
passwd=$(openssl passwd -1 123456)
#安装cobbler所依赖的源
yum install epel-release -y
yum install dhcp tftp-server xinetd httpd cobbler cobbler-web pykickstart debmirror -y
sleep 1
yum makecache
sleep 2
#修改settings文件
sed -i "s/^server: 127.0.0.1/server: $IPADD/" /etc/cobbler/settings
sed -i "s/^next_server: 127.0.0.1/next_server: $IPADD/" /etc/cobbler/settings
#修改tftp配置文件
sed -i "/disable/s/yes/no/ " /etc/xinetd.d/tftp
#配置dhcp服务器
cat >> /etc/dhcp/dhcpd.conf <<EOF
subnet ${ip_range}0 netmask 255.255.255.0 {
option routers ${IPADD};
range ${ip_range}100 ${ip_range}200;
}
next-server ${IPADD};
filename="pxelinux.0";
EOF
#禁用非标准化操作系统和32位操作系统
sed -i "s/@dists=\"sid\";/#@dists=\"sid\";/ " /etc/debmirror.conf
sed -i "s/@arches=\"i386\";/#@arches=\"i386\";/ " /etc/debmirror.conf
#安装cman和fence-agents
yum install cman fence-agents -y
#由于cobbler取消了get-loaders命令,所以需要手动添加启动文件
cp /usr/share/syslinux/pxelinux.0 /var/lib/cobbler/loaders/
cp /usr/share/syslinux/menu.c32 /var/lib/cobbler/loaders/
sleep 3
#启动服务并加入开机自启
systemctl start dhcpd
systemctl start httpd
systemctl start cobblerd
systemctl start xinetd
systemctl start rsyncd
systemctl enable httpd cobblerd xinetd rsyncd dhcpd
sleep 2
#修改默认密码
sed -i "s|^default_password_crypted.*|default_password_crypted: \""$passwd"\"|" /etc/cobbler/settings
#重启服务
systemctl restart cobblerd
#导入配置文件
cobbler sync
sleep 1
echo ""
#验证配置文件
cobbler check
sleep 1
echo ""
#挂载镜像文件
echo "镜像挂载在/mnt目录下"
mount -t iso9660 /dev/cdrom /mnt/
#上传镜像到cobbler目录下
cobbler import --name="centos7.5" --path=/mnt
#查看镜像文件
echo -e "\033[31m上传的镜像为↓↓↓↓↓↓↓↓↓↓↓↓\033[0m"
cobbler distro list
echo -e "\033[31m↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑\033[0m"
#ks配置文件:图形化配置文件
cat > /root/gonme_desk.cfg <<EOF
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted \$default_password_crypted
# System language
lang en_US
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# SELinux configuration
selinux --disabled
# Firewall configuration
firewall --disabled
# Reboot after installation
reboot
# System timezone
timezone Africa/Abidjan
# Use network installation
url --url="\$tree"
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="xfs" --size=600
part swap --fstype="swap" --size=4000
part / --fstype="xfs" --grow --size=1
%packages
@^gnome-desktop-environment
@base
@core
@desktop-debugging
@dial-up
@directory-client
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@input-methods
@internet-browser
@java-platform
@multimedia
@network-file-system-client
@networkmanager-submodules
@print-client
@x11
chrony
kexec-tools
%end
EOF
#最小化安装配置文件
cat > /root/os_base.cfg <<EOF
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted \$default_password_crypted
# System language
lang en_US
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# SELinux configuration
selinux --disabled
# Firewall configuration
firewall --disabled
# Reboot after installation
reboot
# System timezone
timezone Africa/Abidjan
# Use network installation
url --url="\$tree"
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="xfs" --size=600
part swap --fstype="swap" --size=4000
part / --fstype="xfs" --grow --size=1
%packages
@base
@core
%end
EOF
#拷贝配置文件到ks目录下
echo "带桌面安装系统ks文件:/var/lib/cobbler/kickstarts/gonme_desk.cfg"
cp /root/gonme_desk.cfg /var/lib/cobbler/kickstarts/
echo "最小化安装系统ks文件:/var/lib/cobbler/kickstarts/os_base.cfg"
cp /root/os_base.cfg /var/lib/cobbler/kickstarts/
echo ""
echo ""
#选择需要的ks文件与上传的镜像做绑定,替换自定义ks文件之前需要先删除自动生成的文件
cat <<EOF
1.查看自动生成的ks文件:cobbler profile list
2.删除自动生成的ks文件:cobbler profile remove --name=此处填写ks文件名称
3.添加自定义ks文件:cobbler profile add --name=名称自定义 --distro=这里需要与上传的镜像名一致 --kickstart=ks文件所在位置
EOF
标签:批量,配置文件,server,etc,cobbler,yum,Linux,Cobbler,tftp
From: https://blog.51cto.com/qclr/7250961