Linux--PXE+Kickstart unattended to achieve efficient batch network installation--How to be a qualified network administrator?


  • With the continuous growth of Internet technology and the increasing number of servers, IT operation and maintenance has become an important part of the connotation of IT services. Facing more and more complex business and more and more diverse user needs, The ever-expanding IT applications require more and more reasonable models to ensure that IT services can be continuously guaranteed in a flexible, convenient, safe and stable manner. The guarantee factor in this model is IT operation and maintenance.
  • From a few servers in the early days to a huge data center, labor alone can no longer meet the requirements in terms of technology, business, management, etc., so the factors such as standardization, automation, architecture optimization, process optimization, etc. to reduce IT service costs are becoming more and more. valued by people
  • And how to automate mass deployment and install a stable system is the first step in automation.
  • Next, let's learn the network installation method based on PXE (pre-boot Execution Environment) technology, and combine Kickstart configuration to realize unattended automatic installation

1. Introduction to PXE

  • PXE, the pre-boot execution environment, is a way of booting. This protocol is generally composed of two parts, one is the server and the other is the client. In short, we can create an "installation source" by ourselves in this way, as long as we can find this "source" when installing the system. The system can be installed.
  • PXE is a network boot technology developed by Intel. It works in Client/Server mode, allowing clients to download boot images from remote servers through the network and load installation files or the entire operating system.

2. Prerequisites for building PXE (theoretical steps)

  • Before realizing unattended installation, we must build some services to realize the establishment of "installation source", such as ftp, http, tftp, dhcp, etc.
  • When a host starts, the standard input and output will transfer the PXE client into our memory to perform related operations, and prompt related options, where we can choose. So the client's network card must support the PXE protocol (integrated BOOTROM chip), and the motherboard supports network boot
  • The PXE client downloads (download) the boot file to run locally through the network. The specific process is that the PXE client sends an ip request to the local area network through the network card, and then the DHCP server will provide it with an ip address and the files required for system installation, and then use the received files for system installation. Therefore, there must be a DHCP server in the network to automatically assign addresses to clients and specify the location of boot files.
  • The installation process requires resources provided by other servers, such as: yum source, kernel files, etc. When the host gets these resources, it can be installed smoothly. The final result is: any host will obtain the ip distributed by the DHCP server when it selects the network to start, communicate with the TFTP server in the LAN through the obtained ip address and obtain the startup file, communicate with FTP or HTTP and obtain the yum source files and kernel files. The server provides the download of the boot image file through TFTP (Trivial File Transfer Protocol, Trivial File Transfer Protocol).
  • Among them, the first condition is actually a hardware requirement. At present, most servers and most PC s can provide this support. It only needs to allow booting from Network or LAN in the BIOS settings.
  • Then start the automatic installation, and this process does not require any human action
  • A simple schematic is shown below:

3. Advantages of PXE batch deployment

  • Remote implementation: not limited by optical drives, CD-ROMs and some external devices
  • Scale: Assemble multiple servers simultaneously
  • Automation: Install the system and configure various services, which can be unattended, greatly reducing the workload of operation and maintenance personnel

Fourth, build a PXE remote installation server

  • PXE Remote Install Server integrates with:
    • CentOS7 installation source
    • TFTP service
    • DHCP service
  • Ability to send PXE bootloader, Linux kernel, boot menu, etc. data to guest bare metal, as well as provide installation files

1. Install and start the TFTP service

  • TFTP (Trivial File Transfer Protocol) is a protocol based on UDP protocol for simple file transfer between client and server, suitable for small file transfer applications; TFTP service is managed by xinetd service by default, using UDP port 69
  • xinetd is a new generation of network daemon service program, also known as super server, which is often used to manage a variety of lightweight Internet services
  • The configuration file of xindtd service is located in /etc/xindtd.d/ftp , just change "disable = yes" to "disable = no" when configuring
