Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Theory + practice: PXE efficient batch Network installation-- theoretical explanation

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Install the system through the network, how to deploy the configuration

Preface

Deploy PXE remote installation service

Set up PXE remote installation server to verify PXE network installation

Implement unattended installation of Kickstart

In preparation for installation, you should take files to realize batch automatic installation. 1: batch deployment of servers on a large scale: assemble multiple servers at the same time to automate: install the system and configure various services remotely: do not need CD, U disk and other installation media shortcomings: if there are too many bare machines installed at the same time, you need to consider whether the bandwidth is enough, that is, the transmission media.

Second, about the PXE network 2.1 PXE,Pre-boot eXcution Environment pre-boot execution environment, running before the operating system can be used for remote installation, build diskless workstations 2.2 server configuration run DHCP service, used to assign addresses, locate bootstrap programs to run TFTP services, provide bootstrap downloads 2.3 client hardware requirements network card support PXE protocol motherboard support network startup

The bare metal is plugged into the network card and there is no IP address, so the server should first run the DHCP service and assign the address to the client, that is, the server should install the bootstrap first.

The bootstrap program instructs the client to download the relevant installation files from the server

The bootstrap program is placed on the TFTP server, UDP protocol 69 port, fast transmission speed, small text second step

Put the image file on VSFTPD, tcp21 and port 20 step 3

Openstack

Daiwops

Configure PXE installation server 3.1 basic deployment process prepares Centos 7 installation source configuration DHCP service, which is used to assign address, indicate bootstrap location configuration TFTP service, to provide kernel, bootstrap configuration startup menu 3.1.1 TFTP service and boot file installation tftp-server package Enable tftp service preparation kernel file vmlinuz prepare initialization mirror initrd.img prepare bootstrap file pxelinux.0 (bootstrap file pxelinux.0 depends on the syslinux program Need to install syslinux program first) there is also a default configuration file for tftp that needs to be modified / etc/xinetd.d/tftp [root@localhost pxelinux.cfg] # yum install tftp-sever-y 'install tftp service software' [root@localhost pxelinux.cfg] # vim / etc/xinetd.d/tftp 'modify tftp configuration' # default: off# description: The tftp server serves files using the trivial file transfer\ # protocol. The tftp protocol is often used to boot diskless\ # workstations, download configuration files to network-aware printers \ # and to start the installation process for some operating systems.service tftp {socket_type = dgram protocol = udp wait = yes user = root server = / usr/sbin/in.tftpd server_args =-s / var/lib/tftpboot Disable = no 'double negative enable' per_source = 11 cps = 100 2 flags = PXE setting for IPv43.1.2 DHCP service [root@localhost pxelinux.cfg] # yum install dhcp 'install dhcp service' subnet 192.168.100.0 netmask 255.255.255.0 { Range 192.168.100.1 192.168.100.200 Option routers 192.168.100.100; option domain-name-servers 8.8.8.8; next-server 192.168.100.100; 'specify TFTP server address' filename "pxelinux.0" 'specify the bootstrap file to download'} [root@localhost pxelinux.cfg] # systemctl start dhcpd 'enable' [root@localhost pxelinux.cfg] # systemctl enable dhcpd 'self-boot' 3.1.3 default startup menu file [root@localhost ~] # vim / var/lib/tftpboot/pxelinux.cfg/default 'edit default'default auto' default share 'prompt 1' startup time 'label auto Kernel vmlinuz 'kernel' append initrd=initrd.img method= ftp://192.168.100.100/centos7 ks= ftp://192.168.100.100/ks.cfg append process initialization file method to locate kickstart location label linux text 'text mode installation' kernel vmlinuz append text initrd=initrd.img method= ftp://192.168.100 .100 / centos7label linux rescue 'enter Rescue Mode' kernel vmlinuz append rescue initrd=initrd.img method= ftp://192.168.100.100/centos7 4: creating answer files about kickstart4.1 kickstart unattended technology Various installation settings are pre-defined to eliminate the interactive setup process, so as to achieve fully automated installation by adding% post script to complete various configuration operations after installation 4.2 prepare the contents of the answer file answer file root@localhost ~] # vim / var/ftp/ks.cfg#platform=x86, AMD64, or Intel EM64T#version=DEVEL6 # Install OS instead of upgradeinstall# Keyboard layoutskeyboard 'us'# Root passwordrootpw-- iscrypted $1 $6qKSDsgs$eaNnQ18jrgccQjSX95B9Z.# Use network installationurl-- url= "ftp://192.168.100.100/centos7"' Network installation Source" # System languagelang zh_CN# Firewall configurationfirewall-- disabled# System authorization informationauth-- useshadow-- passalgo=sha512# Use graphical installgraphicalfirstboot-- disable# SELinux configurationselinux-- disabled# Network informationnetwork-- bootproto=dhcp-- device=ens33# Reboot after installationreboot# System timezonetimezone Asia/Shanghai# System bootloader configurationbootloader-- location=none# Partition clearing informationclearpart- -all# Disk partitioning informationpart / boot-- fstype= "xfs"-- size=512part / home-- fstype= "xfs"-- size=4096part swap-- fstype= "swap"-- size=4096part /-- fstype= "xfs"-- grow-- size=1%packages' customized package group @ ^ gnome-desktop-environment@base@core@desktop-debugging@dial-up@directory-client@fonts@gnome-desktop@guest-agents@guest-desktop-agents@guest-agents@guest-desktop-agents@input-methods @ internet-browser@java-platform@multimedia@network-file-system-client@networkmanager-submodules@print-client@x11chrony%end4.2 PXE in conjunction with kickstart to deploy the answer file in a location accessible to the client to modify the startup menu file Add call answer file root@localhost ~] # cp / root/ks.cfg / var/ftp/ks.cfg root@localhost ~] # vim / var/lib/tftpboot/pxelinux.cfg/default 'Edit default'default auto' default share 'prompt 0' cancel user time 'label auto kernel vmlinuz' kernel 'append initrd=initrd.img method= ftp://192.168.100.100/centos7 ks= ftp://192.168.100 .100 / ks.cfg append process initialization file method to locate the answer file kickstart location 4.3 PXE+kickstart automatically install 4.3.1 PXE in conjunction with kickstart to modify the startup menu file by deploying the answer file in a location accessible to the client Call answer file experiment: use PXE+kickstart to build a server that automatically installs linux system

