PXE介绍
PXE(Preboot Execution Environment)是预引导执行环境的缩写。它是由Intel设计的,允许客户端计算机通过网络从服务器上加载操作系统镜像。PXE通常用于大规模部署操作系统,例如在企业或学校环境中。
PXE工作流程如下:
- 当计算机启动时,BIOS 会进行 POST(Power-On Self-Test)自检,检查硬件是否正常运行。
- BIOS 随后会从默认启动设备(通常是硬盘)加载引导加载程序(Bootloader)。
- Bootloader 会查找并加载 PXE 客户端软件(通常是 Intel 的 PXE Client)。
- PXE Client 通过广播寻找并选择可用的 PXE 服务端(通常是服务器)。
- 服务器通过 TFTP(Trivial File Transfer Protocol)协议将操作系统镜像发送到客户端。
- 客户端计算机接收并加载操作系统镜像,然后开始安装操作系统。
因此,通过 PXE,IT 管理员可以在大型网络中自动化和集中管理操作系统部署。
更改IP
- 根据需求修改
sed -ri 's/192.168.10.10/172.18.13.99/g' autoinstall.sh
sed -ri 's/192.168.10./172.18.13./g' autoinstall.sh
- 执行脚本
bash autoinstall.sh
脚本内容示例
#!/bin/bash#挂载光盘
mkdir /media/cdrom
echo "/dev/sr0 /media/cdrom iso9660 defaults 0 0" >> /etc/fstab
mount -a#配置本地YUM源
touch /etc/yum.repos.d/rhel8.repo
cat > /etc/yum.repos.d/rhel8.repo <<EOF
[BaseOS]
name=BaseOS
baseurl=file:///media/cdrom/BaseOS
enabled=1
gpgcheck=0
[AppStream]
name=AppStream
baseurl=file:///media/cdrom/AppStream
enabled=1
gpgcheck=0
EOF
#同步YUM仓库
dnf makecache#清除规则并关闭防火墙
iptables -F
systemctl stop firewalld
systemctl disable firewalld
systemctl status firewalld
#关闭selinux
setenforce 0
sed -ri 's/=enforcing/=disabled/g' /etc/selinux/config
cat /etc/selinux/config
getenforce#安装配置dhcp
dnf install -y dhcp-servercat > /etc/dhcp/dhcpd.conf <<EOF
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp-server/dhcpd.conf.example
# see dhcpd.conf(5) man page
#
allow booting;
allow bootp;
ddns-update-style none;
ignore client-updates;
subnet 172.16.13.0 netmask 255.255.255.0 {option subnet-mask 255.255.255.0;option domain-name-servers 172.16.13.99;range dynamic-bootp 172.16.13.110 172.16.13.200;default-lease-time 21600;max-lease-time 43200;next-server 172.16.13.99;filename "pxelinux.0";
}
host yjy-test-01 {hardware ethernet 00:0c:29:df:6c:a0;fixed-address 172.16.13.199;
}
EOF
systemctl start dhcpd
systemctl enable dhcpd
systemctl status dhcpdsleep 5#安装配置tftp-server、xinetd
dnf install -y tftp-server xinetd
touch /etc/xinetd.d/tftp
cat > /etc/xinetd.d/tftp <<EOF
service tftp
{socket_type = dgramprotocol = udpwait = yesuser = rootserver = /usr/sbin/in.tftpdserver_args = -s /var/lib/tftpbootdisable = noper_source = 11cps = 100 2flags = IPv4
}
EOF
systemctl start xinetd
systemctl enable xinetd
systemctl status xinetdsleep 5#安装syslinux,COPY相关配置文件
dnf install -y syslinux
unalias cp
cp -f /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
cp -f /media/cdrom/images/pxeboot/* /var/lib/tftpboot/
cp -f /media/cdrom/isolinux/* /var/lib/tftpboot/
mkdir /var/lib/tftpboot/pxelinux.cfg
cp /media/cdrom/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
chmod 755 /var/lib/tftpboot/pxelinux.cfg/default
sed -ri 's@default vesamenu.c32@default linux@g' /var/lib/tftpboot/pxelinux.cfg/default
sed -ri 's@hd:LABEL=RHEL-8-0-0-BaseOS-x86_64 quiet@ftp://172.16.13.99 ks=ftp://172.16.13.99/pub/ks.cfg quiet@g' /var/lib/tftpboot/pxelinux.cfg/defaultsleep 5#安装配置vsftpd
dnf install -y vsftpd
sed -ri 's/anonymous_enable=NO/anonymous_enable=YES/g' /etc/vsftpd/vsftpd.conf
systemctl start vsftpd
systemctl enable vsftpd
systemctl status vsftpd#COPY数据到ftp目录并设置SELinux(虽然开始关了-_-)
cp -r /media/cdrom/* /var/ftp
setsebool -P ftpd_connect_all_unreserved=on#创建KickStart应答文件
touch /var/ftp/pub/ks.cfg
chmod 755 /var/ftp/pub/ks.cfg
cat > /var/ftp/pub/ks.cfg <<EOF
#version=RHEL8
ignoredisk --only-use=sda
# Partition clearing information
clearpart --none --initlabel
# Use graphical install
graphical
#repo --name="AppStream" --baseurl=file:///run/install/repo/AppStream
repo --name="AppStream" --baseurl=ftp://172.16.13.99/AppStream
# Use CDROM installation media
#cdrom
url --url=ftp://172.16.13.99/BaseOS
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8
# selinux configuration
selinux --disabled#Reboot after installation
reboot# Network information
network --bootproto=dhcp --device=ens160 --onboot=on --ipv6=auto --activate
network --hostname=test
# Root password
rootpw 123456
# 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
part /boot --fstype="xfs" --ondisk=sda --size=1024
part pv.217 --fstype="lvmpv" --ondisk=sda --size=1 --grow
volgroup rhel --pesize=4096 pv.217
logvol / --fstype="xfs" --grow --size=1024 --name=root --vgname=rhel
logvol swap --fstype="swap" --size=2047 --name=swap --vgname=rhel%packages
@^server-product-environment
kexec-tools%end%addon com_redhat_kdump --enable --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
EOFsystemctl restart dhcpd
systemctl restart xinetd
systemctl restart vsftpd
systemctl status dhcpd
systemctl status xinetd
systemctl status vsftpd
分享、在看与点赞
只要你点,我们就是胖友
来自: RHEL8/Centos8 install for PXEhttps://mp.weixin.qq.com/s?__biz=Mzk0NTQ3OTk3MQ==&mid=2247485775&idx=1&sn=99c2678ffc2dfef9552d84a9ebef6388&chksm=c3158103f462081511d082242469d3f7aa7e8d66e314f39cad457c2c9b2926300f1b0c71781d&token=355315523&lang=zh_CN#rd