PXE network installation (small amount)

1. PXE basic installation environment
  • Step 1: Publish the CentOS7 software source via HTTP. In
    this link, you can directly use the YUM software source that is shared on the network, such as the real CentOS machine.
    1) Quickly build httpd server
[ root@pxe~] # yum - y install httpd   //装包
[ root@pxe ~] # systemctl restart  httpd  //启动服务
[ root@pxe ~] # systemctl enable httpd  //设置开机自启

2) Prepare yum warehouse and deploy to Web subdirectory

[ root@pxe ~] # mkdir /var/www/html/ dvd   //建挂载点
[ root@pxe ~] # vim /etc/ fstab
.. ..
/ISO/ CentOS -1804.iso /var/www/html/ dvd iso9660 loop , ro 0
[ root@pxe ~] # mount -a   //挂载ISO镜像文件
[ root@pxe ~] # ls
/var/www/html/dvd/   //确认部署位置
  • Step 2: Make sure that the HTTP resources of the yum warehouse are available
    . Visit http://192.168.4.254/dvd/ from the browser to see the warehouse resources.
2. Configure and verify the DHCP service

Step 1: Configure the DHCP server
1) Install the dhcp software package

[ root@r7 ~] # yum  -y   install   dhcp

2) Establish dhcpd.conf service configuration

[ root@r7 ~] # vim /etc/dhcp/ dhcpd . conf
subnet 192.168.4.0 netmask 255.255.255.0 {
    
    
range 192.168.4.10 192.168.4.200;
next - server 192.168.4.7;
filename "pxelinux.0";
}

3) Start the system service dhcpd and set it to start automatically

[ root@r7 ~] # systemctl  restart dhcpd
[ root@r7 ~] # systemctl  enable dhcpd

4) Confirm dhcpd service status

[ root@r7 ~] # netstat -anptu |  grep  dhcp
udp  0  0 0.0.0.0:67     0.0.0.0:*
864/ dhcpd
  • Step 2: Test the DHCP service on the client
    1) Use the dhclient command to test and observe the process of obtaining an IP address
[ root@r207 ~] # dhclient  -d  eth0
Internet Systems Consortium DHCP Client 4.2.5
Copyright 2004-2013 Internet Systems Consortium .
All rights reserved .
For info , please visit https://www.isc.org/software/dhcp/
.. ..
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 7
( xid =0x6707682f)
DHCPREQUEST on eth0 to 255.255.255.255 port 67 ( xid =0x6707682f)
DHCPOFFER from 192.168.4.7
DHCPACK from 192.168.4.7 ( xid =0x6707682f)
bound to 192.168.4.10 -- renewal in 18643 seconds .
^ C    //按Ctrl+c键退出测试

2) If the IP fails due to abnormal operation, the original IP configuration of the client can be restored

[ root@r207 ~] # pkill  -9  dhclient  //杀死dhclient进程
[ root@r207 ~] # nmcli  connection  up  eth0  //激活原配置
.. .. 
3. Configure PXE boot
  • Step 1: Quickly build a TFTP server
    1) Install the tftp-server software package
[ root@r7 ~] # yum - y install tftp-server

2) Start the system service tftp, and set the boot to start automatically

[ root@r7 ~] # systemctl restart tftp
[ root@r7 ~] # systemctl enable tftp
Created symlink from
/etc/systemd/system/ sockets.target.wants/tftp.socket to /usr/lib/systemd/system/ tftp.socket.
  • Step 2: Deploy the startup file
    1) Copy the pxelinux.0 program and deploy to the TFTP directory
    Find the pxelinux.0 program in the directory provided by the software package syslinux
[ root@r7 ~] # yum - y install syslinux
[ root@r7 ~] # rpm - ql syslinux | grep pxelinux.0
/usr/share/syslinux/ gpxelinux .0
/usr/share/syslinux/ pxelinux .0
[ root@r7 ~] # cp /usr/share/syslinux/ pxelinux.0 /var/lib/tftpboot/
[ root@r7 ~] # ls /var/lib/tftpboot/
pxelinux .0

2) Copy the kernel and initial image of the boot installation and deploy to the TFTP directory

