Linux--PXE+Kickstart unattended to realize efficient batch network installation--On how to be a qualified network manager?


Preface

  • With the continuous growth of Internet technology, the number of servers is also increasing. IT operation and maintenance has become an important part of the connotation of IT services. In the face of more and more complex businesses 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 flexibly, conveniently, safely and continuously guaranteed. The guarantee factor in this model is IT operation and maintenance
  • From the initial development of a few servers to a huge data center, manual labor alone can no longer meet the requirements of technology, business, management, etc., so standardization, automation, architecture optimization, process optimization and other factors that reduce IT service costs are becoming more and more. Valued by people
  • And how to automate batch deployment and install a stable system is the first step to achieve automation.
  • Next, we learn with PXE (pre-boot Execution Environment, based on pre-boot Execution Environment ) network installed art methods, and binding Kickstart configuration unattended automatic installation

1. Introduction to PXE

  • PXE, which is the pre-boot execution environment , is a way of booting. This kind of agreement 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 the "source" when installing the system The installation of the system can be realized.
  • PXE is a network boot technology developed by Intel. It works in Client/Server mode, allowing clients to download boot images from remote servers via the network, and load installation files or the entire operating system

2. Prerequisites to be met to build PXE (theoretical steps)

  • Before implementing 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 for related operations, and prompt related options, where we can choose. Therefore, 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 startup file through the network to run locally. The specific process is that the PXE client sends an ip request to the LAN through the network card, and then the DHCP server will provide it with an ip address and 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 the boot file
  • The installation process requires resources provided by other servers, such as yum sources, 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 selecting the network startup, 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 core files, etc. The server provides the download of the boot image file through TFTP (Trivial File Transfer Protocol)
  • Among them, the first condition is actually the hardware requirement. At present, most servers and most PCs can provide this support. You only need to allow booting from Network or LAN in the BIOS settings.
  • Then it starts to install automatically, and this process does not require anyone to do anything
  • The simple schematic diagram is as follows:
    mark

Three, the advantages of PXE batch deployment

  • Remote realization: not restricted by CD-ROM, CD-ROM and some external devices
  • Scale: install multiple servers at the same time
  • Automation: Install the system and configure various services, which can be unattended, which greatly reduces the workload of operation and maintenance personnel

Fourth, build a PXE remote installation server

  • The PXE remote installation server integrates:
    • CentOS7 installation source
    • TFTP service
    • DHCP service
  • Able to send PXE boot program, Linux kernel, boot menu and other data to the client bare metal, and provide installation files

1. Install and start the TFTP service

  • TFTP (Trivial File Transfer Protocol) is a protocol for simple file transfer between client and server based on UDP protocol, suitable for small file transfer applications; TFTP service is managed by xinetd service by default and used UDP port 69
  • xinetd is a new generation of network daemon service program, also called super server, commonly used to manage a variety of lightweight Internet services
  • The configuration file of the xindtd service is located in /etc/xindtd.d/ftp. When configuring, just change "disable = yes" to "disable = no".
[root@localhost ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ~]# yum -y install tftp-server xinetd        ##安装相关软件包
[root@localhost ~]# vim /etc/xinetd.d/tftp 

mark

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
[root@localhost ~]# setenforce 0
setenforce: SELinux is disabled
[root@localhost ~]# 
[root@localhost ~]# systemctl start tftp
[root@localhost ~]# systemctl enable tftp
Created symlink from /etc/systemd/system/sockets.target.wants/tftp.socket to /usr/lib/systemd/system/tftp.socket.
[root@localhost ~]# systemctl start xinetd
[root@localhost ~]# systemctl enable xinetd

2. Install and enable DHCP service

  • DHCP (Dynamic Host Configuration Protocol, Dynamic Host Configuration Protocol) is a network protocol for local area networks, which works with UDP protocol
[root@localhost ~]# yum -y install dhcp
...
...略
  • Because the /etc/dhcp/dhcpd.conf at the beginning is an empty file, the requirement in the file is to check it in /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example
  • 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        ##dhcp配置文件是dhcp.conf,正常是空的
