Linux -- Network Service -- PXE efficient batch network installation, experiment + theoretical explanation (deploy PXE remote installation service to realize Kickstart unattended installation)

preface

In large-scale linux application environments, such as Web Clusters and distributed computers, servers are often not equipped with CD-ROM devices. In this case, PXE can quickly install systems for dozens or even hundreds of servers.

1: Deploy PXE remote installation service

1.1: set up PXE remote installation server

1.1.1: advantages of batch deployment of servers
  • Scale: assemble multiple servers at the same time
  • Automation: install the system and configure various services
  • Remote implementation: no installation media such as CD and U SB flash disk are required
1.1.2: PXE network
  • PXE(Pre-boot eXcution Environment)

Pre boot execution environment, running before the operating system

  • Server

Run the DHCP service to allocate addresses and locate bootstrappers

Run TFTP service to provide bootstrap Download

  • client

The network card supports PXE protocol

The motherboard supports network startup

1.1.3: configure PXE installation server
  • Basic deployment process

Prepare centos 7 installation source (yum warehouse)

Install and start the TFTP service

Provide linux kernel, PXE boot program, etc

Install and start the DHCP service to assign addresses and guide the bootstrap location

Configure Startup menu

  • Preparing Centos 7 installation source

centos 7 installation source supports HTTP, FTP, NFS and other protocol Publishing

  • Install and start the TFTP service

Install the tftp server package and enable the tftp service

The configuration file is located at /etc/xinetd D/tftp

  • Prepare linux kernel and PXE boot program

The linux kernel and initialization image files are vmlinuz and initrd Img

The boot program is pexlinux 0, provided by software syslinux

  • Setting of PXE of DHCP service