Idea: pxe automatic deployment

DHCP

Automatically obtain the IP address for the client and boot to locate the location of the TFTP file

Command:

IP of next-server TFTP

Fliename "pxelinux.0"

TFTP installs the tftp-server package, the first to install syslinux (including pxelinux.0) 'bootstrap

​ 's second compressed kernel vmlinxuz (obtained in the iso image file)

​ 's third initialization file initrd.img (obtained in the iso image file)

​ 's fourth default configuration file default (self-built file: three modes, default is auto, directing the location of FTP image system files)

Vsftpd system Image unattended installation configuration template (ks.cfg)

Five: experimental steps

Add a new network card and set the host mode only. The host network card is used to install the server to connect the bare metal, and the NAT network card is used to download the software package.

[root@localhost named] # ifconfig View Network Card ens33: flags=4163 mtu 1500 inet 192.168.139.131 netmask 255.255.255.0 broadcast 192.168.139.255 'Network Card with Internet access' inet6 fe80::413b:c9ad:e0e:1afc prefixlen 64 scopeid 0x20 ether 00:0c:29:d6:c0:8a txqueuelen 1000 (Ethernet) RX packets 638059 bytes 939850586 (896.3 MiB) RX errors 0 dropped 0 Overruns 0 frame 0 TX packets 157948 bytes 9731567 (9.2 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0ens36: flags=4163 mtu 1500 'newly added network card Need to reconfigure 'inet6 fe80::351b:fad2:2b7c:7ac2 prefixlen 64 scopeid 0x20 ether 00:0c:29:d6:c0:94 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 13 bytes 2334 (2.2KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@localhost named] # cp / etc/sysconfig/network-scripts / ifcfg-ens33 / etc/sysconfig/network-scripts/ifcfg-ens36 'copy and modify the ens33 network card as a template to ens36' [root@localhost named] # vim / etc/sysconfig/network-scripts/ifcfg-ens36' modify configuration 'TYPE= "Ethernet" PROXY_METHOD= "none" no "BOOTPROTO=" static "' network card is set to static 'DEFROUTE=" yes "IPV4_FAILURE_FATAL=" no "IPV6INIT=" yes " IPV6_AUTOCONF= "yes" IPV6_DEFROUTE= "yes" IPV6_FAILURE_FATAL= "no" IPV6_ADDR_GEN_MODE= "stable-privacy" NAME= "ens36" 'name changed to 36 devices = "ens36" ONBOOT= "yes" IPADDR=192.168.100.100' configure IP address' NETMASK=255.255.255.0 'configure subnet mask' GATEWAY=192.168.100.1 'configure gateway' [root@localhost named] # systemctl restart network 'restart network card "[root@localhost named ] # ifconfig 'View' ens33: flags=4163 mtu 1500 inet 192.168.139.131 netmask 255.255.255.0 broadcast 192.168.139.255ens36: flags=4163 mtu 1500 inet 192.168.100.100 netmask 255.255.255.0 'successful'

