PXE+Kickstart+HTTP unattended batch installation of Centos6.9 system steps are fully explained

PXE+Kickstart+HTTP unattended batch installation of Centos6.9 system steps are fully explained

0. Principle

0.1 PXE

  • Name: Pre-boot Execution Environment, pre-boot execution environment
  • Working environment: Client/Server network mode
  • Work content: a boot method, PXE protocol can make the computer start through the network. It is used to support the downloading of the system image from the server through the network, and to start the operating system through the network. To run the PXE protocol, you need to set up a DHCP server and a tftp server.
  • The DHCP server will assign an IP address to the PXE Client (the host where the system will be installed), and the corresponding PXE settings need to be added when configuring the DHCP server.
  • PXE Client can download required files to TFTP Server through TFTP protocol.

0.2 PXE working process

Insert picture description here

0.3 Kickstart

  • Definition: an unattended installation method;

  • Working principle: Record some of the various parameters (partition settings/network settings, etc.) that require manual intervention during the installation process, and generate a file named ks.cfg;

  • If there are parameters to be filled in during the installation process, the installation program will first look for the files generated by Kickstart. If suitable parameters are found, the found parameters will be used (if there are no suitable parameters, manual intervention is required);

  • After installing the system, the installation program will restart the system according to the settings in ks.cfg and end the installation

    ​ If we compare the system image file to ingredients and the installed system as a table of dishes, the ks.cfg file is the recipe for making a table of good dishes

    ​ The names of the dishes are: language environment/keyboard settings/network configuration/partition settings/user password settings/installation package settings/grub startup settings/etc;

    ​ So when can the host of the system to be installed run the commands in this file? Of course, after the system enters the init.d initialization and the network card has been configured with a number, it can only run after the installation system has successfully loaded the ks.cfg file from the mirror source location.

1. PXE+Kickstart to achieve unattended installation of Centos6 steps

1.1 Experiment preparation and software installation

Requirements: completed in Centos6

Experiment preparation: two hosts, one centos6.9 (complete static configuration ip address), and one client without system

Experimental environment: VMware Workstation 15

Network mode: NAT

Network card eth0 IP: 192.168.6.146/24

Regarding how to statically configure the centos7 ip address, refer to previous articles: Centos7/Ubuntu1604 network static configuration IP address process

  1. Turn off the firewall and selinux
[root@lin ~]# iptables -F  
#还没有学过防火墙服务的,简单粗执行这个命令就行了
#系统若有重启再关掉,以免待安装主机TFTP请求不成功加载不了镜像文件
[root@lin ~]# setenforce 0 
#可以永久性修改:/etc/sysconfig/selinux 中修改成这个字段:SELINUX=disabled 
  1. Install the software required for the experiment, the result is shown in the figure
[root@lin ~]# yum install httpd tftp-server dhcp syslinux system-config-kickstart -y

httpd 					
#为安装操作系统过程提供光盘文件,(其实:也可也以选择ftp服务来传输)
tftp-server 			
#存放应答文件和pxelinux.0文件
syslinux 				
#提供pxelinux.0等文件
dhcp 					
#为客户机分配ip地址
system-config-kickstart 
#用来制作ks文件即菜谱,前提是:需要图形化界面启动,后面会教你安装图形化界面环境和工具

Insert picture description here

  1. Set the installed service to start automatically at boot and start the service
[root@lin ~]# chkconfig dhcpd on  #设定在各个等级(2,3,4,5)为on,系统重启就不用操心这个服务
[root@lin ~]# service xinetd start
Starting xinetd:                                          [  OK  ]
  1. Need to install x windows and desktop , and restart

    The system-confgi-kickstart tool is required to generate the ks.cfg file, and this tool depends on X windows

    ( Remember to turn off the firewall and SElinux again ):

[root@lin ~]# yum groupinstall "Desktop" "X Window System"
[root@lin ~]# yum groupinstall Fonts
[root@lin ~]# reboot
  1. **Start service HTTP+**Auto start setting
[root@lin ~]# /etc/init.d/httpd start
Starting httpd: 
[root@lin ~]# chkconfig --level 35 httpd on
#--level 35表示操作只在等级3和5执行,on表示启动
  1. Load the ISO image and mount

    • Set to load ISO image in the virtual machine (like a CD)

      In addition to downloading the mirror image, it can be installed on a CD or by a network. Use the wget command to download the mirror source to the local. This method finds it by itself

Insert picture description here

  • Mount the iso file to /mnt/cdrom
[root@lin ~]# mkdir /mnt/cdrom
[root@lin ~]# mount /dev/cdrom /mnt/cdrom
mount: block device /dev/sr0 is write-protected, mounting read-only
  1. Copy the contents of the CD to the root directory of http

    [root@lin ~]# cp -r /mnt/cdrom /var/www/html/
    

