背景
在学习与测试中,难免会遇到使用不同版本Linux操作系统的情况,如何实现多版本定制Linux操作系统自动安装部署,免除重复性工作,实现基础环境部署标准化,那么选择pxe-kickstart是不二之选。
下面介绍使用Kickstart同时部署Centos7.6.1810、rhel7.9。
1 环境
环境:CentOS Linux release 7.6.1810 (Core) 最小化安装
IP :192.168.150.222
安装系统基础支持RPM包
DHCP服务器:为 PXE-client 分配 IP ,获得安装程序文件位置
TFTP服务器:传输安装文件pxelinux.0、vesamenu.c32、initrd.img、vmlinuz、default内核文件等给 PXE-client
Kickstart:生成的ks.cfg配置文件,定制操作系统
选http/nfs/ftp 服务中的一种,本次采用ftp文件传输协议,用于传送安装源文件给 PXE-client
2 配置yum源
mount /dev/sr0 /mnt
cat >centos7.6.repo<<EOF
[c7.6]
name=centos7.6
baseurl=file:///mnt
gpgcheck=0
enabled=1
EOF
安装所需服务的RPM包 :
yum install tftp tftp-server vsftpd xinetd dhcp system-config-kickstart syslinux
2 配置vsftpd服务
vsftpd配置:/etc/vsftpd/vsftpd.conf
cat >/etc/vsftpd/vsftpd.conf<<EOF
anonymous_enable=YES
anon_root=/var/ftp/pub
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=YES
pam_service_name=vsftpd
EOF
/etc/vsftpd/ftpusers 此文件中的用户名列表是不允许连接FTP的
sed -i ‘s/^root/#root/g’ /etc/vsftpd/ftpusers
cat /etc/vsftpd/ftpusers
#-Users that are not allowed to login via ftp
#root # 将root注释
…分割线
启动服务及查看服务状态
systemctl start vsftpd
systemctl status vsftpd
3 将ISO文件复制到ftp目录
mkdir -p /var/ftp/pub/iso/{enmo,centos76}
mount /dev/sr0 /mnt
cp -pr /mnt/* /var/ftp/pub/iso/centos76/
umount /mnt
换盘
mount /dev/sr0 /mnt
cp -pr /mnt/* /var/ftp/pub/iso/enmo/
4 配置dhcp服务
dhcp配置:
cat >/etc/dhcp/dhcpd.conf<<EOF
#-
#-DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.example
# see dhcpd.conf(5) man page
#-
ddns-update-style none;
ignore client-updates;
subnet 192.168.150.0 netmask 255.255.255.0{
option routers 192.168.150.2;
option subnet-mask 255.255.255.0;
range 192.168.150.230 192.168.150.245;
default-lease-time 604800;
max-lease-time 605800;
next-server 192.168.150.222;
filename “pxelinux.0”;
}
EOF
启动服务及查看服务状态:
systemctl start dhcpd
systemctl status dhcpd
5 配置xinetd 中tftp服务
tftp配置:/etc/xinetd.d/tftp
cat >/etc/xinetd.d/tftp<<EOF
#-default: off
#-description: The tftp server serves files using the trivial file transfer
# protocol. The tftp protocol is often used to boot diskless
# workstations, download configuration files to network-aware printers,
# and to start the installation process for some operating systems.
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot # tftp传输系统启动文件存放目录
disable = no # 原为yes 改为 no
per_source = 11
cps = 100 2
flags = IPv4
}
EOF
启动服务及查看服务状态:
systemctl start xinetd
systemctl status xinetd
查看TFTP服务端口:
lsof -i:69
6 ks.cfg文件的配置
界面采用:Xmanager - Passive
设置环境变量:export DISPLAY=192.168.150.222:0.0
system-config-kickstart
第一步:basic configration 输入root用户密码,勾选安装完成后重新引导系统与采用文件本模式进行安装两个复选框,其余选项根据实际需求定
第二步:installation method 安装源采用FTP Server:192.168.150.222 FTP Directory:/iso/enmo,本次实验采用的是ftp的默认目录,当输入用户与密码后采用用户的目录(关于nfs,http需要)
第三步:默认
第四步:第一次安装系统选择 clear master boot record ,remove existing partitions,disklabel 默认
分区:swap /boot / 可以根据实际需求定
第五步:网络配置:eth0 自动分配或指定静态地址
第六步:验证
第七步:防火墙配置selinux disabled
第八步:显示配置
第九步:包选择,根据实际需求选择
第十步:安装前执行的脚本
第十一步:安装后执行的脚本
保存配置cent76.cfg。
最后将文件保存在
/var/ftp/pub/ks/cent76.cfg
/var/ftp/pub/ks/zdata.cfg
此文件在enmo定制光盘中 ks目录下。
7 tftp传输系统启动文件需要从源/var/ftp/pub/iso/{centos76,enmo}中复制到tftp配置文件中指定的目录/var/lib/tftpboot/{centos76,enmo}
ll /var/ftp/pub/iso/enmo/isolinux/{vmlinuz,vesamenu.c32,splash.png,initrd.img,boot.msg}
ll /var/ftp/pub/iso/enmo/isolinux/isolinux.cfg
cp /var/ftp/pub/iso/enmo/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/enmo/
cp /var/ftp/pub/iso/centos76/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/centos76/
cp /var/ftp/pub/iso/enmo/isolinux/{vesamenu.c32,splash.png,boot.msg} /var/lib/tftpboot/
mkdir -p /var/lib/tftpboot/pxelinux.cfg
cp /var/ftp/pub/iso/enmo/isolinux/isolinux.cfg /var/lib/tftpboot/isolinux.cfg/default
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/pxelinux.0 # 此文件只有Yum安装syslinux包才会有
ll /var/lib/tftpboot/pxelinux.cfg/default
cat >/var/lib/tftpboot/pxelinux.cfg/default<<EOF
default vesamenu.c32
timeout 600
display boot.msg
menu clear
menu background splash.png
menu title CentOS 7
menu vshift 8
menu rows 18
menu margin 8
#menu hidden
menu helpmsgrow 15
menu tabmsgrow 13
menu color border * #00000000 #00000000 none
menu color sel 0 #ffffffff #00000000 none
menu color title 0 #ff7ba3d0 #00000000 none
menu color tabmsg 0 #ff3a6496 #00000000 none
menu color unsel 0 #84b8ffff #00000000 none
menu color hotsel 0 #84b8ffff #00000000 none
menu color hotkey 0 #ffffffff #00000000 none
menu color help 0 #ffffffff #00000000 none
menu color scrollbar 0 #ffffffff #ff355594 none
menu color timeout 0 #ffffffff #00000000 none
menu color timeout_msg 0 #ffffffff #00000000 none
menu color cmdmark 0 #84b8ffff #00000000 none
menu color cmdline 0 #ffffffff #00000000 none
menu tabmsg Press Tab for full configuration options on menu items.
menu separator # insert an empty line
menu separator # insert an empty line
label linux7
menu label ^Install CentOS 7
kernel centos76/vmlinuz
append initrd=centos76/initrd.img repo=ftp://192.168.150.222/iso/centos76 ks=ftp://192.168.150.222/ks/cent76.cfg
label enmo
menu label ^Install Red Hat Enterprise Linux 7.9
kernel enmo/vmlinuz
append initrd=enmo/initrd.img repo=ftp://192.168.150.222/iso/enmo ks=ftp://192.168.150.222/ks/zdata.cfg
menu end
EOF
最后启动裸虚拟机就可以实现自动安装系统了。