1.

[root@localhost named] # systemctl stop firewalld.service turn off firewall [root@localhost named] # setenforce 0 'turn off enhancement' [root@localhost named] # rpm-Q dhcp 'check if dhcp is installed' dhcp-4.2.5-77.el7.centos.x86_64 [root@localhost named] # yum install dhcp- y 'use this command' loaded plug-in: fastestmirror LangpacksLoading mirror speeds from cached hostfile * base: mirrors.zju.edu.cn * extras: mirrors.zju.edu.cn * updates: mirrors.zju.edu.cn package 12:dhcp-4.2.5-77.el7.centos.x86_64 is installed and is the latest version without any processing [root@localhost named] # cp/ usr/share/doc/dhcp-4.2.5/dhcpd.conf.example / etc/dhcp/dhcpd.conf 'copy template to / etc/dhcp.dhcpd' [root@localhost named] # vim / etc/dhcp/dhcpd.conf 'Edit' subnet 192.168.100.0 netmask 255.255.255.0 {range 192.168.100.1 192.168.100.200 Option routers 192.168.100.100; option domain-name-servers 8.8.8.8; next-server 192.168.100.100; 'specify TFTP server' filename "pxelinux.0" 'specify the directory of bootstrap files to download'}

two。 Install the tftp service

[root@localhost named] # yum install tftp-server- y 'install TFTPd service' [root@localhost named] # rpm-ql tftp-server 'View all files of the tftp service' / etc/xinetd.d/tftp 'need to configure' / usr/lib/systemd/system/tftp.service/usr/lib/systemd/system/tftp.socket/usr/sbin/in.tftpd/usr/share/doc/tftp-server-5.2/usr/share/doc/tftp-server-5 .2 / CHANGES/usr/share/doc/tftp-server-5.2/README/usr/share/doc/tftp-server-5.2/README.security/usr/share/man/man8/in.tftpd.8.gz/usr/share/man/man8/tftpd.8.gz/var/lib/tftpboot [root@localhost named] # vim / etc/xinetd.d/tftp' Editor / etc/xinetd.d/tftp'14 disable = no 'double negative to enable' [root@localhost named] # vim / var/lib/tftpboot 'tftpboot site' [root@localhost named] # cd / var/lib/tftpboot [root@localhost tftpboot] # ls [root@localhost tftpboot] # [root@localhost tftpboot] # yum install syslinux-y 'install syslinux' [root@localhost tftpboot] # rpm-ql syslinux | grep pxelinux.0/usr/share/syslinux/gpxelinux.0/usr/share/syslinux/pxelinux.0' put pxelinux .0 copy to tftpboot'[root@localhost tftpboot] # [root@localhost tftpboot] # cp / usr/share/syslinux/pxelinux.0 / var/lib/tftpboot/ [root@localhost tftpboot] # ls / var/lib/tftpbootpxelinux.0 [root@localhost tftpboot] # yum install vsftpd-y 'install vsftpd service' [root@localhost tftpboot] # rpm-ql vsftpd | grep pub/var/ftp/pub [root@localhost tftpboot] # mkdir / var/ftp/centos7 'create / var/ftp/ Centos7 directory'[root@localhost tftpboot] # cd / var/ftp [root@localhost ftp] # lscentos7 pub [root@localhost ftp] # lscentos7 / [root@localhost ftp] #

Open the optical drive and use the image file of the corresponding system

[root@localhost ftp] # mount / dev/sr0 / var/ftp/centos7 'Mount the image file to centos7' mount: / dev/sr0 write protection Change the read-only mount [root@localhost ftp] # ls centos7CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL [root@localhost ftp] # cd centos7/images'to the images directory'[root@localhost images] # lsefiboot.img pxeboot TRANS.TBL [root@localhost images] # cd pxeboot 'under the mirror file to the pxeboot directory' [root@localhost pxeboot] # lsinitrd.img TRANS.TBL vmlinuz [root@localhost pxeboot] # cp vmlinuz initrd.img / var/lib/tftpboot' copy the two files to var/lib/tftpboot' [root@localhost pxeboot] # ls / var/lib/tftpboot initrd.img pxelinux.0 vmlinuz [root@localhost pxeboot] # cd / var/lib/tftpboot' to the tfpboot directory'[root@localhost tftpboot] # mkdir pxelinux.cfg 'create pxelinux.cfg directory' [root@localhost Tftpboot] # cd pxelinux.cfg [root@localhost pxelinux.cfg] # vim default 'create a default file under the pxelinux.cfg directory' [root@localhost pxelinux.cfg] # lsdefault [root@localhost pxelinux.cfg] # defalut auto 'defaults to adaptive' prompt 1 'waiting time' label auto 'tag adaptive' kernel vmlinuz 'kernel' append initrd=initrd.img method= ftp://192.168.100.100/centos7 'append initialization process', path method 'label linux text kernel vmlinuz append text initrd=initrd.img method= ftp://192.168.100.100/centos7label linux rescue kernel vmlinuz append rescue initrd=initrd.img method= ftp://192.168.100.100/centos7[root@localhost pxelinux.cfg] # systemctl start dhcpd' Open dhcpd' [root@localhost pxelinux.cfg] # systemctl start vsftpd' Open vsftpd' [root@localhost pxelinux .cfg] # systemctl start tftp' enable tftp'