1.2 TFTP service configuration

  1. Enable tftp service tftp-server
[root@lin ~]# vi /etc/xinetd.d/tftp 
service tftp
{
        disable = no   #修改这里
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /var/lib/tftpboot
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}

The tftp service is mounted under the super process xinetd, and the tftp service is started by starting xinetd, and it is set to start automatically after booting.

[root@lin ~]# /etc/init.d/xinetd restart
Stopping xinetd:                                        [  OK  ]
Starting xinetd:                                        [  OK  ]
[root@lin ~]# chkconfig xinetd on

1.3 Copy image file + system startup configuration file modification

  1. Copy the pxelinux.0 file to the /var/lib/tftpboot folder
[root@lin ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/

syslinux is the boot loader. The small linux operating system simplifies the time to install linux for the first time, and establishes and maintains other special-purpose boot disks.

  1. Copy the initrd.img and vmlinuz in the /image/pxeboot/ directory in the iso image to the /var/lib/tftpboot folder
[root@lin ~]# cp /var/www/html/cdrom/images/pxeboot/{initrd.img,vmlinuz} /var/lib/tftpboot/
  1. Copy **/isolinux/*.msg** in the iso image to the /var/lib/tftpboot directory
[root@lin ~]# cp /var/www/html/cdrom/isolinux/*.msg /var/lib/tftpboot/
  1. Create a new pxelinux.cfg directory in /var/lib/tftpboot/, copy isolinux.cfg in the /isolinux directory in the iso image to the pxelinux.cfg directory, and change the file name to default
[root@lin ~]# mkdir /var/lib/tftpboot/pxelinux.cfg

[root@lin ~]# cp /var/www/html/cdrom/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
  1. Modify the default file
[root@lin ~]# vim /var/lib/tftpboot/pxelinux.cfg/default 
default ks  
prompt 1    #显示:boot:提示符 
timeout 600 #用户输入前的超时时间,单位为毫秒
display boot.msg  #默认在/var/lib/tftpboot目录下显示某个文件内容
label linux
  kernel vmlinuz  #kernel 参数指定要启动的内核
  append initrd=initrd.img #追加给内核的参数
label ks
  kernel vmlinuz  
  append ks=http://192.168.6.146/ks.cfg initrd=initrd.img  #镜像源的ip地址,注意是http没有s
#指明获取ks.cfg文件的位置

1.4 DHCP service configuration

  1. Copy the configuration template to the DHCP configuration directory
[root@lin ~]# cp -f /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample  /etc/dhcp/dhcpd.conf
  1. Modify the **/etc/dhcp/dhcpd.conf** configuration file
ddns-update-style interim;
ignore client-updates;
filename "pxelinux.0";
next-server 192.168.6.146;

subnet 192.168.6.0 netmask 255.255.255.0 {
    
    
  option routers 192.168.6.2;   	#网关ip地址
  option subnet-mask 255.255.255.0; #掩码
 
  range dynamic-bootp 192.168.6.200 192.168.6.250#设定分配ip 地址的范围
  default-lease-time 21600;
  max-lease-time 43200;
} 
#除此以外其他内容可以删掉
  1. Start the dhcp service
[root@lin ~]# /etc/init.d/dhcpd start
Starting dhcpd:                                         [  OK  ]
#启动失败的话根据提示
#查看日志文件,需要查看是否格式写对,是否写漏分号
#查看启动状态 service dhcpd status

1.5 Kickstart configuration file generation

  1. Start the X Windows environment

    [root@lin ~]# startx
    
  2. Execute system-config-kickstart on the terminal

​ A. Set language, keyboard, time zone, Root password, restart after installation, etc.
Insert picture description here

B. Set the installation method, this article introduces HTTP installation, select HTTP
Insert picture description here
C. Install MBR
Insert picture description here

D. Partition settings

Insert picture description here

Insert picture description here

E. Configure the network
Insert picture description here

F. Authentication configuration
Insert picture description here

G. SElinux and firewall configuration
Insert picture description here
H. Graphical environment configuration
Insert picture description here

I. Package installation options (minimize)
Insert picture description here

J.ks file setting preview
Insert picture description here
K. Generate ks.cfg file, save the file under the /var/www/html folder
Insert picture description here

In fact, the ks file can also be manually edited and generated by yourself, and the relevant information can be searched by yourself, as long as it meets the specifications and no Chinese can appear in any place in the document, and it can be saved to the location specified in the above figure.

1.6 Unattended installation of client system

A. Create a virtual machine

Insert picture description here

B. Network configuration, select "Connect at startup", NAT mode

Insert picture description here
Insert picture description here

C. Start the virtual machine , the network card starts, the DHCP server has assigned an IP address to the client, and is requesting TFTP service
Insert picture description here

D. Press Enter to start the system installation
Insert picture description here

E. Installation is complete

Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_31789689/article/details/108143747