pxe+kickstart实现自动化安装系统

相逢意气为君饮,系马高楼垂柳边。这篇文章主要讲述pxe+kickstart实现自动化安装系统相关的知识,希望能为你提供帮助。
一、要求的环境:
  Rhel8两块网卡
              一块网卡桥接到我的物理网络,用作管理,可以ssh登录。地址是192.168.8.128
              另一块网卡通过VMware的vmnet10连接,且vmnet10的dhcp关闭,这个网卡的地址是10.1.0.1/24
              开启另外一台服务器,该服务器没有操作系统,网络也要调到仅主机
?
(一)pxe配置部分
1、挂载光盘配置软件仓库
[root@ssh-server ~]# mount /dev/sr0 /iso/
 
2、创建yum仓库
[root@ssh-server ~]# cat /etc/yum.repos.d/iso.repo

[iso]
name = iso repo
enable = yes
gpgcheck = 0
baseurl = file:///iso/BaseOS


[wjg]
name = wjg repo
enable = yes
gpgcheck = 0
baseurl = file:///iso/AppStream

 


二、安装dhcp服务端软件
1、安装dhcp
[root@ssh-server ~]# yum -y install dhcp-server
2、编辑dhcp-server的配置文件
[root@ssh-server ~]# vim /etc/dhcp/dhcpd.conf
subnet 10.1.0.0 netmask 255.255.255.0
range 10.1.0.100 10.1.0.200;


3、重启dhcp服务
[root@ssh-server dhcp]# systemctl restart dhcpd
[root@ssh-server dhcp]# systemctl enable dhcpd
[root@ssh-server dhcp]# netstat -anptul |grep dhcp
 
4、关闭防火墙,关闭selinux
[root@ssh-server dhcp]# systemctl disable firewalld --now
[root@ssh-server dhcp]# setenforce 0
 
三、搭建tftp服务器
1、安装tftp-server软件
[root@ssh-server ~]# yum -y install tftp-server
2、启动tftp服务器
[root@ssh-server ~]# systemctl enable tftp --now
[root@ssh-server ~]# netstat -anptul |grep 69
 
3、找到pxelinux.0文件,将这个文件放入/var/lib/tftpboot
[root@ssh-server ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
    注意:如果没有pxelinux.0包,需要安装yum -y install syslinux
4、修改dhcp服务器配置文件
[root@ssh-server ~]# vim /etc/dhcp/dhcpd.conf
subnet 10.1.0.0 netmask 255.255.255.0
range 10.1.0.100 10.1.0.200;
next-server 10.1.0.1;
filename "pxelinux.0";

 
    注意:记得重启服务
dhcp服务器告诉dhcp客户端,如果你是pxe引导,那么tftp服务器的地址是10.1.0.1,你可以到tftp服务器上的根目录上下载pxelinux.0
[root@ssh-server ~]# cp /usr/share/syslinux/ldlinux.c32   /var/lib/tftpboot/
5、创建pxelinux.cfg
该目录是pxe客户端在执行完pxelinux.0后会自动请求的一个目录,会请求该目录下的boot menu。
[root@ssh-server ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@ssh-server ~]# cp -rf /usr/share/syslinux/* /var/lib/tftpboot/
 
6、创建一个配置文件,并编辑
[root@ssh-server ~]# vim /var/lib/tftpboot/pxelinux.cfg/default
default menu.c32
timeout 10
label jackpxewjg

 
?
四、搭建http服务器
1、安装httpd
[root@ssh-server ~]# yum -y install httpd
2、创建光盘挂载点
[root@ssh-server ~]# mkdir /var/www/html/jingxiang
3、挂载光盘
[root@ssh-server ~]# mount /dev/sr0 /var/www/html/jingxiang
【pxe+kickstart实现自动化安装系统】4、启动服务
[root@ssh-server ~]# systemctl enable httpd --now
5、将这两个文件拷贝过去
[root@ssh-server html]# cp /iso/isolinux/vmlinuz  /iso/isolinux/initrd.img  /var/lib/tftpboot/
6、编辑default
[root@ssh-server ~]# vim /var/lib/tftpboot/pxelinux.cfg/default
default menu.c32
timeout 10
label jackpxewjg
kernel vmlinuz
append initrd=initrd.img method=http://10.1.0.1/jingxiang

 
然后在新机上启动虚拟机就可以看到配置界面了。
 
(二)Kickstart配置
1、在/var/www/html/整一个配置文件
[root@ssh-server ~]# vim /var/www/html/wjg.cfg
#version=RHEL8
ignoredisk --only-use=nvme0n1
autopart --type=lvm
# Partition clearing information
clearpart --all --initlabel
# Use graphical install
text
url --url="http://10.1.0.1/jingxiang"
# Use CDROM installation media
# Keyboard layouts
keyboard --vckeymap=cn --xlayouts=cn
# System language
lang zh_CN.UTF-8
reboot
# Network information
network--bootproto=dhcp --device=ens160 --onboot=off --ipv6=auto --no-activate
network--hostname=localhost.localdomain
# Root password
rootpw --iscrypted $1$pNClbHxi$0hEF4ILod8uP340tMXmRU.
# X Window System configuration information
xconfig--startxonboot
# Run the Setup Agent on first boot
firstboot --enable
# System services
services --disabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc --nontp
user --groups=wheel --name=wjg --password=$1$pNClbHxi$0hEF4ILod8uP340tMXmRU. --iscrypted --gecos="wjg"

%packages
@^graphical-server-environment
kexec-tools

%end

%addon com_redhat_kdump --disable --reserve-mb=auto

%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

?
2、在  /var/lib/tftpboot/pxelinux.cfg/default改配置文件
[root@ssh-server ~]# vim /var/lib/tftpboot/pxelinux.cfg/default
default menu.c32
timeout 10
label jackpxewjg
kernel vmlinuz
append initrd=initrd.img method=http://10.1.0.1/jingxiang ks=http://10.1.0.1/wjg.cfg

 
3、开启新虚机等待就行

    推荐阅读