PXE remote network and installed unattended installation CentOS 7

Linux in large-scale application environments, such as Web clusters, distributed computing, servers are often not equipped with CD-ROM device, in this case, how to hundreds of servers bare metal quick installation system? Traditional USB drives, removable hard disk installation is apparently powerless, then we need to --PXE network installed and unattended installation.

PXE network and installed unattended installation function may be implemented are:
1. scale: simultaneously mounting multiple servers;
2. Automation: mounting system configured services;
3. Remote achieved: no CD-ROM, U-mounted medium.

Figure:
PXE remote network and installed unattended installation CentOS 7

Installed on Windows PXE network can refer Bowen: Windows Server 2016 to deploy WDS Service

若要搭建PXE网络体系,必须要满足的条件有:
1.客户机的网卡支持PXE协议(集成BOOTROM芯片),且主板支持网络引导;
2.网络中必须有一台DHCP服务器为客户机分配IP地址、指定引导文件的位置;
3.服务器通过TFTP(简单文件传输协议)提供引导镜像文件的下载。

Where the first condition is that the hardware requirements, most of the current server and PC are able to provide this support, it can simply allowed to start from Network or LAN in the BIOS setup.

Once satisfied, we have to achieve this function!

Remote Installation Services PXE basic deployment process:

The test PXE remote installation server integrates CentOS 7 installation source, FTP service, TFTP service, DHCP service can send PXE boot program like client (bare metal), Linux kernel boot menu and other data, as well as providing installation files.

PXE远程安装服务的部署过程大致可以分成这样几步:
1.安装FTP服务并准备CentOS 7 安装源;
2.安装TFTP服务并启动;
3.准备Linux内核、初始化镜像文件;
4.准备PXE引导程序、启动菜单文件;
5.安装并启动DHCP服务;
6.验证PXE网络安装效果。

Next we start step by step to complete the experiment, and to achieve the desired results!

1. Install the FTP service and are ready to install CentOS 7 sources

Install a range of services by setting up a local YUM way. If you have friends do not understand the structures of YUM can refer Bowen: YUM warehouse configuration and command Detailed

[root@localhost ~]# mount /dev/cdrom /mnt
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# rm -rf *
[root@localhost yum.repos.d]# vim a.repo
[a]
baseurl=file:///mnt
gpgcheck=0
[root@localhost ~]# yum -y install vsftpd
//安装FTP服务
[root@localhost ~]# mkdir /var/ftp/centos7
[root@localhost ~]# cp -rf /mnt/* /var/ftp/centos7/
//将光盘中的东西全部复制到FTP服务科匿名访问的目录中
[root@localhost ~]# systemctl start vsftpd
//启动FTP服务

2. Install and start the TFTP service

TFTP (Trivial File Transfer Protocol) service to use UDP port 69.

[root@localhost ~]# yum -y install tftp-server
//安装TFTP服务
[root@localhost ~]# vim /etc/xinetd.d/tftp
//修改TFTP服务的配置文件,内容如下:
service tftp
{
        socket_type             = dgram
        protocol                = udp                          //TFTP服务采用udp传输协议
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /var/lib/tftpboot             //指定TFTP服务的根目录
        disable                 = no                           //这项必须改成“no”
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}
[root@localhost ~]# systemctl start tftp
//启动TFTP服务

3. Prepare the Linux kernel initialization image file

PXE network installation using Linux kernel, initialization file system CentOS 7 can be obtained from the optical disc, located images / pxeboot / directory, respectively initrd.img and vmlinuz. Copy the two files to the root directory of the TFTP service.

[root@localhost ~]# cd /mnt/images/pxeboot/
[root@localhost pxeboot]# cp vmlinuz initrd.img /var/lib/tftpboot/

4. Prepare PXE boot process, the boot menu file

PXE boot program for network installation for pxelinux.0, provided by the package syslinux. Therefore, you need to install syslinux.

[root@localhost ~]# yum -y install syslinux
[root@localhost ~]# cp /usr/share/syslinux/pxelinux.0  /var/lib/tftpboot/

Start menu to guide the client's boot process, including how to call the kernel, how to load initialization image. The default boot menu file to default, should be placed under the pxelinux.cfg subdirectory under the TFTP root directory, a typical boot menu boot file to be created manually, you can refer to the following:

