The CentOS system implements batch unattended installation through PXE, And the centospxe is unattended.

Source: Internet
Author: User
Tags file transfer protocol

The CentOS system implements batch unattended installation through PXE, And the centospxe is unattended.

Manual intervention is required to install and deploy a computer in the traditional way. It takes a lot of time to deploy a large number of workstation or server with similar functions. In addition, in the traditional installation mode, each computer requires an optical drive device, an installation disc, and other media, which will increase the deployment cost. Therefore, many system administrators want to deploy the operating system to the target computer through a network-based, unattended automatic installation method.

 

I. related services and tools

1. PXE Protocol

PXE is a protocol designed by Intel. Computers can boot from the network through the PXE protocol. The PXE protocol is divided into client and server during the startup process. The PXE protocol mainly solves two problems: IP address first, then solve the problem of how to transfer the Operating System Startup File and Installation File. The first problem can be solved through the DHCP Server. Generally, the DHCP Server is mainly used to assign an IP address to the client. However, in the PXE environment, the DHCP server needs to load additional PXE configurations. To solve the second problem, the PXE client has a corresponding TFTP client in the early stage. You can download the relevant files to the TFTP server through the TFTP protocol to start the computer. During the later installation process, a large number of operating system installation files are downloaded through FTP or NFS protocol.

2. Kickstart

When you install and deploy a computer in a traditional way, you are required to answer various questions in an interactive manner to complete the installation and deployment tasks. This process is cumbersome and cannot be automated. RedHat developed the Kickstart installation method. The ks file can solve all the problems that need to be answered during normal installation. You can use the system-config-kickstart tool to customize the ks file, or you can use the relevant syntax to manually write the installation script.

3. CentOS Operating System

The operating system used and installed in this experiment is CentOS 7. In theory, CentOS 6 is also applicable.

4. DHCP

The Dynamic Host Configuration Protocol is mainly used to automatically assign IP addresses to DHCP clients to facilitate user management of computers in the network. In the PXE environment, in addition to the IP address assigned to the DHCP server, you also need to configure the "next-server" option to define the address of the TFTP server and set the "filename" option to define the name of the Startup File. And enable support for "booting" and "bootp.

5. TFTP and FTP

The simple File Transfer Protocol (TFTP) is mainly used for simple file transfer between the client and the server. During early PXE startup, "pxelinux.0" was transmitted mainly through the TFTP protocol ". The file transfer protocol (FTP) is suitable for transferring a large number of files. During the later installation process, the installation package of the Linux operating system is transmitted through FTP.

 

Ii. install and configure the FTP service

The FTP service mainly downloads ks. cfg files and operating system files. It can also be replaced by HTTP or NFS.

1. Install the vsftpd service

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

2. Provide operating system image files

The default FTP configuration is enough. We need to apply anonymous users. To install the operating system through ftp, We need to copy the operating system image file to this anonymous user directory.
[Root @ localhost ~] # Mount/dev/cdrom/var/ftp/pub/#/var/ftp/pub is the ftp Anonymous user directory

3. Start the ftp service

[Root @ localhost ~] # Systemctl start vsftpd # start the ftp service [root @ localhost ~] # Systemctl enable vsftpd # Set startup

 

3. Install dhcp and tftp

The DHCP and TFTP services can be separately installed, or the dnsmasq service can be installed to implement DHCP and TFTP functions.

1. Install the dnsmasq package

[root@localhost ~]# yum install -y dnsmasq

2. Configure dnsmasq

The dnsmasq configuration file is/etc/dnsmasq. conf, which removes the following comments and sets the DHCP modification range and the TFTP root directory.

Bogus-privfilterwin2kinterface = eth0dhcp-range = 192.168.0.50, 192.168.0.100, 12hdhcp-boot = pxelinux?enable-tftptftp-root =/Var/Tftp# The tftp directory does not exist by default. You need to manually create dhcp-authoritative

3. Create a tftp root directory

[root@localhost ~]# mkdir /var/tftp

4. Start dnsmasq

[root@localhost ~]# systemctl start  dnsmasq[root@localhost ~]# systemctl enable dnsmasq

 

4. Copy and prepare relevant files

1. Copy kernel images and file system images from iso

Cp/var/ftp/pub/images/pxeboot/initrd. img/var/tftp/# copy the file system image cp/var/ftp/pub/images/pxeboot/vmlinuz/var/tftp/# copy the kernel Image File

2. Generate the pxe Startup File pxelinux.0

Yum install-y syslinux # package required to install pxelinux.0 rpm-ql syslinux | grep "pxelinux.0" # query the directory cp/usr/share/syslinux/pxelinux.0/var/tftp/ # copy the pxelinux.0 file to the tftp root directory

3. Prepare the default menu configuration file.

Mkdir/var/tftp/pxelinux. cfg/# create pxelinux. cfg directory, fixed directory name: vim/var/tftp/pxelinux. cfg/default # default file, which must be named # the content to be edited is as follows: default linuxprompt 1 timeout 60 display boot. msglabel linux kernel vmlinuz append initrd = initrd. img textKs = ftp: // 192.168.0.3/ks. cfg # The ks. cfg file download path is specified here, and the file will be generated later.

4. Generate a kickstart File

The kickstart file can be configured through the system-config-kickstart visualization tool to generate the ks. cfg file; you can also slightly modify it through the template file anaconda-ks.cfg of the installed operating system. The ks. cfg file below is a sample during the experiment. The content is as follows (bold as the modification part ):

# Version = DEVEL # System authorization informationauth -- enableshadow -- passalgo = sha512 # Use CDROM installation mediaInstallurl -- url = ftp ://192.168.0.3/pub/# You need to specify the installation method to download and install the operating system through ftp # Use graphical installgraphical # Run the Setup Agent on first bootfirstboot -- enableignoredisk -- only-use = sda # Keyboard layoutskeyboard -- vckeymap = us -- xlayouts = 'us' # System Monitoring agelang en_US.UTF-8 # Network informationnetwork -- bootproto = dhcp -- device = ens33 -- onboot = off -- ipv6 = auto -- no-activatenetwork -- hostname = localhost. localdomain # Root passwordrootpw -- iscrypted $6 $ LK7yftVlSa2zcGia $ 4loHYYWZUosdWvZA7Qzf. 0lhmrcD5n26BK1xWm7QCNBdbBSjC7MK7yAYRvmIXGI8wu. feature # System servicesservices -- disabled = "chronyd" # System timezonetimezone Asia/Shanghai -- isUtc -- nontp # System bootloader configurationbootloader -- append = "crashkernel = auto" -- location = mbr -- boot-drive = sdaautopart -- type = lvm # Partition clearing informationclearpart -- all -- initlabel -- drives = sda
... # There is still a lot of content

Copy the ks. cfg file to the FTP directory.

[root@localhost ~]# cp /root/anaconda-ks.cfg /var/ftp/ks.cfg
[root@localhost ~]# chmod +r /var/ftp/ks.cfg

 

V. Operating System installation on the client

After completing the preceding steps, you can install the operating system:

1. Prepare a physical machine with proper configuration
2. Connect the network cable to the server in the same LAN
3. Set BIOS to start from NIC
4. Waiting for Installation

Some hosts cannot start and install normally from the network even if BIOS is set to start from the network. You need to carefully find the PXE switch settings of BISO and then turn it on, the BIOS settings for each host are different. You need to set the settings based on the specific hardware.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.