pxe remote installation service and unattended installation

Steps to install PXE remote service (install a virtual machine as a server, 300G)

1. Prepare Centos installation source (yum warehouse)

Mount the CD: mount /devcdrom /mnt
Permanent mount: vi /etc/fstab; add: /dev/cdrom /mnt iso9660 defaults 0 0
Turn off the firewall: systemctl stop firewalld
Startup: systemctl disable firewalld
Turn off the core protection: vi / etc/selinux/config; Modify SELINUX=disabled and
switch to: cd /etc/yum.repos.d/
Create directory: mkdir backup
Move file: mv C* backup/
Copy data: cp backup/Centos-Base.repo local.repo
Edit the file:

vi local.repo
[centos]
name=CentOS
baseurl=file:///mnt
gpgcheck=0
enabled=1
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

Clear yum cache: yum clean all
open local yum cache: yum makecache

2. Install and enable TFTP service

Create a directory: mkdir -p /var/ftp/centos7
copy the CD data: cp -rf /mnt/* /var/lib/centos7
install vsftpd service: yum -y -install vsftpd
start vsftpd service: systemctl start vsftpd
start automatically: systemctl enable vsftpd
installs the TTP service, which is provided by the tftp-server software package: yum -y install tftp-server

The software is managed by the xinetd super service, so the configuration file is located in /etc/xinetd.d/tftp. When configuring, just change "disable=yes" to "disable=no", and then start the xinetd service:

vi /etc/xinetd.d/tftp 
.....................省略内容
改为:disable=no
.....................省略内容

Start tftp service: systemctl start tftp
self- start after booting: systemctl enable tftp

3. Prepare the Linux kernel and initialize the image file

Switch directory: cd /mnt/images/pxeboot
copy two files: cp vmlinux initrd.img /var/lib/tftpboot

4. Prepare PXE boot program and boot menu file

The PXE boot program is pxelinux.0 provided by the software package syslinux, so install syslinux first:
yum -y install syslinux
Copy files: cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot

5. Install dhcp service

Install dhcp: yum -y install dhcp
edit: vi /etc/dhcp/dhcpd.conf

subnet 20.0.0.0 netmask 255.255.255.0 {
option routers 20.0.0.24;
option subnet-mask 255.255.255.0;
option domain-name "bdqn.com";
option domain-name-servers 20.0.0.254,202.106.0.20;
default-lease-time 21600;
max-lease-time 43200;
range 20.0.0.100 20.0.0.200;
next-server 20.0.0.24;                    #####指定 TFTP 服务器的地址
filename "pxelinux.0";                     ####指定 PXE 引导程序的文件名
}

Start the dhcp service: systemctl start dhcpd
boot from the start: systemctl enable dhcpd

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 default, which should be placed in the pxelinux.cfg subdirectory of the tftp root directory. A typical boot
menu configuration can be created manually by referring to the following operations.

Create file: mkdir /var/lib/tftpboot/pxelinux.cfg
Edit: vi /var/lib/tftpboot/pxelinux.cfg/default

default auto
prompt 1
   label auto
            kernel vmlinuz
            append initrd=initrd.img method=ftp://20.0.0.24/centos7
   label linux text
            kernel vmlinuz
            append text initrd=initrd.img method=ftp://20.0.0.24/centos7
   label linux rescue
            kernel vmlinuz
            append rescue initrd=initrd.img method=ftp://20.0.0.24/centos7

7. Install a virtual machine (test machine) with a memory greater than 2G, and install a different disc image; enter the system and press Enter. . . . (test)

Realize Kickstart unattended installation. (Configuring on the server)

1. Install the system-config-kickstart tool, that is, configure the installation answer file through a graphical wizard tool.

            yum -y install system-config-kickstart

2. Switch the root user on the server to open the graphical interface for configuration:

Basic configuration:
Default language: Chinese (PR of China)-Chinese (Simplified)
Keyboard: US English
Time zone: Asia/Shanghai
Root password: abc123
Default password: abc123
Check √: Encrypt the root password
Advanced configuration:
Target architecture: X86, AMD64, IntelEm64T
check √: restart after installation Uncheck: install
in text mode (default is graphical mode)

########Installation method##########
Installation method:
check √: perform a new installation

Installation method:
check √: FTP
FTP server: ftp://20.0.0.254
FTP directory: centos

########Boot loader options######
Installation type:
check √: install new boot loader

########Partition Information##########
In the "Partition Information" interface, you need to plan the hard disk partition scheme correctly. For example, you can divide a 500MB /boot
partition, 4GB /home partition, 2GB swap partition, and divide the remaining space into the root partition

/boot xfs is 500
/home xfs is 4096
swap is 2048
/ xfs is 1
#######################

#####Network Configuration and Firewall Configuration####
In the "Network Configuration" interface, add a network device "ens33" and set the network type to "DHCP".
In the "Firewall Configuration" interface, you can choose to disable SELinux and disable the firewall.

#####Package selection##### The
CentOS 7 system no longer provides a choice of software packages. If you need to install the software package, you can copy the package installation script of /root/anaconda-ks.cfg to In the ks.cfg file, you only need to copy the %packages to the %end part. Between %packages and %end, it contains a list of packages starting with @. Delete the unwanted software names. The rest is the system will Automatically installed software packages. For example, only keeping the following content is a minimal installation

###Other information###
If there is no special requirement, just keep the default settings in the "Verify" interface and "Display Configuration" interface.

####After installing the script####
Check √: Use the interpreter: /bin/bash
Type your %post script below:

rm -rf /etc/yum.repos.d/*
echo -e ‘[base]\nname=CentOS7.6\nbaseurl=ftp://20.0.0.254/centos7\nenabled=1
ngpgcheck=1\ngpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7’>/etc/yum.repos.d/centos7.repo

3. Switch to the character interface

Edit: vi ks.cfg
added at the end of the data: %packages
@^minimal
%end

4. Start the automatic answer file

In the PXE remote installation server, copy the answer file created in the previous section to the /var/ftp/centos7 directory,
so that the client can access through ftp://20.0.0.254/centos7/ks.cfg; then edit the boot menu File
default, add the ks boot parameter to specify the URL path of the ks.cfg answer file.

Copy: cp /root/ks.cfg /var/ftp/ks.cfg
Edit: vi /var/lib/tftpboot/pxelinux.cfg/default

default auto
prompt 0
  label auto
       kernel vmlinuz
       append initrd=initrd.img method=ftp://20.0.0.24/centos7 ks=ftp://20.0.0.24/ks.cfg
   (其他几行在开头添加“#”号)

5. Verify unattended installation

Authentication performed on the test:
enabled Auto answer after installation, each time when the client to PXE boot, will automatically download ks.cfg answer with
a profile, and install the system in accordance with CentOS 7 disposed therein, without manual intervention, such as As shown in Figure 6.8, the
system can be installed for multiple clients at the same time.
After the client is installed, check its YUM software warehouse configuration, and you can find that
the /etc/yum.repos.d/centos7.repo file has been automatically created according to the settings of the "post-installation script" .

[root@localhost ~]# cat /etc/yum.repos.d/centos7.repo
[base]
name=CentOS7.6
baseurl=ftp://20.0.0.24/centos7
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/ RPM-GPG-KEY-CentOS-7

———————————————————————————————————————————————— ————————————————————————————————————
This is the end, thanks for watching.

Guess you like

Origin blog.csdn.net/XCsuperman/article/details/107804466