Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

CentOS 7 system deployment PXE remote installation service and Kickstart unattended installation

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Foreword:

I believe that many people have installed the system experience, used to use CD-ROM, now basically use USB disk to install the system. We only need to make a USB drive, which is convenient and quick to install. But if the enterprise needs to install a large number of systems at the same time, the flash drive is obviously not suitable, it will take a lot of time. At this point, we can use the PXE remote installation service, which can provide a large number of clients to install the system at the same time. However, the number of clients installed at the same time is limited by bandwidth. And when installing the system, you also need to make some settings manually. At this point, we will use the Kickstart unattended installation.

Brief introduction:

PXE: the pre-boot execution environment (Preboot eXecution Environment,PXE), also known as the pre-execution environment, provides a mechanism for starting a computer using a network interface (Network Interface). This mechanism allows the computer to start without relying on a local data storage device (such as a hard disk) or a locally installed operating system. Work in the network mode of Client/Server, which supports workstations to download images from remote servers through the network, and thus supports booting the operating system through the network. During the startup process, the terminal requires the server to assign an IP address, and then download a startup software package to the local memory with TFTP (trivial file transfer protocol) or MTFTP (multicast trivial file transfer protocol) protocol for execution. The startup software package completes the basic software settings of the terminal. Thus booting the terminal operating system pre-installed in the server. Strictly speaking, PXE is not an installation method, but a boot mode. The necessary condition for PXE installation is that a PXE-supported network card (NIC) must be included in the computer to be installed, that is, there must be PXE Client in the network card. The PXE protocol enables computers to start over the network. This protocol is divided into Client side and Server side, while PXE Client is in the ROM of the network card. When the computer boots, BIOS calls the PXE Client into memory for execution, and then PXE Client downloads the files placed at the remote end to run locally through the network. Running the PXE protocol requires setting up a DHCP server and a TFTP server. The DHCP server assigns an IP address to the PXE Client (the host on which the system will be installed), and since the IP address is assigned to the PXE Client, you need to add the corresponding PXE settings when configuring the DHCP server. In addition, TFTP Client already exists in PXE Client's ROM, so it can download the required files to TFTP Server through the TFTP protocol.

Kickstart: is an unattended installation method. It works by recording various parameters that typically require human intervention during installation and generating a file called ks.cfg. If parameters are to be filled in during the installation process (not limited to the machine that generates the Kickstart installation files), the installer will first look for the files generated by Kickstart, and if it finds the right parameters, it will use the parameters found; if the appropriate parameters are not found, the installer will need to intervene manually. So, if the Kickstart file covers all the parameters that may need to be filled in during the installation process, then the installer can just tell the installer where to get the ks.cfg file and go about his own business. When the installation is complete, the installer will restart the system according to the settings in ks.cfg and finish the installation.

The working process of PXE: 1. PXE Client starts from its own PXE network card and asks the DHCP server in this network for IP;2. The DHCP server will assign the IP to the client, while telling the location of the PXE file (the file is usually placed on a TFTP server); 3. PXE Client requests the pxelinux.0 file from the TFTP server in the network; 4. PXE Client gets the pxelinux.0 file and executes the file. 5. According to the execution result of pxelinux.0, the kernel and file system are loaded through the TFTP server; 6. When you go to the installation screen, you can install it by selecting one of HTTP, FTP or NFS (I use FTP).

Experimental environment:

Use the VMware14 virtual machine to do this experiment:

1. First of all, in order to facilitate the experiment, we need a CentOS7 to deploy DHCP, TFTP and FTP services as PXE servers at the same time. The server needs to configure double network cards, one is NAT mode, which is used to install the required programs on the network, and the other is host-only mode, and a fixed IP is configured to interwork with the local area network.

two。 A new virtual machine is used as a PXE client for remote installation, and the installed system is also CentOS7.

Experimental operation:

1. Add a network card to the client and change the network mode to host-only mode.

two。 Go to the "/ network-scripts/" directory and copy a "ifcfg-ens33" configuration file named "ifcfg-ens36". "- p" retains the original permissions.

Input: cd / etc/sysconfig/network-scripts/ input: cp-p ifcfg-ens33 ifcfg-ens36

3. Edit the configuration file "ifcfg-ens36" with the vim editor, change "dhcp" to "static", "ens33" to "ens36", delete "UUID", and add IP address, subnet mask and gateway.

TYPE=EthernetPROXY_METHOD=noneBROWSER_ONLY=noBOOTPROTO=staticDEFROUTE=yesIPV4_FAILURE_FATAL=noIPV6INIT=yesIPV6_AUTOCONF=yesIPV6_DEFROUTE=yesIPV6_FAILURE_FATAL=noIPV6_ADDR_GEN_MODE=stable-privacyNAME=ens33UUID=7bdb3fdc-0c3b-4a92-918d-3815b0816b02DEVICE=ens33ONBOOT=yesIPADDR=192.168.100.100NETMASK=255.255.255.0GATEWAY=192.168.100.1

4.

Input: systemctl restart network input: ifconfig

5. Install the software packages required for the DHCP service.

Enter: yum install dhcp-y

6. Copy a template of the DHCP master profile and overwrite the DHCP master profile.

Input: cp/ usr/share/doc/dhcp-4.2.5/dhcpd.conf.example / etc/dhcp/dhcpd.conf

7. Use the vim editor to edit the DHCP service master configuration file and add a configuration file for the "192.168.100.0" network segment. The address pool can be determined according to the specific circumstances, mainly the path of the next TFTP server and the location of the bootstrap.

