CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

Preface:

I believe many people have had the experience of installed systems, used to be CD-ROM, and now basically use U disk to install the system. We just need to make a U-disk drive, the installation easy and quick. But if a company will need to install a large number of systems, U disk obviously does not fit, it will spend a lot of time. Then we can use the PXE remote installation services, and it can provide a large number of clients at the same time to install the system. However, the number of simultaneous client installation is subject to the bandwidth limitations. And install the system, but also partially set manually. At this time we will use the Kickstart unattended installation.

Summary:

PXE: Pre-Boot Execution Environment (Preboot eXecution Environment, PXE) is also known as pre-execution environment, provides a mechanism to boot the computer using a network interface (Network Interface) is. This mechanism lets you start your computer can not rely on local data storage devices (like hard disks) or locally installed operating system. Operating in network mode Client / Server support workstations from a remote server to download the image, and thereby support via a network through a network operating system boot, the boot process, the terminal requires the server to assign an IP address, and then TFTP (trivial file transfer protocol ) or MTFTP (multicast trivial file transfer protocol) protocol to download a package to start the machine's memory executed by the startup completion terminal basic software package provided to guide the terminal operating system pre-installed in the server. Strictly speaking, PXE is not an installation, but a guide mode. PXE installation of the necessary conditions must contain a PXE support of the machine to be installed in the network card (NIC), that is, the card must have a PXE Client. PXE protocol allows the computer to boot through the network. This protocol is divided into Client-Server and an end, and the Client is the PXE ROM in the NIC. When the computer boots, the BIOS into memory the PXE Client performed by the PXE Client then placed at the distal end of the file is downloaded over the network to the local operation. Run PXE protocol need to set up a DHCP server and TFTP server. The DHCP server will PXE Client (host system will be installed) assigned an IP address, since the IP address is assigned to the PXE Client, so that when configuring the DHCP server need to add the appropriate PXE settings. In addition, in the ROM PXE Client, has been in existence TFTP Client, then you can go to the TFTP Server download the desired file by TFTP protocol.


Kickstart: an unattended installation. It works by recording various parameters typical of manual intervention required to fill in during the installation process, and generates a file named ks.cfg. If the situation appears to fill parameters (Kickstart installation file is not limited to generate machine) during installation, the installation program will first go to find Kickstart files generated, if the appropriate parameters found, using the parameters found; if not found the appropriate parameters, the installer will need a manual intervention. So, if Kickstart file covers all the parameters required to complete the installation process that may occur, so the installer can only tell the installer where to take the ks.cfg file, then go do your own thing. Other installation, the installer is provided in accordance ks.cfg restart the system, and complete the installation.

PXE working process:

1. PXE Client 从自己的PXE网卡启动,向本网络中的DHCP服务器索取IP;

2. DHCP 服务器会分配给客户机的IP,同时告知PXE文件的放置位置(该文件一般是放在一台TFTP服务器上) ;

3. PXE Client 向本网络中的TFTP服务器索取pxelinux.0 文件;

4. PXE Client 取得pxelinux.0 文件后之执行该文件;

5. 根据pxelinux.0 的执行结果,通过TFTP服务器加载内核和文件系统 ;

6. 进入安装画面, 此时可以通过选择HTTP、FTP、NFS 方式之一进行安装(我用的是FTP)。

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

lab environment:

With VMware14 virtual machine to perform this experiment:

1. First, in order to facilitate the experiment, we need a CentOS7 deploy DHCP, TFTP, FTP service as a PXE server. The server needs to configure dual card, a mode of NAT for network installation procedures required, as only a master mode, a fixed IP configured to communicate with the LAN.
2. Create a virtual machine is used as the PXE client, for remote installation, the installation system is also CentOS7.

Experimental operation:

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

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

2. Go to "/ network-scripts /" directory, a copy of "ifcfg-ens33" configuration file named "ifcfg-ens36". "-P" to retain the existing permissions.

输入:cd /etc/sysconfig/network-scripts/
输入:cp -p ifcfg-ens33 ifcfg-ens36

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

3. edit the configuration file "ifcfg-ens36" with vim editor, the "dhcp" was changed to "static", "ens33" changed to "ens36", delete "UUID", while adding IP address, subnet mask gateway.

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=7bdb3fdc-0c3b-4a92-918d-3815b0816b02
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.100.100
NETMASK=255.255.255.0
GATEWAY=192.168.100.1

4. Restart network services, and then check the network configuration. Fixed IP "ens36" card has been successfully set.

输入:systemctl restart network
输入:ifconfig

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

5. Install the DHCP service required packages.

输入:yum install dhcp -y

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

6. Copy the master template of a DHCP configuration file, covering the main DHCP configuration file.

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

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

7.用vim编辑器对DHCP服务主配置文件进行编辑,添加一个“192.168.100.0”网段的配置文件,地址池可根据具体情况自己决定,主要是下一个TFTP服务器的路径和引导程序的位置。
CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

添加:
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.114;
        next-server 192.168.100.100;
        filename "pxelinux.0";
}

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

8.安装“syslinux”软件包和“tftp-server”软件包。

输入:yum install syslinux -y
输入:yum install tftp-server -y

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation
CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

9.查看一下“syslinux”和“tftp-server”软件包的配置文件,我将重要的配置文件标了出来。

输入:rpm -ql syslinux |grep pxelinux.0
输入:rpm -ql tftp-server

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

10.复制一份“pxelinux.0”文件到“/var/lib/tftpboot/”目录下,并查看是否复制成功。

