
点击上方蓝字:Linux技术宅,关注我!!!

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 管理员可以在大型网络中自动化和集中管理操作系统部署。

根据需求修改
sed -ri 's/192.168.10.10/172.18.13.99/g' autoinstall.shsed -ri 's/192.168.10./172.18.13./g' autoinstall.sh
执行脚本
bash autoinstall.sh

#!/bin/bash#挂载光盘mkdir /media/cdromecho "/dev/sr0 media/cdrom iso9660 defaults 0 0" >> etc/fstabmount -a#配置本地YUM源touch /etc/yum.repos.d/rhel8.repocat > etc/yum.repos.d/rhel8.repo <<EOF[BaseOS]name=BaseOSbaseurl=file:///media/cdrom/BaseOSenabled=1gpgcheck=0[AppStream]name=AppStreambaseurl=file:///media/cdrom/AppStreamenabled=1gpgcheck=0EOF#同步YUM仓库dnf makecache#清除规则并关闭防火墙iptables -Fsystemctl stop firewalldsystemctl disable firewalldsystemctl status firewalld#关闭selinuxsetenforce 0sed -ri 's/=enforcing/=disabled/g' etc/selinux/configcat /etc/selinux/configgetenforce#安装配置dhcpdnf 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;}EOFsystemctl start dhcpdsystemctl enable dhcpdsystemctl status dhcpdsleep 5#安装配置tftp-server、xinetddnf install -y tftp-server xinetdtouch /etc/xinetd.d/tftpcat > etc/xinetd.d/tftp <<EOFservice tftp{socket_type = dgramprotocol = udpwait = yesuser = rootserver = /usr/sbin/in.tftpdserver_args = -s var/lib/tftpbootdisable = noper_source = 11cps = 100 2flags = IPv4}EOFsystemctl start xinetdsystemctl enable xinetdsystemctl status xinetdsleep 5#安装syslinux,COPY相关配置文件dnf install -y syslinuxunalias cpcp -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.cfgcp /media/cdrom/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/defaultchmod 755 /var/lib/tftpboot/pxelinux.cfg/defaultsed -ri 's@default vesamenu.c32@default linux@g' /var/lib/tftpboot/pxelinux.cfg/defaultsed -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#安装配置vsftpddnf install -y vsftpdsed -ri 's/anonymous_enable=NO/anonymous_enable=YES/g' /etc/vsftpd/vsftpd.confsystemctl start vsftpdsystemctl enable vsftpdsystemctl status vsftpd#COPY数据到ftp目录并设置SELinux(虽然开始关了-_-)cp -r /media/cdrom/* /var/ftpsetsebool -P ftpd_connect_all_unreserved=on#创建KickStart应答文件touch /var/ftp/pub/ks.cfgchmod 755 /var/ftp/pub/ks.cfgcat > /var/ftp/pub/ks.cfg <<EOF#version=RHEL8ignoredisk --only-use=sda# Partition clearing informationclearpart --none --initlabel# Use graphical installgraphical#repo --name="AppStream" --baseurl=file:///run/install/repo/AppStreamrepo --name="AppStream" --baseurl=ftp://172.16.13.99/AppStream# Use CDROM installation media#cdromurl --url=ftp://172.16.13.99/BaseOS# Keyboard layoutskeyboard --vckeymap=us --xlayouts='us'# System languagelang en_US.UTF-8# selinux configurationselinux --disabled#Reboot after installationreboot# Network informationnetwork --bootproto=dhcp --device=ens160 --onboot=on --ipv6=auto --activatenetwork --hostname=test# Root passwordrootpw 123456# Run the Setup Agent on first bootfirstboot --enable# Do not configure the X Window Systemskipx# System servicesservices --disabled="chronyd"# System timezonetimezone Asia/Shanghai --isUtc --nontp# Disk partitioning informationpart /boot --fstype="xfs" --ondisk=sda --size=1024part pv.217 --fstype="lvmpv" --ondisk=sda --size=1 --growvolgroup rhel --pesize=4096 pv.217logvol / --fstype="xfs" --grow --size=1024 --name=root --vgname=rhellogvol swap --fstype="swap" --size=2047 --name=swap --vgname=rhel%packages@^server-product-environmentkexec-tools%end%addon com_redhat_kdump --enable --reserve-mb='auto'%end%anacondapwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notemptypwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyokpwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty%endEOFsystemctl restart dhcpdsystemctl restart xinetdsystemctl restart vsftpdsystemctl status dhcpdsystemctl status xinetdsystemctl status vsftpd

分享、在看与点赞
只要你点,我们就是胖友

文章转载自Linux技术宅,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