Add: 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 114.114.114; next-server 192.168.100.100; filename "pxelinux.0";}

8. Install the syslinux package and the tftp-server package.

Input: yum install syslinux-y input: yum install tftp-server-y

9.

Input: rpm-ql syslinux | grep pxelinux.0 input: rpm-ql tftp-server

10. Copy a "pxelinux.0" file to the "/ var/lib/tftpboot/" directory and see if the copy is successful.

Input: cp / usr/share/syslinux/pxelinux.0 / var/lib/tftpboot/ input: ls / var/lib/tftpboot/

11. Use the vim editor to edit the configuration file of the TFTP service, change the "yes" after "disable" to "no", and open the TFTP service.

Input: vim / etc/xinetd.d/tftp

twelve。 Install the software packages required for the FTP service.

Enter: yum install vsftpd-y

13. Go to the site directory of the FTP service and create a new centos7 directory.

Input: cd / var/ftp/ input: mkdir centos7

14. Mount the CD image needed by the PXE client to the centos7 directory you just created, and view the mount information (you can also copy it directly).

Input: mount / dev/sr0 / var/ftp/centos7/ input: df-h

15. Go to the "centos7/images/pxeboot/" directory (you can enter it directly in one step) and copy the files "initrd.img" and "vmlinuz" to the "/ var/lib/tftpboot/" directory.

Input: cd centos7/images/pxeboot/ input: cp initrd.img vmlinuz / var/lib/tftpboot/

16. Take a look at the "/ var/lib/tftpboot/" directory and you already have three files, where "pxelinux.0" is the bootstrap file, "vmlinuz" is the compressed kernel file, and "initrd.img" is the system initialization file. There is still a default startup menu file missing, so let's go directly to the "/ var/lib/tftpboot/" directory, create a directory "pxelinux.cfg", and then create a new file "default" in the directory "pxelinux.cfg".

Input: ls / var/lib/tftpboot/ input: cd / var/lib/tftpboot/ input: mkdir pxelinux.cfg input: cd pxelinux.cfg/ input: vim default

17. In the default file, enter the following.

Default auto / / default automatic mode prompt 1 / / wait time 1slabel auto / / install kernel vmlinuz append initrd=initrd.img method= ftp://192.168.100.100/centos7label linux text in automatic mode / / install kernel vmlinuz append text initrd=initrd.img method= ftp://192.168.100.100/centos7label linux rescue in text mode / / enter rescue mode kernel vmlinuz append rescue initrd=initrd.img method= ftp://192.168.100.100/centos7

18. Turn off the firewall and enhanced security features, and turn on DHCP, TFTP and FTP services at the same time.

Input: systemctl stop firewalld.service input: setenforce 0 input: systemctl start dhcpd input: systemctl start tftp input: systemctl start vsftpd

19. Let's create a new virtual machine and configure it as shown in the following figure. Note that the network is in host-only mode.

20. Open the newly created virtual machine as the PXE client and select the network driver.

21. The client gets the IP address assigned by the DHCP service, then launches the bootstrap and loads the default startup menu. At this point, you need to enter to continue.

twenty-two。 After entering, after a short wait, you will enter the setup interface of the system installation.

23. We can see that the PXE remote installation service needs to be set up manually during the installation process, and what we need is an unattended installation, so we can configure the "kickstart" program. First install a "system-config-kickstart" package.

Enter: yum install system-config-kickstart-y

24.

25. Basic configuration, set the default language and time zone, and set the root user password. Check the box to install and restart.

twenty-six。 Installation method, select FTP, and enter the path of the FTP server and the directory where the image files are stored.

twenty-seven。 Bootloader option, check to install the bootloader. The GRUB password can also be set so that the system is more secure.

twenty-eight。 For partition information, click add to set the size of "/ boot", "/ home", "swap", "/" and other partitions respectively. Note that there is no need to set the size of the root partition "/", just check the use of all unused disk space.

twenty-nine。 Network configuration, add an ens33 network card, network type default DHCP mode can be.

thirty。 Firewall configuration, disable SELinux.

thirty-one。 For the post-installation script, choose to use the interpreter and type "/ bin/bash".

thirty-two。 Save the configured file and save the file "ks.cfg" to the site directory "/ var/ftp" of the FTP service.

thirty-three。 We first enter the root home directory, use the vim editor to enter the "anaconda-ks.cfg" file, this is the "ks.cfg" template file, we copy and paste the installation package commands into the "ks.cfg" file.

Input: cd ~ input: vim anaconda-ks.cfg input: cd / var/ftp/ input: vim ks.cfg

thirty-four。 Let's go to the "/ var/lib/tftpboot/pxelinux.cfg/" directory, edit the "default" file with the vim editor, and add a path to the kickstart configuration file after the file in automatic mode.

Default autoprompt 1label auto kernel vmlinuz append initrd=initrd.img method= ftp://192.168.100.100/centos7 ks= ftp://192.168.100.100/ks.cfglabel linux text kernel vmlinuz append text initrd=initrd.img method= ftp://192.168.100.100/centos7label linux rescue kernel vmlinuz append rescue initrd=initrd.img method= ftp://192.168.100.100/centos7

thirty-five。 Let's create a new virtual machine with the same configuration as before.

thirty-six。 Start the newly created virtual machine in the same way as the PXE remote installation, but this time you don't need to set it manually, the system will automatically execute what we configured in the "ks.cfg" file.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report