dhclient.d             dhcpd6.conf  scripts
dhclient-exit-hooks.d  dhcpd.conf
[root@localhost dhcp]# cd /usr/share/doc/dhcp-4.2.5/        ##切换至dhcp配置模板文件目录
[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/dhcpd.conf 
cp:是否覆盖"/etc/dhcp/dhcpd.conf"? yes        ##确认覆盖,将配置文件模板复制到dhcp配置文件中去
  • Then change the configuration file of dhcpd, first change the global configuration
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf 

ddns-update-style  none;
next-server 192.168.126.15;
filename "pxelinux.0";
...
...
subnet 192.168.126.0 netmask 255.255.255.0 {
  range 192.168.126.100 192.168.126.200;
  option routers 192.168.126.15;
}

mark

  • Next change the address pool
    mark
  • Enable DHCP service
[root@localhost ~]# systemctl start dhcpd
[root@localhost ~]# systemctl enable dhcpd
Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd.service to /usr/lib/systemd/system/dhcpd.service.
[root@localhost ~]# 

3. Prepare the Linux kernel and initialize the image file

mount /dev/sr0 /mnt
cd /mnt/images/pxeboot						
cp vmlinuz /var/lib/tftpboot/	
cp initrd.img /var/lib/tftpboot/
  • Copy the Linux system kernel file initrd.img and the initialization image file to the tftp root directory
    mark

4. Prepare the PXE boot program

[root@localhost pxeboot]# yum -y install syslinux        ##PXE引导程序由软件包syslinux提供
...
...略
  • After downloading syslinux, copy the PXE boot program in this directory to the tftp root directory
    mark

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

[root@localhost ~]# yum -y install vsftpd
...
...略
[root@localhost ~]# mkdir /var/ftp/centos7        ##新建目录
[root@localhost ~]# cp -rf /mnt/* /var/ftp/centos7/        ##将/mnt下所有文件复制至该新建目录,需等待一段时间加载
[root@localhost ~]# systemctl start vsftpd
[root@localhost ~]# systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service 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 call the kernel and how to load the initial image.
  • The default boot menu file is in the pxelinux.cfg subdirectory of the TFTP root directory (/var/lib/tftpboot/), the file name is default
[root@localhost ~]# cd /var/lib/tftpboot
[root@localhost tftpboot]# ls
initrd.img  pxelinux.0  vmlinuz
[root@localhost tftpboot]# mkdir pxelinux.cfg
[root@localhost tftpboot]# vim pxelinux.cfg/default

default  auto
prompt 0

label   auto
kernel vmlinuz
append  initrd=initrd.img 
method=ftp://192.168.126.15/centos7

label linux text
kernel  vmlinuz
append text initrd=initrd.img
method=ftp://192.168.126.15/centos7

label linux rescue
kernel vmlinuz
append  rescue initrd=initrd.img
method=ftp://192.168.126.15/centos7

mark

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
  • Use VMware to create a new virtual machine for testing. Note that the memory of the virtual machine here is at least 2G or more, otherwise an insufficient memory error will occur
  • Do nothing about the virtual machine settings, just click to start
  • Press Enter directly after the prompt string "boot:" (or execute the "auto" command), the installation file will be automatically downloaded through the network, and enter the default graphical installation entrance (press "↑" or "↓" during the Check progress)
    mark

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

  • Blood and tears = = Must be careful and serious! You will lose everything if you make a wrong punctuation! ! !

Fifth, realize Kickstart unattended installation

  • The previous article introduced the method of remotely installing CentOS 7 system through PXE technology. The installation medium is no longer limited to CD-ROM, mobile hard disk and other equipment, greatly improving the flexibility of system installation
  • However, during installation, a series of cross-operations such as manually selecting language, keyboard type, and specifying installation source are still required, which is very inconvenient when batch installation is required.
  • Next, we will further learn how to implement unattended automatic installation. By using the Kickstart tool to configure the installation answer file, various settings during the installation process are automatically completed, thereby eliminating the need for manual intervention and improving the efficiency of network installation.

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 写保护,将以只读方式挂载
[root@localhost ~]# yum -y install system-config-kickstart
...
...略

2. Open the "Kickstart Configuration Program" window

通过桌面菜单“应用程序”-->“系统工具”-->“Kickstart” 打开
执行 “system-config-kickstart” 命令打开

mark
mark

3. Configure kickstart options

3.1 Basic configuration

mark

3.2 Installation method

mark

3.3 Bootloader options

mark

3.4 Partition Information

mark
-/boot
mark
500M-/home 4096M-
mark
/swap 4096M-
mark
/ The remaining space is allocated to it
mark
mark

3.5 Network configuration

mark
mark

3.6 Firewall configuration

mark

3.7 Post-installation script

勾选“使用解释程序”:/bin/bash
脚本:
rm -rf /etc/yum.repos.d/*
echo '[local]
name=local
baseurl=ftp://192.168.126.15/centos7
enabled=1
gpgcheck=0' > /etc/yum.repos.d/local.repo

mark

4. Save the auto answer file

mark

  • Select the specified save location, the file name is ks.cfg and the
    default save is /root/ks.cfg
    mark

5. Realize batch automatic installation

  • Once you have the answer file for automatic installation, just place it in the FTP directory of the PXE installation server and modify the boot menu appropriately to realize batch automatic installation based on the network.

5.1 Check to confirm that it has been saved successfully

  • Then copy it to the /var/ftp directory
[root@localhost ~]# ls
anaconda-ks.cfg       ks.cfg  模板  图片  下载  桌面
initial-setup-ks.cfg  公共    视频  文档  音乐
[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 software packages to be installed

[root@localhost ftp]# cd
[root@localhost ~]# ls
anaconda-ks.cfg       ks.cfg  模板  图片  下载  桌面
initial-setup-ks.cfg  公共    视频  文档  音乐
[root@localhost ~]# vim anaconda-ks.cfg 
[root@localhost ~]# 
  • For desktop installation, you need to copy %packages to %end to the ks.cfg file
    mark
  • Select directly, right click to copy and paste
[root@localhost ~]# vim ks.cfg 

Enter the editing mode directly i, drag to the bottom, right-click to copy and paste, wq save and exit, you are done
mark

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

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

mark

6. Verify unattended installation

  • After starting the automatic response, every time the client boots in PXE mode, it will automatically download the ks.cfg response configuration file, and then install the CentOS 7 system according to the settings therein, without system intervention
  • Open a new, blank virtual machine to try ( Memory 1G default do not they get the out of memory brother )
    mark
    ...
    ... Loading ...
  • The process is fully automatic, you only need to operate this step and accept the license
    mark
  • Then log in the user and enter the password
    mark
    mark
  • Became
    mark
  • After the client is installed, check its yum warehouse 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 
[local]
name=local
baseurl=ftp://192.168.126.15/centos7
enabled=1
gpgcheck=0
[root@localhost ~]# 

##Little friends, you can open a few more blank virtual machines and try the pleasure of mass-efficient and brainless installation##

Humble reminder: Be careful that the fan will explode
==,

Guess you like

Origin blog.csdn.net/weixin_51486343/article/details/111102708