[root@localhost ~]#yum install dhcp -y
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
[root@localhost ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp: overwrite '/etc/dhcp/dhcpd.conf'? y
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf

 subnet 192.168.100.0 netmask 255.255.255.0 {
          range 192.168.100.20 192.168.100.30;
          option routers 192.168.100.100;
          option domain-name-servers 6.6.6.6;
          next-server 192.168.100.100;		'specify TFTP server address'
          filename "pxelinux.0";		'filename: Specify the bootstrap file to download'
  }
[root@localhost ~]#systemctl start dhcpd
[root@localhost ~]#systemctl enable dhcpd
  • Configure Startup menu file
[root@localhost ~]# vi /var/lib/tftpboot/pxelinux.cfg/default
default auto
prompt 1
label auto
​    kernel vmlinuz
​	append initrd=initrd.img method=ftp://20.0.0.47/centos7
label linux text
​    kernel vmlinuz
​	append text initrd=initrd.img method=ftp://20.0.0.47/centos7
label linux rescue
​    kernel vmlinuz
​	append rescue initrd=initrd.img method=ftp://20.0.0.47/centos7

1.2: PXE deployment summary

  • Four documents
File name explain effect
default Pxelinux CFG contents The boot configuration file is loaded by default
vmlinuz Compressed kernel Defined in default to load first
initrd.img Initialize image file The second loaded
pxelinux.0 Bootstrap You need to install the syslinux package. It is defined in the dhcp configuration file
  • Three services
DHCP Enable the client to obtain the IP address and actively network the PXE server Point to TFTP in configuration
TFTP Simple file system, UDP, 69 port, fast loading bootstrap, small bootstrap capacity The default configuration file points to the FTP image location
FTP File system, TCP, 21 port connection service, 20 port data transmission System image storage

1.3: verify PXE network installation

  • Installing systems for clients

Adjust BIOS settings to boot from the network

Automatically obtain the IP address and specify the centos7 installation source

The rest of the process is the same as the local installation

2: PXE experimental configuration

2.1: experimental purpose

Bare metal machines without systems can automatically install systems through PXE

2.2: experimental environment

centos 7 system in VMware software and a bare metal without system installed

Step 1: set up dual network cards on the server
Add a network adapter to centos 7 and set it to host only mode. It is used for installation and server network card
The original network adapter keeps the NAT mode unchanged. Used to install the yum package

Step 2: modify the network card configuration information

[root@localhost ~]# cd /etc/sysconfig/network-scripts/

[root@localhost network-scripts]# ls

[root@localhost network-scripts]# cp -p ifcfg-ens33 ifcfg-ens36

[root@localhost network-scripts]# vim ifcfg-ens36

[root@localhost network-scripts]# systemctl restart network

[root@localhost network-scripts]# ifconfig

Step 3: install DHCP and set

[root@localhost ~]# yum install dhcp -y
[root@localhost ~]# cat /etc/dhcp/dhcpd.conf 
[root@localhost ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf 

[root@localhost ~]# vim /etc/dhcp/dhcpd.conf 

Step 4: install and set syslinux

Install the package syslinux because PXE bootstrap pxelinux 0 is provided by the package syslinux.

[root@localhost ~]# yum install syslinux -y
[root@localhost ~]# RPM -ql syslinux | grep pxelinux 0 filter to find pxelinux Where is 0

[root@localhost ~]# yum install tftp-server -y
[root@localhost ~]# rpm -ql tftp-server 

[root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@localhost ~]# ls /var/lib/tftpboot/


Step 5: set TFTP - configure and install TFTP server

The TFTP service is provided by the TFTP server software package and is managed by the xinetd super service by default. Therefore, the configuration file bit is /etc/xinetd,d/tftp. During configuration, just change "yes" to "no" and start xinetd service.

[root@localhost ~]# vim /etc/xinetd.d/tftp 

[root@localhost ~]# yum install vsftpd -y
[root@localhost ~]# rpm -ql vsftpd

[root@localhost ~]# cd /var/ftp/
[root@localhost ftp]# ls
[root@localhost ftp]# mkdir centos7
[root@localhost ftp]# ls
[root@localhost ftp]# mount /dev/sr0 /var/ftp/centos7/

Step 6: copy the file in the image

[root@localhost ftp]# cd centos7/
[root@localhost centos7]# ls
[root@localhost centos7]# cd images/
[root@localhost images]# ls
[root@localhost images]# cd pxeboot/
[root@localhost pxeboot]# ls

[root@localhost pxeboot]# cp initrd.img vmlinuz /var/lib/tftpboot/
[root@localhost pxeboot]# ls /var/lib/tftpboot/


Step 7: set the default configuration file

[root@localhost tftpboot]# mkdir pxelinux.cfg
[root@localhost tftpboot]# ls
[root@localhost tftpboot]# cd pxelinux.cfg/
[root@localhost pxelinux.cfg]# vim default

[root@localhost pxelinux.cfg]# systemctl stop firewalld.service 
[root@localhost pxelinux.cfg]# setenforce 0
[root@localhost pxelinux.cfg]# systemctl start dhcpd
[root@localhost pxelinux.cfg]# systemctl start tftp
[root@localhost pxelinux.cfg]# systemctl start vsftpd

Step 8: switch to the bare metal position and start the virtual machine

It can be installed and the experiment is successful

3: Enable Kickstart unattended installation

3.1: prepare the installation response file

  • kickstart unattended Technology

Create an answer file and pre define various installation settings

Eliminates the interactive setup process to achieve fully automated installation

Complete various configuration operations after installation by adding%post script

  • Contents of answer file

3.2: realize batch automatic installation

The[ root@localhost ~]#Yum install system config kickstart -y install kickstart tool

After installation, kickstart tool is found

[root@localhost ~]# cd /var/ftp
[root@localhost ftp]# ls

[root@localhost ftp]# cd /root
[root@localhost ~]# ls
[root@localhost ~]# vim anaconda-ks.cfg 


[root@localhost ~]# vim /var/ftp/ks.cfg 

[root@localhost ~]# cd /var/lib/tftpboot/
[root@localhost tftpboot]# ls
[root@localhost tftpboot]# cd pxelinux.cfg/
[root@localhost pxelinux.cfg]# ls
[root@localhost pxelinux.cfg]# vim default 



Switch to bare metal and restart

4: PXE+Kickstart auto install

4.1: verifying automatic installation

Boot the client in PXE mode
The system will automatically complete the installation and configure the software warehouse
No manual intervention is required during the whole installation process

Tags: Linux cloud computing

Posted by jawapro on Tue, 31 May 2022 18:41:23 +0530