一、实验题目
基于Cobbler实现多版本系统批量部署
二、实验目的
通过Cobbler,实验旨在实现无需人工干预即可自动安装多个版本的操作系统。这可以大大提高机房设备或服务器集群的部署效率,减少人力成本和操作错误。
三、实验环境
centos7.9并安装Cobbler及其依赖服务(如DHCP、TFTP、HTTP等)。
配置EPEL源(如果系统默认源中没有Cobbler),因为Cobbler可能依赖于EPEL源中的某些包。
四、实验内容
- 安装Proxmox VE。
- 创建 Proxmox VE 集群。
- 添加共享存储(NFS)
- 上次rocky linux 8.x镜像,创建主机vm1。
- 下载CT模板 ubuntu-22.04,创建CT名称为vm2。
- vm1迁移。
- vm1克隆和快照。
五、实验步骤
第一步:
#centos7 换阿里yum源
cd /etc/yum.repos.d/
mkdir bak_repo
mv *.repo bak_repo/
curl -O https://mirrors.aliyun.com/repo/Centos-7.repo
第二步:
# 关闭防火墙、禁用SELinux
systemctl disable --now firewalld
sed -i '/^SELINUX=/ c SELINUX=disabled' /etc/selinux/config
第三步:
# 配置epel源
yum install
http://ftp.situ.edu.cn/fedora/epel/7/x86_64/Packages/e/epel-release-7-14.noarch.rpm -y
第四步:
安装dhcp httpd xinetd
yum install -y httpd dhcp xinetd tftp-server
安装cobbler
yum install -y cobbler cobbler-web
第五步:
[root@cobbler ~]# cobbler check
#执行这个命令后会出现下面十个问题,下面我们来一一解决
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 : SELinux is enabled. Please review the following wiki page for details on ensuring cobbler works correctly in your SELinux environment:
https://github.com/cobbler/cobbler/wiki/Selinux
4 : change 'disable' to 'no' in /etc/xinetd.d/tftp
5 : Some network boot-loaders are missing from /var/lib/cobbler/loaders. 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.
6 : enable and start rsyncd.service with systemctl
7 : debmirror package is not installed, it will be required to manage debian deployments and repositories
8 : ksvalidator was not found, install pykickstart
9 : 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
10 : 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.
首先改成自己的IP地址
[root@cobbler ~]# sed -i 's#server: 127.0.0.1#server: 192.168.121.8#g' /etc/cobbler/settings #192.168.121.8写成自己的ip地址
[root@cobbler ~]# sed -i 's#next_server: 127.0.0.1#next_server: 192.168.121.8#g' /etc/cobbler/settings #192.168.121.8写成自己的ip地址
然后进入到
[root@cobbler ~]# vim /etc/xinetd.d/tftp
把disable改为no
然后需要loaders.tar.gz文件导入到centos7.9里面
执行 yum install lrzsz -y
tar xf loaders.tar.gz -C /var/lib/cobbler/loaders/
systemctl enable --now rsyncd.service
yum install pykickstart
执行:
[root@cobbler ~]# openssl passwd -1 -salt `openssl rand -hex 8` '123456'
$1$b03d519c$/I0WqBte6biWEoZL3G0LO.
把这个值复制下来粘贴到vim /etc/cobbler/settings
default_password_crypted: "$1$b03d519c$/I0WqBte6biWEoZL3G0LO."
再执行:
[root@cobbler ~]# yum install cman fence-agents -y
完成之后重启一下
[root@cobbler ~]# cobbler check
The following are potential configuration items that you may want to fix:
1 : SELinux is enabled. Please review the following wiki page for details on ensuring cobbler works correctly in your SELinux environment:
https://github.com/cobbler/cobbler/wiki/Selinux
2 : debmirror package is not installed, it will be required to manage debian deployments and repositories
Restart cobblerd and then run 'cobbler sync' to apply changes.
上述两个不用管开始下一步
[root@cobbler ~]# cobbler get-loaders
改dhcp(写自己的):
[root@cobbler cobbler]# vim /etc/cobbler/dhcp.template
#manage_dhcp: 0 #设置为1时,开启cobbler的dhcp管理器
subnet 192.168.121.0 netmask 255.255.255.0 {
option routers 192.168.121.2;
option domain-name-servers 223.5.5.5;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.121.100 192.168.121.200;
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
class "pxeclients" {
setenforce 0
getenforce
然后浏览器访问https://ip/cobbler_web
写自己的ip地址,账号和密码都是cobbler
页面如下所示
第六步:
在cobbler进行批量部署centos7/8
7的镜像已经挂载了,创建一个目录我们把8的镜像传进去
#再创建目录
[root@cobbler iso]# mkdir -p CentOS/X86_64/CentOS{7..8}/dvd
看一下自己的centos7是否挂载
然后创建镜像导入存放目录,导入dvd 数据
[root@cobbler iso]# mkdir -p /CentOS/X86_64/CentOS{7..8}/dvd
[root@cobbler iso]# mount /dev/cdrom /CenOS/X86_64/CentOS7/dvd
[root@cobbler iso]# mount /iso/CentOS-8.1.1911-x86_64-dvd1.iso /CentOS/X86_64/CentOS8/dvd
mount: /dev/loop0 is write-protected, mounting read-only
[root@cobbler iso]# cobbler import --path=/CentOS/X86_64/CentOS8/dvd/ --name=CentOS8.1 --arch=x86_64
第七步:
创建新的模版
写入如下代码:
# Cobbler for Kickstart Configurator for CentOS 7 by yao zhang
install
url --url=$tree
text
lang en_US.UTF-8
keyboard us
zerombr
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
#Network information
$SNIPPET('network_config')
#network --bootproto=dhcp --device=eth0 --onboot=yes --noipv6 --hostname=CentOS7
timezone --utc Asia/Shanghai
authconfig --enableshadow --passalgo=sha512
rootpw --iscrypted $default_password_crypted
clearpart --all --initlabel
part /boot --fstype xfs --size 1024
part swap --size 1024
part / --fstype xfs --size 1 --grow
firstboot --disable
selinux --disabled
firewall --disabled
logging --level=info
reboot
%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%end
%packages
@^minimal
@compat-libraries
@core
@debugging
@development
bash-completion
chrony
dos2unix
kexec-tools
lrzsz
nmap
sysstat
telnet
tree
vim
wget
%end
%post
systemctl disable postfix.service
%end
再给centos8创建一个
写出如下代码
#version=RHEL8
install
ignoredisk --only-use=sda
# Partition clearing information
clearpart --all --initlabel
# Use graphical install
text
# Use CDROM installation media
url --url=$tree
reboot
# Keyboard layouts
keyboard --vckeymap=cn --xlayouts='cn'
# System language
lang en_US.UTF-8
selinux --disabled
firewall --disabled
# Network information
network --bootproto=dhcp --device=ens160 --ipv6=auto --activate
network --hostname=wenzi.localhost
# Root password
rootpw --iscrypted
$default_password_crypted
# Run the Setup Agent on first boot
firstboot --enable
# Do not configure the X Window System
skipx
# System services
services --disabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc --nontp
# Disk partitioning information
zerombr
part /boot --fstype="ext4" --ondisk=sda --size=1024
part /swap --fstype="swap" --ondisk=sda --size=2048
part / --fstype="xfs" --ondisk=sda --grow --size=1
%packages
@^minimal-environment
kexec-tools
%end
%addon com_redhat_kdump --enable --reserve-mb='auto'
%end
%post
%end
%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
记得点击save保存
然后进行验证即可