test

At this point, the network card of the virtual machine tested needs to be in host-only mode.

Enter 4

Boot hit enter.

Auto boot end

3. Unattended installation

[root@localhost ~] # yum install system-config-kickstart-y 'install the system configuration tool kickstart'

[root@localhost ~] # cd / var/ftp 'switch to / var/ftp directory' [root@localhost ftp] # lscentos7 ks.cfg pub [root@localhost ftp] # vim ks.cfg 'modify ks.cfg configuration file' # platform=x86, AMD64 Or Intel EM64T#version=DEVEL# Install OS instead of upgradeinstall# Keyboard layoutskeyboard 'us'# Root passwordrootpw-iscrypted $1 $6qKSDsgs$eaNnQ18jrgccQjSX95B9Z.# Use network installationurl-- url= "ftp://192.168.100.100/centos7"# System languagelang zh_CN# Firewall configurationfirewall-- disabled# System authorization informationauth-- useshadow-- passalgo=sha512# Use graphical installgraphicalfirstboot-- disable# SELinux configurationselinux-- disabled# Network informationnetwork-- bootproto=dhcp-- device=ens33# Reboot after installationreboot# System timezonetimezone Asia/Shanghai# System bootloader configurationbootloader-- location=none# Partition clearing informationclearpart-- all# Disk partitioning informationpart / boot-- fstype= "xfs"-- size=512part / home-- fstype= "xfs"-- size=4096part swap-- fstype= "swap"-- size=4096part /-- fstype= "xfs"-- grow-- size=1 [root@localhost ftp] # cd ~ 'switch to root's Home Directory' [root@localhost ~] # lsanaconda-ks.cfg Public Video document Music initial-setup-ks.cfg template Picture download Desktop [root @ localhost ~] # vim anaconda-ks.cfg 'put' # version=DEVEL# System authorization informationauth-enableshadow-passalgo=sha512# Use CDROM installation mediacdrom# Use graphical installgraphical# Run the Setup Agent on first bootfirstboot-enableignoredisk-only-use=sda# Keyboard layoutskeyboard-vckeymap=cn-xlayouts='cn'# System languagelang zh_CN.UTF-8# Network informationnetwork-bootproto=dhcp-device=ens33-ipv6=auto-activatenetwork-hostname=localhost.localdomain# Root passwordrootpw-iscrypted $6$ lZy/ZqchdBxv/dZ0 $RUyTDADN9e2H0hJlb9J757GyZ0nxWhPKY1sDdyCtvBR2 in the anaconda.ks.cfg file / Asw/CPCAFFIfJB.kO7qbicMQx1LeoP53Xq/YXJeC0# System servicesservices-enabled= "chronyd" # System timezonetimezone Asia/Shanghai-isUtcuser-name=gsy-password=$6 $4r65p5GBvUZhGlnz$Cs.RsqZdbDij5eQeIxWRi3f4VERzZFsp1TSkgaURI3d0Beafr8TT//iBETmpgEsW//yoHoqfvL9k2BwmGQlx51-iscrypted-gecos= "gsy" # X Window System configuration informationxconfig-startxonboot# System bootloader configurationbootloader-location=mbr-boot-drive=sdaautopart-type=lvmbootloader-location=mbr-boot-drive=sdaautopart-type=lvm# Partition clearing informationclearpart-none-initlabel%packages@ ^ gnome-desktop-environment@base@core@desktop-debugging@dial-up@directory-client@ Fonts@gnome-desktop@guest-agents@guest-desktop-agents@input-methods@internet-browser@java-platform@multimedia@network-file-system-client@networkmanager-submodules@print-client@x11chrony%end%addon com_redhat_kdump-- disable-- reserve-mb='auto'%end%anacondapwpolicy root-- minlen=6-- minquality=1-- notstrict-- notemptypwpolicy user-- minlen=6-- minquality=1-- notstrict-- nochanges-- emptyokpwpolicy luks-- minlen=6-- minquality=1-- notstrict-- nochanges-- notempty% End~ [root@localhost] # vim / var/ftp/ks.cfg%packages@ ^ gnome-desktop-environment@base@core@desktop-debugging@dial-up@directory-client@fonts@gnome-desktop@guest-agents@guest-desktop-agents@input-methods@internet-browser@java-platform@multimedia@network-file-system-client@networkmanager-submodules@print-client@x11chrony%end [root@localhost ~] # cd / var/lib/tftpboot/ [root@localhost tftpboot] # lsinitrd.img pxelinux. 0 pxelinux.cfg vmlinuz [root@localhost tftpboot] # cd pxelinux.cfg [root@localhost pxelinux.cfg] # lsdefault [root@localhost pxelinux.cfg] # vim defaultlabel auto kernel vmlinuz append initrd=initrd.img method= ftp://192.168.100.100/centos7 ks= ftp://192.168.100.100/ks.cfg[root@localhost pxelinux.cfg] # systemctl restart dhcpd [root@localhost pxelinux.cfg] # systemctl restart tftp [root@localhost pxelinux.cfg] # systemctl restart vsftpd