[root@localhost ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
//在TFTP服务根目录下创建pxelinux.cfg目录
[root@localhost ~]# cd /var/lib/tftpboot/pxelinux.cfg/
[root@localhost pxelinux.cfg]# vim default
//创建default菜单文件。文件内容如下:
default auto
prompt 1 
label auto 
        kernel vmlinuz 
        append initrd=initrd.img method=ftp://192.168.1.1/centos7
label linux text 
        kernel vmlinuz
        append text initrd=initrd.img method=ftp://192.168.1.1/centos7

label linux rescue  
        kernel vmlinuz
        append rescue initrd=initrd.img method=ftp://192.168.1.1/centos7
其中个配置项的含义:
default:用来指定默认入口名称;
prompt:用来决定是否需要等待用户控制(1表示需要,0表示不需要);
label:用来定义并分割启动项,文件中有三种引导模式:
分别是图形安装(默认)、文本安装、救援模式;
kernel:用来指定所需内核;
append:追加配置项;
initrd:用来指定系统初始化文件;
method:用来指定安装方式;
引导入口的个数及内容根据实际情况自定义。

5. Install and start the DHCP service

Since the PXE client is usually a bare-metal system has not been installed, so in order to get in touch with the correct server and download the boot files, you need to pre-configure the DHCP server to automatically assign an address and inform the boot file location.

[root@localhost ~]# yum -y install dhcp
[root@localhost ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
//复制DHCP服务的模板
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
//修改DHCP服务的配置文件,主要内容如下:
                   ………………           //省略部分内容
subnet 192.168.1.0 netmask 255.255.255.0 {
  range 192.168.1.100 192.168.1.200;
  option domain-name-servers 192.168.1.1;
  option domain-name "internal.example.org";
  option routers 192.168.1.1;
  option broadcast-address 192.168.1.255;
  default-lease-time 600;
  max-lease-time 7200;
  next-server 192.168.1.1;                         //指定TFTP服务器的地址
  filename "pxelinux.0";                              //指定PXE引导程序的文件名
}
                   ………………           //省略部分内容
[root@localhost ~]# systemctl start dhcpd

6. Verify PXE network installation effect

For the purchase of new bare metal, generally you do not need to set (if the system is re-installed, it should be recommended to adjust BIOS network boot). If you use vmware virtual machine for testing, virtual machine memory requires at least 2GB , otherwise start error.

PXE remote network and installed unattended installation CentOS 7
Wait a few minutes later:
PXE remote network and installed unattended installation CentOS 7
this happens, indicating successful deployment!

By PXE remote installation services, though, the installation media is no longer limited to the CD-ROM, removable hard disk, U disk and other equipment, greatly improving the system's installation flexibility think, however, still requires human interactive operation during installation, when required very inconvenient batch installation. Then you need to - "Kickstart Unattended Installation"

Kickstart achieve unattended installation

实现Kickstart无人值守安装部署过程:
1.配置应答文件并保存;
2.启动自动应答文件;
3.验证无人值守安装。

Next we start step by step to complete, and to achieve the desired results!

1. Configure answer file and save

To create an answer file graphically, you need to install system-config-kickstart tool, if the configuration file is very familiar with, you can also modify the unattended installation configuration file automatically created /root/anaconda-ks.cfg directly. The case install system-config-kickstart tools, graphical editing configuration files.

[root@localhost ~]# yum -y install system-config-kickstart
//安装system-config-kickstart工具,安装完成之后:

PXE remote network and installed unattended installation CentOS 7
PXE remote network and installed unattended installation CentOS 7
PXE remote network and installed unattended installation CentOS 7
PXE remote network and installed unattended installation CentOS 7
PXE remote network and installed unattended installation CentOS 7
PXE remote network and installed unattended installation CentOS 7
PXE remote network and installed unattended installation CentOS 7
PXE remote network and installed unattended installation CentOS 7
PXE remote network and installed unattended installation CentOS 7
PXE remote network and installed unattended installation CentOS 7
PXE remote network and installed unattended installation CentOS 7
PXE remote network and installed unattended installation CentOS 7
PXE remote network and installed unattended installation CentOS 7
PXE remote network and installed unattended installation CentOS 7
PXE remote network and installed unattended installation CentOS 7
PXE remote network and installed unattended installation CentOS 7
PXE remote network and installed unattended installation CentOS 7

[root@localhost ~]# vim /var/ftp/ks.cfg 
//查看刚才通过图形化编辑的应答文件
#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$3uZeSVnX$FYsU4y8y/qqEWA66Wuysg1
# Use network installation
url --url="ftp://192.168.1.1/centos7"
# System language
lang zh_CN
# Firewall configuration
firewall --disabled
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# SELinux configuration
selinux --disabled

# Network information
network  --bootproto=dhcp --device=ens33
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part swap --asprimary --fstype="swap" --size=2048
part / --asprimary --fstype="xfs" --grow --size=1

%post --interpreter=/bin/bash
rm -rf /etc/yum.repos.d/*
cd /etc/yum.repos.d/
echo -e "[a]"  >> a.repo
echo -e "baseurl=ftp://192.168.1.1/centos7" >> a.repo
echo -e "gpgcheck=0" >> a.repo

%end

But I have already explained, leaving a shortfall of an option - "Package Selection", you need to add a few lines of configuration items themselves manually, you can add at the end, add the following:

%packages
@^minimal
%end
//这三项的意思就是最小安装

Of course, you can refer to /root/anaconda-ks.cfg file, file% end% packages between all configuration options, one per line configuration options, arbitrary choice!
We can not go through graphical editing, directly copy the configuration file! Effect can also be achieved!

2. Start auto-answer file

[root@localhost ~]# vim /var/lib/tftpboot/pxelinux.cfg/default 
default auto
prompt 0
label auto
        kernel vmlinuz
        append initrd=initrd.img method=ftp://192.168.1.1/centos7 ks=ftp://192.168.1.1/ks.cfg

The prompt to 0, which means no waiting for the user to select. Ks add boot parameters, and to develop URL access path.

3. Verify Unattended Installation

PXE remote network and installed unattended installation CentOS 7
PXE remote network and installed unattended installation CentOS 7
Completion of the experiment!

Guess you like

Origin blog.51cto.com/14157628/2429032