One preparation
1.1 complete architecture: Kickstart+DHCP+NFS+TFTP+PXE
1.2 component application
Kickstart server IP: 172.24.8.12
DHCP: provide client IP, gateway, image path, etc;
TFTP: sharing pxelinux.0, initrd.img, vmlinux, isolinux.cfg, boot.msg, vesemanu.c32, splash.png files
NFS: share ks.cfg and all CD files
Note: this ks.cfg file and all CD-ROM files can also be shared through HTTP, FTP and other ways. Please refer to other notes.
1.3 installation of TFTP and other components
[root@server ~]# yum -y install dhcp* tftp* rpcbind nfs-utils [root@server ~]# yum -y install xinetd #tftp depends on xinetd, so xinetd needs to be installed
1.4 mount system CD
[root@localhost ~]# mount /dev/sr0 /mnt/cdrom/
1.5 turn off firewall and SELinux
[root@server ~]# systemctl stop firewalld.service [root@server ~]# systemctl disable firewalld.service [root@server ~]# setenforce 0 [root@server ~]# vi /etc/selinux/config #Shut down SELinux completely SELINUX=disabled
2. Server configuration
2.1 configure DHCP
[root@server ~]# vi /etc/dhcp/dhcpd.conf option domain-name-servers 223.5.5.5,223.6.6.6; #Global DNS default-lease-time 600; #Default lease time max-lease-time 7200; #Maximum leasable time subnet 172.24.8.0 netmask 255.255.255.0 { #Set up network segment range 172.24.8.13 172.24.8.50; #Set assignable address pool option routers 172.24.8.2; #Default gateway next-server 172.24.8.12; #ip of tftp server filename "pxelinux.0";} #The name of the boot file required for pxe boot, equivalent to bootloader [root@server ~]# systemctl start dhcpd.service #Start dhcp service [root@server ~]# systemctl enable dhcpd.service #Start up automatically
2.2 NFS configuration
[root@server ~]# mkdir /centosinstall #Create nfs shared directory [root@server ~]# chown nfsnobody:nfsnobody /centosinstall/ #Modify directory owner [root@server ~]# vi /etc/exports /centosinstall 172.24.8.0/24(rw,sync) [root@server ~]# cp /mnt/cdrom/* /centosinstall/ #Copy all files on the CD to the nfs directory [root@server ~]# systemctl start rpcbind.service [root@server ~]# systemctl enable rpcbind.service [root@server ~]# systemctl start nfs-server.service [root@server ~]# systemctl enable nfs-server.service
2.3 configure TFTP
[root@localhost ~]# vi /etc/xinetd.d/tftp service tftp { ...... server = /usr/sbin/in.tftpd server_args = -s /var/lib/tftpboot #This is the TFTP service root disable = no #Open TFTP ...... } [root@server ~]# systemctl start xinetd.service #When xinetd is started, the tftp managed by xinetd will also be started [root@server ~]# systemctl enable xinetd.service #When xinetd is started, the tftp managed by xinetd will also start
2.4 TFTP file configuration
#Specify relevant PXE kernel modules and relevant parameters in TFTP directory [root@server ~]# yum -y install syslinux #Linux boot loader [root@server ~]# find / -name pxelinux.0 /usr/share/syslinux/pxelinux.0 #Find the directory of pxelinux.0 file [root@server ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ #Copy pxelinux.0 to the directory where TFTP is located so that clients (hosts that need to automatically install the system) can find this loader through TFTP. [root@server ~]# cp /mnt/cdrom/images/pxeboot/{initrd.img,vmlinuz} /var/lib/tftpboot/ #copy the vmlinuz and initrd.img files in the CD directory, which are equivalent to the boot files in the / boot directory when the system starts [root@server ~]# mkdir -p /var/lib/tftpboot/pxelinux.cfg [root@server ~]# cp /mnt/cdrom/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default #Create a directory of pxelinux.cfg in TFTP directory, and copy [isolinux.cfg: display configuration file information at startup] to this directory. [root@server ~]# cp /mnt/cdrom/isolinux/{boot.msg,splash.png} /var/lib/tftpboot/ #The configuration file required for copy pxe boot, splash.png: background. boot.msg startup banner, vesemanu.c32: display the program for peer interface
2.5 modification of ks.cfg file
Note: this file is an automatic answer file during installation. You can use the anaconda-ks.cfg file of Kickstart as a template, or you can set this file graphically [refer to 006 notes].
[root@server ~]# cp /root/anaconda-ks.cfg /centosinstall/ks.cfg [root@server /]# chmod 755 /centosinstall/ks.cfg [root@server ~]# vi /centosinstall/ks.cfg auth --enableshadow --passalgo=sha512 nfs --server=172.24.8.12 --dir=/centosinstall graphical firstboot --enable ignoredisk --only-use=sda keyboard --vckeymap=us --xlayouts='us' lang en_US.UTF-8 --addsupport=zh_CN.UTF-8 #Add language support as required reboot network --bootproto=dhcp --device=eno16777736 --onboot=yes --ipv6=auto --activate #This item can be used by default. The test and modification of the network card name eth0 can not take effect. It is still eno16777736. network --hostname=localhost.localdomain rootpw --iscrypted $6$LgafQJ7F1rcyRCpk$ZteQKXvywjifMoPbAnhm7nESFx4fuROoxVYie4YvP04DGiUGpjEW2mA.m0TUQyq1ZoOUv.EF9vMWUaBjGyowW. services --disabled="chronyd" timezone Asia/Shanghai --isUtc --nontp bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda clearpart --all --initlabel part /boot --fstype="xfs" --ondisk=sda --size=300 part pv.195 --fstype="lvmpv" --ondisk=sda --size=30419 volgroup centos --pesize=4096 pv.195 logvol / --fstype="xfs" --size=1 --name=root --vgname=centos --grow logvol swap --fstype="swap" --size=2148 --name=swap --vgname=centos logvol /home --fstype="xfs" --size=10340 --name=home --vgname=centos %packages @^minimal @core kexec-tools %end %addon com_redhat_kdump --enable --reserve-mb='auto' %end
Be careful:
1: key --skip: skip the process of entering serial number for red hat system; if it is CentOS series, this content can not be retained;
2: reboot: required item and the location must be set in the document, otherwise, it cannot be restarted automatically after installation;
3: clearpart --all --initlabel: required item, automatically select to clear all data without human intervention.
[root@server ~]# systemctl restart xinetd #Restart tftp service
2.6 Kickstart configuration
[root@server ~]# chmod 755 /var/lib/tftpboot/pxelinux.cfg/default #This file is given modification permission and cannot be modified by default. [root@server ~]# vi /var/lib/tftpboot/pxelinux.cfg/default default linux #Default boot entry timeout 1 #waiting time label linux menu label ^Install CentOS 7 kernel vmlinuz append ks=nfs:172.24.8.12:/centosinstall/ks.cfg initrd=initrd.img quiet [root@server ~]# systemctl restart xinetd #Restart tftp service #timeout 1: #Select a dwell time of 1 second #172.24.8.12: Kickstart server; #/centosinstall: the directory where nfs shares the Linux image, that is, the path where Linux stores the installation files; #ks.cfg: Kickstart auto answer configuration file; #Different services share ks—— HTTP Server ks=http://server_ip:port/path/kickstart_file HTTPS Server ks=https://server_ip:port/path/kickstart_file FTP Server ks=ftp://serverip:port/path/kickstart_file NFS Server ks=nfs:server_ip:/path/kickstart_file
Three client tests
Automatic installation of client after power on
Note: the client needs to be in the same network segment as the server, or can obtain IP and related files from the server.