[ root@r7 ~] # mkdir /var/lib/tftpboot/ CentOS7
[ root@r7 ~] # cd /var/lib/tftpboot/CentOS7/
[ root@r7 CentOS7 ] # wget http://192.168.4.254/dvd/isolinux/vmlinuz
[ root@r7 CentOS7 ] # wget http://192.168.4.254/dvd/isolinux/initrd.img  //下载内核、初始化文件
[ root@svr7 pxeboot ] # ls -R  /var/lib/tftpboot/
/var/lib/tftpboot/:
pxelinux .0 CentOS7
/var/lib/tftpboot/ CentOS7 :
initrd . img vmlinuz
  • Step 3: Configure the boot menu
    1) Create a configuration directory
[ root@r7 ~] # mkdir  /var/lib/tftpboot/ pxelinux.cfg

2) Using the isolinux directory in the CD as a template, copy the necessary files

[ root@r7 ~] # cd  /var/lib/tftpboot/
[ root@r7 tftpboot ] # wget  http://192.168.4.254/dvd/isolinux/vesamenu.c32 //提供图形支持
[ root@r7 tftpboot ] # wget http://192.168.4.254/dvd/isolinux/splash.png //准备背景图片
[ root@r7 tftpboot ] # wget - O pxelinux .cfg/default  http://192.168.4.254/dvd/isolinux/isolinux.cfg     //建立菜单配置
[ root@r7 isolinux ] # ls -R  /var/lib/tftpboot/   //确认部署结果
/var/lib/tftpboot/:
pxelinux.0  pxelinux.cfg  CentOS7   splash.png   vesamenu.c32
/var/lib/tftpboot/pxelinux.cfg :
default
/var/lib/tftpboot/CentOS7 :
initrd.img vmlinuz

3) Adjust the startup parameters when
entering vim mode, you can set the line number (set nu)

[ root@svr7 ~] # vim  /var/lib/tftpboot/ pxelinux.cfg/default
default vesamenu.c32   //默认交给图形模块处理
timeout 600                       //选择限时为60秒(单位1/10秒)
.. ..
menu title PXE   Installation        Server         //启动菜单标题信息
.. ..
label  linux                 //菜单项标签
	menu label ^ Install CentOS7 Linux 7

 kernel CentOS7/vmlinuz      //内核的位置
append initrd =CentOS7/ initrd.img
inst.stage2 = http://192.168.4.254/dvd      //初始镜像、安装源位置

label rescue
	menu label ^ CentOS7 system
	kernel CentOS7/ vmlinuz
	append initrd =CentOS7/initrd.img
inst . stage2 = http://192.168.4.254/dvd rescue

label local               //从硬盘启动
menu    default        //默认启动方式
menu label Boot from ^ local drive
localboot 0xffff
menu     end
  • Step 4: Access the TFTP server to make sure it is available
    1) Install the tftp command tool on pc207
[ root@pc207 ~] # yum -y install  tftp

2) Access the TFTP server on svr7 on pc207, download the file to test

[ root@pc207 ~] # tftp 192.168.4.7 -c   get pxelinux .0
[ root@pc207 ~] # ls -lh   pxelinux .0   //检查下载结果
-rw-r--r-- 1 root root 27k 2月  23 18:27 pxelinux.0
4. Verify PXE network installation
  • Step 1: Create a new virtual machine pxetest
    Create a new virtual machine, pay attention to select the installation method "Network Boot (PXE)" (as shown in Figure-2).
    Refer to other settings of the virtual machine: memory 2G, hard disk 20G; the network type should be the same as that of the PXE server, for example, use
    private1 to isolate the network. (Using vm)
    figure 2

Note: If it is a client computer that already has a system in the production environment, you need to adjust the BIOS settings and use the network boot
as the first boot device.

  • Step 2: Start the virtual machine pxetest, verify the PXE network installation process
    1) Confirm the startup interface After the
    client is booted through PXE, the configuration interface provided by the server can be obtained (as shown in Figure-3).
    Insert picture description here
    2) Select the first menu item to start installing the CentOS7 operating system
    . The welcome interface of the CentOS7 installation program appears successfully. Follow the prompts to select Chinese (as shown in Figure-4) and continue.
    Insert picture description here
    3) In the next step, you need to manually select the installation source.
    Specify the software warehouse located at http://192.168.4.254/dvd. The software selection, installation location and other settings
    are specified as needed, and then continue after confirmation.
    The follow-up process is similar to the normal CD installation, so I won't repeat it.
    The smooth operation here shows that the goal of PXE network boot installation has been achieved.

Guess you like

Origin blog.csdn.net/weixin_45942735/article/details/104467967
Recommended