Details of the tutorial for automatically installing CentOS 7.6 using PXE

  • 2021-07-01 08:35:46
  • OfStack

1. Requirements

There are 300 new servers in the base, so it is necessary to install CentOS version 7.6 operating system by itself, and choose to use PXE for batch installation.

Step 2: Preparations

Use Layer 2 switches to connect servers without operating system installed, so as to avoid affecting the normal servers of the existing network.

Upload the operating system image to the server and install PXE environment prerequisite services.

Mount the image file as a local software repository.

Environmental preparation


systemctl stop firewalld  #  Close the firewall 
setenforce 0  #  Temporary setting SELINUX For loose mode 
sed -i '/^SELINUX=/s/.*/SELINUX=disabled/' /etc/selinux/config  #  Permanently disabled SELINUX (Need to restart to take effect) 
mkdir -p /var/www/html/CentOS1810/
mount /tmp/CentOS-7-x86_64-DVD-1810.iso /var/www/html/CentOS1810
mkdir /etc/yum.repos.d/backup 
mv /etc/yum.repos.d/{*,backup}  #  You don't need to pay attention to reporting errors 
cat >/etc/yum.repos.d/local.repo<<EOF
[local_repo]
name=local_repo
baseurl=file:///var/www/html/CentOS1810
gpgcheck=0
EOF
yum clean all && yum makecache 
yum install httpd dhcp xinetd tftp-server syslinux -y

3. Service configuration

Configuring the dhcp service

Modifying the dhcp Server Configuration File


mv /etc/dhcp/dhcpd.conf{,.bak}  #  Back up the default configuration file 
cat>/etc/dhcp/dhcpd.conf<<EOF
subnet 10.0.0.0 netmask 255.255.255.0 {   #  Define assigned network segments and masks 
range 10.0.0.1 10.0.0.252;         #  Define the assigned address range 
next-server 10.0.0.253;           #  Specify the server for the boot file IP Address 
filename "pxelinux.0";           #  Specify the boot file name  
}
EOF
systemctl start dhcp
systemctl enable dhcp
ss -nltup |grep :67

Configuring tftp-server

Edit/etc/xinetd. d/tftp


sed -i '/disable/s/yes/no/' /etc/xinetd.d/tftp
systemctl start xinetd
systemctl enable xinetd
ss -nltup |grep :69

Copy related files to the default home directory of tftp service


mkdir /var/lib/tftpboot/pxelinux.cfg 
cp -a {/var/www/html/CentOS1810/isolinux/*,/usr/share/syslinux/pxelinux.0} /var/lib/tftpboot/  #  Copy the startup menu and boot loader 
cp -a /var/www/html/CentOS1810/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default

Summarize


Related articles: