Table of contents
1. Experimental topology diagram
3. Configure the PXE installation server
1. Set up firewall and selinux
3. Copy system files to /var/ftp for installation
5. Prepare pxelinx.0 files, boot files, and kernel files
4. Test the communication between pxe and relay
5. Create a new test host to test the installation effect
1. Create a new network card 2 network segment host
2. Create a new host with network card 3 network segment
6. Configure unattended pxe installation
Copy: Copy the software installation fields from the /root/anaconda-ks.cfg file to ks.cfg
Preface
PXE (Preboot Execution Environment) installation is a method of booting and installing an operating system over a network. It allows a computer to load operating system installation files from a remote server or network share over the network and complete the installation process without a local storage device (such as a hard disk or optical drive).
PXE installations are commonly used for large-scale deployment and remote management of computers, especially in server and client environments. It can greatly simplify the operating system installation and configuration process, improve deployment efficiency and consistency, and reduce the need for manual operations.
The basic working principle of PXE installation is as follows:
1. The client (the computer to be installed) starts over the network and sends a DHCP request to obtain the IP address and other configuration information.
2. The DHCP server responds and provides an IP address and related configuration for the PXE boot service.
3. The client uses TFTP (Trivial File Transfer Protocol) to download the boot program (such as pxelinux.0) from the PXE server.
4. The bootloader loads and starts, providing menus and options that allow the user to select the desired operating system installation.
5. After the client selects an installation option, the bootloader downloads the appropriate operating system installation files (such as the kernel, initialization memory disk (initrd), and installer) from the PXE server.
6. The client uses the downloaded file to proceed with the operating system installation process.
The configuration of PXE installation includes setting up and maintaining PXE server, creating boot file, setting up DHCP server and TFTP server, etc. It is often used in conjunction with other automation tools such as Kickstart files to enable automated and batch operating system deployment.
1. Experimental topology diagram
Conditions: According to the above requirements, we prepare the equipment, set up firewall, selinux, and add respective network cards.
Purpose: To realize manned and unattended installation of machines in different network segments
2. PXE components
- vsftpd/httpd/nfs is responsible for providing system installation files
- tftp is responsible for providing boot files and kernel files before system installation
- dhcp is responsible for providing the client's IP address allocation and pxe boot file, as well as the pxe server address
3. Configure the PXE installation server
1. Set up firewall and selinux
systemctl stop firewalld.service
systemctl enable firewalld.service
setenforce 0
2. Install and start vsftp
######配置本地yum
cd /etc/yum.repos.d
mkdir back
mv CentOS-* back
vim local.repo
###插入
[local]
name=local
baseurl=file:///mnt
enabled=1
gpgcheck=0
###挂载sr0,安装vsftpd
mount /dev/sr0 /mnt
yum -y install vsftpd
systemctl start vsftpd
3. Copy system files to /var/ftp for installation
cd /var/ftp
mkdir centos7
cp -r /mnt/* /var/ftp/centos7
sync
4. Configure tftp
###安装
yum install -y tftp-server
###修改配置文件
vim /etc/xinit.d/tftp
###修改处
disable=no
###启动
systemctl start tftp
5. Prepare pxelinx.0 files, boot files, and kernel files
###准备pxelinux.0文件
yum install -y syslinux
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot
###准备引导文件、内核文件
cd /mnt/images/pxeboot
cp initrd.img vmlinuz /var/lib/tftpboot
6. Configure local IP
vim /etc/sysconfig/network-scripts/ifcfg-ens33
###改为
TYPE=Ethernet
BOOTPROTO=static
NAME=ens33
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.100.253
PREFIX=24
GATEWAY=192.168.100.254
###保存退出,重启网络、ip a 查看
systemctl restart network
ip a
7. Configure DHCP service
yum -y install dhcp
cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf
vim /etc/dhcp/dhcpd.conf
##删除前3段的subnet字段,修改剩下的字段
subnet 192.168.100.0 netmask 255.255.255.0 {
range 192.168.100.1 192.168.100.252;
#option domain-name-servers ns1.internal.example.org;
#option domain-name "internal.example.org";
option routers 192.168.100.254;
option broadcast-address 192.168.100.255;
default-lease-time 600;
max-lease-time 7200;
next-server 192.168.100.253;
filename "pxelinux.0";
}
subnet 192.168.200.0 netmask 255.255.255.0 {
range 192.168.200.1 192.168.200.252;
#option domain-name-servers ns1.internal.example.org;
#option domain-name "internal.example.org";
option routers 192.168.200.254;
option broadcast-address 192.168.200.255;
default-lease-time 600;
max-lease-time 7200;
next-server 192.168.100.253;
filename "pxelinux.0";
}
###启动DHCP服务
systemctl start dhcpd
8. Create default file
cd /var/lib/tftpboot
mkdir pxelinux.cfg
cd pxelinux.cfg
vim default
###插入内容
default auto #默认安装标签
prompt 1 #等待用户确认,1表示等待,0表示不等待
label auto #定义标签
kernel vmlinuz #指定内核
append initrd=initrd.img method=ftp://192.168.100.253/centos7 #指定引导镜像文件与系统安装文件
The manned mode has been basically configured.
4. Configure relay
1. Add network card
2. Configure the network card
###设置防火墙、selinux
systemctl stop firewalld.service
setenforce 0
###
cd /etc/sysconfig/network-scripts
vim ifcfg-ens33
##改为
TYPE=Ethernet
BOOTPROTO=static
NAME=ens33
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.100.254
PREFIX=24
###############################################
vim ifcfg-ens37
##改为
OTPROTO=static
NAME=ens37
DEVICE=ens37
ONBOOT=yes
IPADDR=192.168.200.254
PREFIX=24
3. Add routing function
####安装DHCP
yum -y install dhcp
dhcrelay 192.168.100.253
vim /etc/sysctl.conf
####文末插入
net.ipv4.ip_forward = 1
###保存退出
sysctl -p
4. Test the communication between pxe and relay
5. Create a new test host to test the installation effect
1. Create a new network card 2 network segment host
Choose next step
Use network card 2
Turn on the computer, the connection is successful, press Enter to start the installation
2. Create a new host with network card 3 network segment
The creation method is the same as above, so I won’t go into details. Just change the network card to 3 here
Power on verification
Enter + wait patiently
The test is completed and the result is ok
6. Configure unattended pxe installation
1. Graphical configuration
##使用图形界面配置
yum install -y system-config-kickstart.noarch
system-config-kickstart
After executing the above command, a graphical interface will appear
Start configuring below
The script depends on your needs
keep
View where the file is saved
Copy: Copy the software installation fields from the /root/anaconda-ks.cfg file to ks.cfg
vim anaconda-ks.cfg
##复制以下字段插入到ks.cfg
%packages
@^graphical-server-environment
@base
@core
@desktop-debugging
@development
@dial-up
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@hardware-monitoring
@input-methods
@internet-browser
@multimedia
@print-client
@x11
chrony
kexec-tools
%end
copy
cp ks.cfg /var/ftp
2. Modify the default file
vim /var/lib/tftpboot/pxelinux.cfg/default
###修改
default auto
prompt 0
label auto
kernel vmlinuz
append initrd=initrd.img method=ftp://192.168.100.253/centos7 ks=ftp://192.168.100.253/ks.cfg
3. Verification
Create a new host in the 192.168.100.0 network segment and start it
Create a new host in the 192.168.200.0 network segment and start it
After a while, it has connected itself and started to install the system. We don't have to do anything, just wait
Finally, it’s OK. Enter the password we set in the graphical settings to log in to the root account.
Check the new host in the 192.168.100.0 segment
Check the new host in the 192.168.200.0 segment
Summarize
This experiment successfully carried out attended PXE installation and unattended PXE installation on new hosts in different network segments. According to the experimental results, the expected purpose was basically achieved. The steps in this experiment are roughly divided into configuring the PXE server and relay equipment. The most important thing is the settings of our pex server:
vsftpd/httpd/nfs is responsible for providing system installation files
tftp is responsible for providing boot files and kernel files before system installation
dhcp is responsible for providing the client's IP address allocation and pxe boot file, as well as the pxe server address