Verify again

Select the fourth one and enter

Six: summary: PXE+kickstart batch network installation of the building server 1. First, turn off the firewall with two commands: systemctl stop firewalld.servicesetenforce 02. Configure dual network card 3. Run the DHCP service (port number: assign an address to the client and boot the installation file) add two commands: subnet 192.168.100.0 netmask 255.255.255.0 {range 192.168.100.1 192.168.100.200; option routers 192.168.100.100; 'point the gateway to yourself when configuring the local area network installation service' option domain-name-servers 8.8.8; next-server 192.168.100.100 'specify FTP server 'filename "pxelinux.0" 'specify the directory of bootstrap files to download'} 4. Run the vsftpd service (tcp21 and port 20, store image files) to install the vsftpd package, and create a new centos7 directory in its data file / var/ftp/ directory. This new directory is the image package, which can be mounted, or you can directly copy the whole package to it. Run the tftpd service (udp port number 69, bootstrap on TFTPd) to install the tftp-server package, configure the kernel file vmlinuz, initialize the mirror initrd.img, program boot file pxelinux.0 (pxelinux.0 depends on syslinux software), pxelinux.cfg directory

Configure the profile / etc/xinetd.d/tftp for the tftpd service

Change disable to no to 'open' the / var/lib/tftpboot site data directory for configuring tftpd: contains initrd.img, vmlinuz, pxelinux.0, pxelinux.cfg directories,

Initrd.img and vmlinuz files are derived from the image file: copy the two initrd.img and vmlinuz files under the images/pxeboot/ directory under the image file to the / var/lib/tftpboot directory

Pxelinux.0 file: you need to install the syslinux software first, and copy the pxelinux.0 file directly to the var/lib/tftpboot/ directory in its / usr/share/syslinux directory

The pxelinux.cfg directory is the newly created directory, and then create a new default file under the var/lib/tftpboot/pxelinux.cfg/ directory

​ pxelinux.cfg/default File configuration

Default auto 'default sharing' prompt 1 'startup time' label auto kernel vmlinuz 'kernel' append initrd=initrd.img method= ftp://192.168.100.100/centos7 ks= ftp://192.168.100.100/ks.cfg append process initialization file method location kickstart location label linux text 'text mode security Load 'kernel vmlinuz append text initrd=initrd.img method= ftp://192.168.100.100/centos7label linux rescue' into rescue mode 'kernel vmlinuz append rescue initrd=initrd.img method= ftp://192.168.100.100/centos7'

Then turn on all the services

Systemctl start dhcpd' open dhcpd'systemctl start vsftpd' open vsftpd'systemctl start tftp' open tftp'6. Configure KICKstart

Install the system-config-kickstart system configuration kickstart software first

Then configure the interface graphically.

Installation method FTP server ftp://192.168.100.100/

Directory centos7

Boot loader is selected to open

Partition setting, / boot512M / home 4096m swap 4096m / give him all the rest

Add network card ens33

Disable the firewall

Post-installation scripts use the interpreter / bin/bash

Then save it in the / var/ftp/ directory of the vsftpd service

The script can pac the data in ~ / anaconda.cfg

Kages to% end copy to / var/ftp/ks.cfg

Just restart again at this time.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report