[root@localhost ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 write-protected, will mount as read-only
[root@localhost ~]# yum -y install.server tftp xinetd        ##Install related packages
[root@localhost ~]# cd /etc/xinetd.d/
[root@localhost xinetd.d]# vim tftp

[root@localhost xinetd.d]# systemctl stop firewalld
[root@localhost xinetd.d]# systemctl disable firewalld
[root@localhost xinetd.d]# setenforce 0
setenforce: SELinux is disabled
[root@localhost xinetd.d]# 
[root@localhost xinetd.d]# systemctl start tftp        ###enable ftp service
[root@localhost xinetd.d]# systemctl enable tftp        ###Enable ftp service to start automatically at boot
Created symlink from /etc/systemd/system/ to /usr/lib/systemd/system/tftp.socket.
[root@localhost xinetd.d]# systemctl start xinetd        ## #Start the xinetd service
[root@localhost xinetd.d]# systemctl enable xinetd        ###Enable the xinetd service to start automatically at boot

2. Install and enable DHCP service

  • DHCP (Dynamic Host Configuration Protocol, Dynamic Host Configuration Protocol) is a local area network network protocol, using the UDP protocol to work
[root@localhost xinetd.d]# cd
[root@localhost ~]# yum -y install dhcp        ##install dhcp package
  • Because the initial /etc/dhcp/dhcpd.conf is an empty file, the file is required to go to /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example to view
  • So we need to copy this file to the /etc/dhcp/dhcpd.conf file, and then make subsequent configuration file changes
[root@localhost xinetd.d]# cd
[root@localhost ~]# cd /etc/dhcp/
[root@localhost dhcp]# ls        ##The dhcp configuration file is dhcp.conf, which is normally empty
dhclient.d             dhcpd6.conf  scripts
dhclient-exit-hooks.d  dhcpd.conf
[root@localhost dhcp]# cd /usr/share/doc/dhcp-4.2.5/        ##Switch to the dhcp configuration template file directory
[root@localhost dhcp-4.2.5]# ls
dhcpd6.conf.example  dhcpd.conf.example  ldap
[root@localhost dhcp-4.2.5]# cp dhcpd.conf.example /etc/dhcp/dhc
cp: whether to cover"/etc/dhcp/dhcpd.conf"? yes        ##Confirm the overwrite and copy the configuration file template to the dhcp configuration file
  • Then change the configuration file of dhcpd, first change the global configuration
  • Next, change the address pool
  • Enable DHCP service
[root@localhost ~]# systemctl start dhcpd
[root@localhost ~]# systemctl enable dhcpd
Created symlink from /etc/systemd/system/ to /usr/lib/systemd/system/dhcpd.service.
[root@localhost ~]# 

3. Prepare the Linux kernel and initialize the image file

  • Copy the Linux system kernel file initrd.img and the initialization image file to the tftp root directory

4. Prepare the PXE bootloader

[root@localhost pxeboot]# yum -y install syslinux        ##The PXE bootloader is provided by the package syslinux
  • After downloading syslinux, copy the PXE boot program in this directory to the tftp root directory

5. Install and enable the FTP service and prepare the centos 7 installation source

[root@localhost ~]# yum -y install vsftpd
[root@localhost ~]# mkdir /var/ftp/centos7        ##new directory
[root@localhost ~]# cp -rf /mnt/* /var/ftp/centos7/        ##Copy all files under /mnt to the new directory, wait for a while to load
[root@localhost ~]# systemctl start vsftpd
[root@localhost ~]# systemctl enable vsftpd
Created symlink from /etc/systemd/system/ to /usr/lib/systemd/system/vsftpd.service.
[root@localhost ~]# 

6. Configure the boot menu file

  • The boot menu is used to guide the boot process of the client, including how to invoke the kernel and how to load the initialization image.
  • The default boot menu file is in the pxelinux.cfg subdirectory of the TFTP root directory (/var/lib/tftpboot/), and the file name is default
[root@localhost ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@localhost ~]# vim /var/lib/tftpboot/pxelinux.cfg/default

7. Confirm that the firewall is turned off and verify the PXE network installation

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
setenforce: SELinux is disabled
[root@localhost ~]# 
  • Use VMware to create a new virtual machine for testing. Note that the memory of the virtual machine here is at least 2G, otherwise an insufficient memory error will occur.
  • Do not move the virtual machine settings, just click Start
  • Press the Enter key directly after the prompt string "boot:" (or execute the "auto" command), it will automatically download the installation file through the network, and enter the default graphical installation entry (press the "↑" or "↓" key during the check progress)

  • If the "linux text" command is executed, enter the text installation entry
  • If you execute the "linux rescue" command, enter the rescue mode

5. Implement Kickstart Unattended Installation

  • The previous article introduced the method of remotely installing the CentOS 7 system through PXE technology. The installation medium is no longer limited to CD-ROMs, mobile hard disks and other devices, which greatly improves the flexibility of system installation.
  • However, a series of cross-operations such as manual selection of language, keyboard type, and installation source are still required during installation, which is very inconvenient when batch installation is required.
  • Next, we will further learn how to realize unattended automatic installation. By using the Kickstart tool to configure the installation answer file, various settings in the installation process are automatically completed, so that manual intervention is not required and the network installation efficiency is improved.

1. Prepare to install the answer file

  • After installing the system-config-kickstart tool in CentOS 7, you can configure the installation answer file through the graphical wizard tool
[root@localhost ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 write-protected, will mount as read-only
[root@localhost ~]# yum -y install system-config-kickstart

2. Open the Kickstart Configurator window

Via the desktop menu "Applications"-->"System Tools"-->"Kickstart" Open
 implement " system-config-kickstart" command open

3. Configure kickstart options

3.1 Basic configuration

3.2 Installation method

3.3 Bootloader options

3.4 Partition Information

- /boot 500M

- /home 4096M

- /swap 4096M

- / All remaining space is allocated to it

3.5 Network Configuration

3.6 Firewall Configuration

3.7 Post-install scripts

Check "Use Interpreter":/bin/bash
rm -rf /etc/yum.repos.d/*
echo '[local]
gpgcheck=0' > /etc/yum.repos.d/local.repo

4. Save the auto answer file

  • Select the specified save location, the file name is ks.cfg
    Saved by default in /root/ks.cfg

5. Realize batch automatic installation

  • After having the answer file for automatic installation, as long as it is placed in the FTP directory of the PXE installation server, and the boot menu is modified appropriately, the network-based batch automatic installation can be realized.

5.1 Check and confirm that it has been saved successfully

  • Then copy it to the /var/ftp directory
[root@localhost ~]# ls
anaconda-ks.cfg       ks.cfg  template picture download desktop
initial-setup-ks.cfg  public    Video Document Music
[root@localhost ~]# cp /root/ks.cfg /var/ftp/ks.cfg
[root@localhost ~]# cd /var/ftp/
[root@localhost ftp]# ls
centos7  ks.cfg  pub
[root@localhost ftp]# 

5.2 Configure the packages to be installed

[root@localhost ftp]# cd
[root@localhost ~]# ls
anaconda-ks.cfg       ks.cfg  template picture download desktop
initial-setup-ks.cfg  public    Video Document Music
[root@localhost ~]# vim anaconda-ks.cfg 
[root@localhost ~]# 
  • For desktop installation, you need to copy the %packages to %end section to the ks.cfg file
  • Right click, copy and paste
[root@localhost ~]# vim ks.cfg 

Direct i to enter the editing mode, pull to the bottom, right-click to copy and paste, wq save and exit, done

5.3 Edit the boot menu file default and add the ks boot parameter

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

6. Verify unattended installation

  • After enabling auto-response, every time the client machine boots in PXE mode, it will automatically download the ks.cfg answer configuration file, and then install the CentOS 7 system according to its settings without system intervention
  • Start a new blank virtual machine and try (don't get 1G default memory again, big brother with insufficient memory)

  • The process is fully automatic and only requires you to perform this step and accept the license
  • Then log in as a user and enter the password

  • became
  • After the client is installed, check its yum repository configuration, you can find that the /etc/yum.repos.d/local.repo file has been automatically created according to the settings of the "post-installation script"
[root@localhost ~]# cat /etc/yum.repos.d/local.repo 
[root@localhost ~]# 

##Friends, you can open a few more blank virtual machines and try the thrill of high-efficiency brainless installation in large quantities##

Humble Reminder: Beware of Fans Exploding
= =,

Posted by PHPNewbie55 on Mon, 02 May 2022 03:38:58 +0300