pxe server 前言
PXE(Preboot eXecution Environment,预启动执行环境)是一种网络启动协议,允许计算机通过网络启动而不是使用本地硬盘。PXE服务器是实现这一功能的服务器,它提供了启动镜像和引导加载程序,使得客户端计算机可以通过网络启动并安装操作系统或运行其他软件。
在Debian系统中,要设置一个PXE服务器,您需要以下几个组件:
- TFTP服务器:用于提供启动镜像和引导加载程序。
- DHCP服务器:用于分配IP地址给客户端计算机。
- NFS或HTTP服务器:用于提供操作系统镜像和其他文件。
在Debian中,可以使用以下软件包来设置PXE服务器:
- atftpd:一个轻量级的TFTP服务器,可以用于提供启动镜像和引导加载程序。
- dnsmasq:一个轻量级的DHCP和DNS服务器,可以用于分配IP地址给客户端计算机。
- nfs-kernel-server:用于提供NFS服务,以便客户端可以访问操作系统镜像和其他文件。
RockyLinux download
- Rocky Linux Download-CSDN博客
创建一键部署pxe server 环境脚本
- pxe server 是RockyLinux 9
- dhcp /etc/dhcp/dhcpd.conf 配置文件
- tftp 配置文件/etc/default/tftpd-hpa
- tftp 69
- http 配置文件/etc/httpd/conf/httpd.conf
- /etc/httpd/conf.d/pxeboot.conf 镜像http配置
- http 端口80
- /var/lib/tftpboot/pxelinux.cfg/default (bios 支持)配置文件
- 10-48 行变量内容详细注意,更改自己需要的,自动化脚本仔细看
- /var/lib/tftpboot/grub.cfg (uefi 支持)配置文件,grub.cfg此处Redhat 系和debian 系不一样哦注意哦
- rockylinux root密码1234.com
- LVM 自动分区,默认禁止/home 分区
- /var/pxe/{rockylinux8.10,rockylinux9.4} 挂载目录
- /var/www/html/{rockylinux8.10,rockylinux9.4} images目录
- /var/www/html/rockylinx_iso 8 9 iso 下载存放目录
- /var/www/html/rockylinx_cfg{Rockylinux8.10-ks.cfg,Rockylinux9.4-ks.cfg} 自动化编排
- rockylinux cfg编排参考
- redhat cfg 编排参考(需要注册redhat 转换登录)
- PXE网络安装参考,相关配置参考
- bios 实现自动化安装esxi 需要syslinux官方是指导3.86,Redhat 8 系列下使用此 版本
-
# 加密密码生成 python -c 'import crypt,getpass; \ print(crypt.crypt(getpass.getpass(), \ crypt.mksalt(crypt.METHOD_SHA512)))'
vim /rockylinux_pxe_server_rockylinx.sh
#!/bin/bash
# -*- coding: utf-8 -*-
# Author: make.han
# Email: CIASM@CIASM
# Date: 2024/07/24
# rockylinux 8 9 action pxe server
# PXE Redhat rockylinux almalinx oraclelinux 8 9#tftp variable configuration
tftp_port=69
tftp_user=tftp
tftp_catalogue=/var/lib/tftpboot#dhcp ip address variable configuration
nic_network_name=`ifconfig -s | awk 'NR>1 && !/^lo/ && !/^idrac/ && !/^br/ && !/^veth/ && !/^docker/{print $1; exit}'`
host_IP=`ifconfig -a | grep inet | grep -v '127.0.0.1' | awk '{ print $2}' | awk 'NR==1'`
MASK="255.255.255.0"
BROADCAST_ADDRESS="192.168.11.255"
ROUTERS="192.168.11.1"
SUBNET="192.168.11.0"
DNS="8.8.8.8"
RANGE="192.168.11.50 192.168.11.80"root_password='$6$4QaHWOfkEYxT2Dv6$3h5T/4AT/vkINa.R.9tToEUwro5YqD2UjulKRQ8k8ZMjqJOhib23nZ/fnKKgRh5TRaTg6I1mIa8VWJxmKQR7o0'# apache2 variable configuration
apache_port=80
apache_catalogue=/var/www/html#syslinux variable configuration
syslinux_download_url=https://mirrors.edge.kernel.org/pub/linux/utils/boot/syslinux/syslinux-4.07.tar.gz
syslinux_gz=syslinux-4.07.tar.gz
syslinux_catalogue=syslinux-4.07# rockylinx download variable configuration
rockylinux8_download_url=https://download.rockylinux.org/pub/rocky/8/isos/x86_64/Rocky-8.10-x86_64-dvd1.iso
rockylinux9_download_url=https://download.rockylinux.org/pub/rocky/9/isos/x86_64/Rocky-9.4-x86_64-dvd.iso
rockylinux8_iso=Rocky-8.10-x86_64-dvd1.iso
rockylinux9_iso=Rocky-9.4-x86_64-dvd.iso# rockylinx 8 9 catalogue
rockylinx_cfg=rockylinx_cfg
rockylinx_iso=rockylinx_iso
rockylinux8_catalogue=rockylinux8.10
rockylinux9_catalogue=rockylinux9.4install_pxe_server (){if ! [ -x "$(command -v dhcpd)" ]; thenif [ $? -eq 0 ];thenecho "install tftp dhcp"
dnf install tftp tftp-server dhcp-server httpd syslinux net-tools -yecho "stop selinx"
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
setenforce 0echo "firewalld tftp"
yum install -y curl
firewall-cmd --zone=public --add-port=$tftp_port/tcp --permanent && firewall-cmd --reload
firewall-cmd --zone=public --add-port=$tftp_port/udp --permanent && firewall-cmd --reloadecho "apache2 firewall"
firewall-cmd --zone=public --add-port=$apache_port/tcp --permanent && firewall-cmd --reloadecho "configuration dhcpd.conf"
rm -rf /etc/dhcp/dhcpd.conf
cat >> /etc/dhcp/dhcpd.conf << EOF
option domain-name "$DNS";
option domain-name-servers $DNS;
default-lease-time 2592000;
max-lease-time 2592000;
authoritative;# add follows
option space pxelinux;
option pxelinux.magic code 208 = string;
option pxelinux.configfile code 209 = text;
option pxelinux.pathprefix code 210 = text;
option pxelinux.reboottime code 211 = unsigned integer 32;
option architecture-type code 93 = unsigned integer 16;subnet $SUBNET netmask $MASK {range dynamic-bootp $RANGE;option broadcast-address $BROADCAST_ADDRESS;option routers $ROUTERS;#add followsclass "pxeclients" {match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";# PXE servers hostname or IP addressnext-server $host_IP;if option architecture-type = 00:07 {filename "BOOTX64.EFI";}else {filename "pxelinux.0";}}
}
EOFecho "restrat dhcpd"
systemctl enable --now dhcpd tftpecho "mkdir catalogue rockylinux cfg ISO save"
mkdir -p $apache_catalogue/{$rockylinx_cfg,$rockylinx_iso}echo "download rockylinux 8 9"
curl -o $apache_catalogue/$rockylinx_iso/$rockylinux8_iso $rockylinux8_download_url
curl -o $apache_catalogue/$rockylinx_iso/$rockylinux9_iso $rockylinux9_download_url mkdir -p /var/pxe/{$rockylinux8_catalogue,$rockylinux9_catalogue}
mkdir -p $tftp_catalogue/{$rockylinux8_catalogue,$rockylinux9_catalogue}echo "mount rockylinux 8 9"
mount -t iso9660 -o loop,ro $apache_catalogue/$rockylinx_iso/$rockylinux8_iso /var/pxe/$rockylinux8_catalogue
mount -t iso9660 -o loop,ro $apache_catalogue/$rockylinx_iso/$rockylinux9_iso /var/pxe/$rockylinux9_catalogueecho "Mount an image on startup"
sed -i "$ a $apache_catalogue/$rockylinx_iso/$rockylinux8_iso /var/pxe/$rockylinux8_catalogue/ iso9660 defaults,loop,ro 0 0" /etc/fstab
sed -i "$ a $apache_catalogue/$rockylinx_iso/$rockylinux9_iso /var/pxe/$rockylinux9_catalogue/ iso9660 defaults,loop,ro 0 0" /etc/fstab echo "http config"
mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.conf.org
sed -i "s#DirectoryIndex index.html#DirectoryIndex index.html index.php index.cgi#" /etc/httpd/conf/httpd.conf
sed -i "s#Options Indexes FollowSymLinks#Options FollowSymLinks#" /etc/httpd/conf/httpd.conf
sed -i "s#AllowOverride None#AllowOverride All#" /etc/httpd/conf/httpd.conf
sed -i '$a ServerTokens Prod' /etc/httpd/conf/httpd.confecho "copy vmlinuz initrd.img"
cp -rf /var/pxe/$rockylinux8_catalogue/images/pxeboot/{vmlinuz,initrd.img} $tftp_catalogue/$rockylinux8_catalogue
cp -rf /var/pxe/$rockylinux9_catalogue/images/pxeboot/{vmlinuz,initrd.img} $tftp_catalogue/$rockylinux9_catalogueecho "add pxeboot.conf"
cat >> /etc/httpd/conf.d/pxeboot.conf<<EOF
# create new
Alias /$rockylinux8_catalogue /var/pxe/$rockylinux8_catalogue
<Directory /var/pxe/$rockylinux8_catalogue>Options Indexes FollowSymLinks# IP address you allow to accessRequire ip 127.0.0.1 $SUBNET/$MASK
</Directory># create new
Alias /$rockylinux9_catalogue /var/pxe/$rockylinux9_catalogue
<Directory /var/pxe/$rockylinux9_catalogue>Options Indexes FollowSymLinks# IP address you allow to accessRequire ip 127.0.0.1 $SUBNET/$MASK
</Directory>
EOF#下载syslinux-4.07.tar.gz,用于支持Bios 模式安装esxi
echo "low version syslinux"
curl -o /$syslinux_gz $syslinux_download_url
tar -zxf /$syslinux_gz -C /
cp -rf /$syslinux_catalogue/core/pxelinux.0 $tftp_catalogue/
cp -rf /$syslinux_catalogue/com32/menu/menu.c32 $tftp_catalogue/
cp -rf /$syslinux_catalogue/com32/menu/vesamenu.c32 $tftp_catalogue/echo "mkdir pxelinux.cfg"
mkdir -p $tftp_catalogue/pxelinux.cfg
cat <<EOF>>$tftp_catalogue/pxelinux.cfg/default
# change like follows#Official page display
default vesamenu.c32#Simple page display
#default menu.c32 #Set the home page timeout period according to project requirements timeout 30
timeout 300 #/var/lib/tftpboot/下,命名为you.png
#menu background ubunutu.pngmenu title ########## PXE Boot Menu #########
display boot.msglabel Auto Rockylinux8.10menu label ^Auto Install Rockylinux8.10kernel $rockylinux8_catalogue/vmlinuzappend initrd=$rockylinux8_catalogue/initrd.img ip=dhcp inst.ks=http://${host_IP}/$rockylinx_cfg/Rockylinux8.10-ks.cfglabel Auto Rockylinux9.4menu label ^Auto Install Rockylinux9.4kernel $rockylinux9_catalogue/vmlinuzappend initrd=$rockylinux9_catalogue/initrd.img ip=dhcp inst.ks=http://${host_IP}/$rockylinx_cfg/Rockylinux9.4-ks.cfglabel Manual Rockylinux8.10menu label ^Manual Install Rockylinux8.10kernel $rockylinux8_catalogue/vmlinuzappend initrd=$rockylinux8_catalogue/initrd.img ip=dhcp inst.repo=http://${host_IP}/$rockylinux8_cataloguelabel Manual Rockylinux9.4menu label ^Manual Install Rockylinux9.4kernel $rockylinux9_catalogue/vmlinuzappend initrd=$rockylinux9_catalogue/initrd.img ip=dhcp inst.repo=http://${host_IP}/$rockylinux9_cataloguelabel local#menu defaultcom32 chain.c32menu label Boot from ^local drivelocalboot 0xffff
menu end
EOFecho "creation grub.cfg"
cat <<EOF>>$tftp_catalogue/grub.cfg
# ubuntu 24
set default="3"set timeout=10
set gfxpayload=keep
set color_normal=white/blackfunction load_video {insmod video_bochsinsmod video_cirrusinsmod all_video
}load_video
insmod gzio
insmod part_msdos
insmod part_gpt
insmod ext2
insmod xfs
insmod png
insmod gfxterm
insmod gfxmenu
terminal_output gfxterm
background_image -m stretch bg.pngmenuentry 'EFI Firmware System Setup' 'uefi-firmware' {fwsetup
}menuentry 'Reboot System' {reboot
}menuentry 'Shutdown System' {halt
}menuentry 'Auto Install Rockylinux 8.10' {linuxefi $rockylinux8_catalogue/vmlinuz ip=dhcp inst.ks=http://${host_IP}/$rockylinx_cfg/Rockylinux8.10-ks.cfginitrdefi $rockylinux8_catalogue/initrd.img
}menuentry 'Auto Install Rockylinux 9.4' {linuxefi $rockylinux9_catalogue/vmlinuz ip=dhcp inst.ks=http://${host_IP}/$rockylinx_cfg/Rockylinux9.4-ks.cfginitrdefi $rockylinux9_catalogue/initrd.img
}menuentry 'Manual Install Rockylinux 8.10' {linuxefi $rockylinux8_catalogue/vmlinuz ip=dhcp inst.repo=http://${host_IP}/$rockylinux8_catalogueinitrdefi $rockylinux8_catalogue/initrd.img
}menuentry 'Manual Install Rockylinux 9.4' {linuxefi $rockylinux9_catalogue/vmlinuz ip=dhcp inst.repo=http://${host_IP}/$rockylinux9_catalogueinitrdefi $rockylinux9_catalogue/initrd.img
}
EOFecho "add rockylinx 9.4 cfg"
cat <<EOF>>$apache_catalogue/$rockylinx_cfg/Rockylinux9.4-ks.cfg
# automatically proceed for each steps
graphical# AppStream
repo --name="AppStream" --baseurl="http://${host_IP}/$rockylinux9_catalogue/AppStream"# Use network installation
url --url="http://${host_IP}/$rockylinux9_catalogue"# install disk
ignoredisk --only-use=sda# selinux stop
selinux --disabled# keyboard layouts
keyboard us# system locale
lang en_US# network settings
network --bootproto=dhcp --ipv6=auto --activate --hostname=localhost
network --bootproto=static --device=em2 --ip=192.168.3.100 --netmask=255.255.255.0 --gateway=192.168.3.11 --nameserver=8.8.8.8 --ipv6=auto --activate# root password you generated above
rootpw --iscrypted $root_password# System timezone
timezone Asia/Shanghai --isUtc# Run the Setup Agent on first boot
firstboot --disable# Firewall configuration
auth --passalgo=sha512 --useshadow
firewall --enabled --ssh
firstboot --disable# Automated low-level formatting
zerombr#Automatic partition, / partition uses all space, disable home partition
autopart --type=lvm --fstype=xfs --nohome# initialize all partition tables
clearpart --all --initlabel
#clearpart --none --initlabel# partitioning
# for [/boot/efi], it needs only for UEFI clients
#part pv.106 --fstype="lvmpv" --ondisk=sda --size=919974
#part /boot --fstype="xfs" --ondisk=sda --size=1024
#part /boot/efi --fstype="efi" --ondisk=sda --size=600 --fsoptions="umask=0077,shortname=winnt"
#volgroup ro --pesize=4096 pv.106
#logvol swap --fstype="swap" --size=8611 --name=swap --vgname=ro
#logvol / --fstype="xfs" --size=911360 --name=root --vgname=ro# reboot after installing
reboot%packages
@^minimal-environment
@console-internet
kexec-tools
net-tools
vim
unzip
wget
tmux
git
tree
curl
jq
%end%post
yum clean all
yum makecache
yum install http://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm -y
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
%end
EOFecho "add Rockylinux8.10-ks.cfg"
cat <<EOF>>$apache_catalogue/$rockylinx_cfg/Rockylinux8.10-ks.cfg
# create new
# automatically proceed for each steps
graphical# AppStream
repo --name="AppStream" --baseurl="http://${host_IP}/$rockylinux8_catalogue/AppStream"# Use network installation
url --url=http://${host_IP}/$rockylinux8_catalogue# install disk
ignoredisk --only-use=sda# selinux stop
selinux --disabled# keyboard layouts
keyboard us# system locale
lang en_US# network settings
network --bootproto=dhcp --ipv6=auto --activate --hostname=localhost
network --bootproto=static --device=em2 --ip=192.168.3.100 --netmask=255.255.255.0 --gateway=192.168.3.11 --nameserver=8.8.8.8 --ipv6=auto --activate# root password you generated above
rootpw --iscrypted $root_password# System timezone
timezone Asia/Shanghai --isUtc# Run the Setup Agent on first boot
firstboot --enable# Firewall configuration
firewall --enabled --port=22:tcp# Automated low-level formatting
zerombr#Automatic partition, / partition uses all space, disable home partition
autopart --type=lvm --fstype=xfs --nohome# initialize all partition tables
clearpart --all --initlabel# partitioning
# for [/boot/efi], it needs only for UEFI clients
#part /boot/efi --fstype="efi" --ondisk=sda --size=4096 --fsoptions="defaults,uid=0,gid=0,umask=0077,shortname=centos"
#part /boot --fstype="xfs" --size=4096
#part pv.12 --grow --fstype="lvmpv" --size=871120
#volgroup ro --pesize=4096 pv.12
#logvol swap --fstype="swap" --size=4096 --name=swap --vgname=ro
#logvol / --fstype="xfs" --size=871120 --name=root --vgname=ro# reboot after installing
reboot%packages
@^minimal-environment
kexec-tools
net-tools
vim
unzip
wget
tmux
git
tree
curl
jq
tar
lm_sensors
lm_sensors-libs
%end%post
yum clean all
yum makecache
yum install http://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm -y
%end
EOFecho "uefl add"
mkdir -p /rpm
yum install yum-utils -y
yumdownloader --resolve --destdir=/rpm shim grub2-efi-x64 syslinux-tftpboot
cd /rpm
rpm2cpio shim-x64-*.rpm | cpio -dimv
rpm2cpio grub2-efi-x64-*.rpm | cpio -dimv
rpm2cpio syslinux-tftpboot-* | cpio -dimv
cp ./boot/efi/EFI/BOOT/BOOTX64.EFI $tftp_catalogue/
cp ./boot/efi/EFI/rocky/grubx64.efi $tftp_catalogue/
chmod 644 $tftp_catalogue/{BOOTX64.EFI,grubx64.efi}#Copy the EFI boot image from the boot directory
echo "Copy the EFI boot image from the boot directory"
mkdir -p $tftp_catalogue/uefi
cp -rf /rpm/boot/efi/EFI/rocky/* $tftp_catalogue/uefi/echo "copy pxelinux"
mkdir -p $tftp_catalogue/pxelinux
cp /rpm/tftpboot/* $tftp_catalogue/pxelinux/echo "restrat dhcp http tftp"
systemctl restart dhcpd httpd tftpecho "Deleting an rpm directory"
rm -rf /rpmecho -e "\033[32mThe esxi pxe server Install Sussess...\033[0m" elseecho -e "\033[33mThe esxi pxe server Install Failed...\033[0m" exit 1fielseecho -e "\033[31mThe esxi pxe server Install already...\033[0m"
fi
}main (){install_pxe_server
}main
执行安装
bash /rockylinux_pxe_server_rockylinx.sh
RockyLinux 8 9 Bios 自动化部署
RockyLinux 8 9 uefi 自动化部署
分区lvm ,去除home目录