输入:cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
输入:ls /var/lib/tftpboot/

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

11.用vim编辑器对TFTP服务的配置文件进行编辑,将“disable”后的“yes”改为“no”,开启TFTP服务。

输入:vim /etc/xinetd.d/tftp

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation
CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

12.安装FTP服务所需软件包。

输入:yum install vsftpd -y

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

13.进入到FTP服务的站点目录下,新建一个centos7目录。

输入:cd /var/ftp/
输入:mkdir centos7

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

14.将PXE客户端所需要的光盘镜像挂载到刚才创建的centos7目录下,并查看挂载信息(你也可以直接复制过去)。

输入:mount /dev/sr0 /var/ftp/centos7/
输入:df -h

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

15.进入到“centos7/images/pxeboot/”目录下(可以一步直接进入),将文件“initrd.img”和“vmlinuz”复制到“/var/lib/tftpboot/”目录下。

输入:cd centos7/images/pxeboot/
输入:cp initrd.img vmlinuz /var/lib/tftpboot/

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

16.查看一下“ /var/lib/tftpboot/”目录,已经有了三个文件了,其中“pxelinux.0”是引导程序文件,“vmlinuz”是压缩内核文件,“initrd.img”是系统初始化文件。现在还差一个默认的启动菜单文件,所以我们直接进入“/var/lib/tftpboot/”目录,创建一个目录“pxelinux.cfg”,然后在目录“pxelinux.cfg”内新建一个文件“default”。

输入:ls /var/lib/tftpboot/
输入:cd /var/lib/tftpboot/
输入:mkdir pxelinux.cfg
输入:cd pxelinux.cfg/
输入:vim default

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

17.在“default”文件中,输入以下内容。

default auto                                                                                                                 //默认自动模式
prompt 1                                                                                                                      //等待时间1s

label auto                                                                                                                    //自动模式安装
        kernel vmlinuz
        append initrd=initrd.img method=ftp://192.168.100.100/centos7

label linux text                                                                                                           //文本模式安装
        kernel vmlinuz
        append text initrd=initrd.img method=ftp://192.168.100.100/centos7

label linux rescue                                                                                                    //进入救援模式
        kernel vmlinuz
        append rescue initrd=initrd.img method=ftp://192.168.100.100/centos7

18.关闭防火墙和增强性安全功能,同时开启DHCP、TFTP、FTP服务。

输入:systemctl stop firewalld.service
输入:setenforce 0
输入:systemctl start dhcpd
输入:systemctl start tftp
输入:systemctl start vsftpd

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

19.咱们新建一个虚拟机,具体配置如下图,注意网络为仅主机模式。

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

20.打开新建的虚拟机作为PXE客户机,选择网络驱动。

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

21.客户机会获取到DHCP服务分配的IP地址,然后启动引导程序,加载默认的启动菜单。此时需要回车才会继续。

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

22.在回车后,稍作等待就会进入系统安装的设置界面。

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

23.我们可以看到PXE远程安装服务,在安装过程中任需要人工进行设置,而我们需要的是无人值守安装,那么我们可以配置“kickstart”程序。首先安装一个“system-config-kickstart”软件包。

输入:yum install system-config-kickstart -y

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

24.我们进入图形化界面(可以用“init 5”命令进入),进入Kickstart的配置面板。

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

25.基本配置,设置好默认语言和时区,同时设置root用户密码,勾选安装后重启。

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

26.安装方法,选择FTP,同时输入FTP服务器的路径和存放镜像文件的目录。

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

27.引导装载程序选项,勾选安装引导装载程序即可。GRUB密码也可以设置,这样系统会更加安全。

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

28.分区信息,点击添加分别设置“/boot”、“/home”、“swap”、“/”等分区的大小。注意根分区“/”不用设置大小,直接勾选使用磁盘全部未使用空间即可。

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installationCentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation
CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation
CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation
CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

29.网络配置,添加一块ens33网卡,网络类型默认的DHCP模式即可。

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

30.防火墙配置,禁用SELinux。

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

31.安装后脚本,选择使用解释程序,输入“/bin/bash”即可。

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

32.保存配置好的文件,将文件“ks.cfg”保存到FTP服务的站点目录”/var/ftp“下。

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation
CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

33.我们先进入root的家目录,用vim编辑器进入“anaconda-ks.cfg”文件,这是“ks.cfg”的模板文件,我们将其中的安装包命令复制,粘贴到“ks.cfg”文件中去。

输入:cd ~
输入:vim anaconda-ks.cfg
输入:cd /var/ftp/
输入:vim ks.cfg

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation
CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation
CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation
CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

34.我们再进入“/var/lib/tftpboot/pxelinux.cfg/” 目录,用vim编辑器对“default”文件进行编辑,在自动模式的文件后面添加一个kickstart配置文件的路径。

default auto
prompt 1

label auto
        kernel vmlinuz
        append initrd=initrd.img method=ftp://192.168.100.100/centos7 ks=ftp://192.168.100.100/ks.cfg

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

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

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

35.我们再新建一台虚拟机,配置与之前的相同。

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

36.启动新建的虚拟机,操作与PXE远程安装一样,不过这次不需要在手动设置了,系统会自动执行我们在“ks.cfg”文件中配置的内容。

CentOS 7 Deployment Remote Installation Services PXE and Kickstart unattended installation

Guess you like

Origin blog.51cto.com/14449541/2438414