通过PXE服务器批量安装系统
生活随笔
收集整理的這篇文章主要介紹了
通过PXE服务器批量安装系统
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
通過PXE服務(wù)器批量安裝系統(tǒng)
- 一、環(huán)境介紹
- 1.PXE服務(wù)器版本
- 2.掛載光盤
- 3.配置yum倉庫
- 二、部署DHCP服務(wù)器
- 1.安裝相關(guān)軟件包
- 2.編輯DHCP配置文件
- 3.重啟dhcp服務(wù)
- 4.放行防火墻端口
- 5.關(guān)閉selinux
- 三、部署TFTP服務(wù)器
- 1.安裝相關(guān)包
- 2.修改TFTP服務(wù)配置文件
- 3.重啟服務(wù)
- 4.放行防火墻
- 5.檢查相關(guān)服務(wù)運行端口
- 四 、在 dhcp 配置文件中加入 tftp 服務(wù)相關(guān)參數(shù)
- 五、配置tftp下服務(wù)文件
- 1.安裝 syslinux軟件包
- 2.將 pxelinux.0 復制到/var/lib/tftpboot
- 3.將光盤 isolinux 目錄所有內(nèi)容,拷貝到/var/lib/tftpboot 中
- 4.創(chuàng)建/var/lib/tftpboot/pxelinux.cfg目錄
- 5.將 isolinux.cfg 文件拷貝并改名為 default
- 六、編輯 pxe 網(wǎng)絡(luò)安裝啟動菜單條
- 1.創(chuàng)建安裝系統(tǒng)對應(yīng)目錄
- 2.掛載安裝所需系統(tǒng)的RHEL8.0光盤
- 3.拷貝相關(guān)系統(tǒng)啟動文件到/var/lib/tftpboot/rhel8.0/下
- 4.修改開機啟動菜單
- 5.客戶端開機pxe引導測試
- 七、安裝httpd服務(wù)
- 1.安裝httpd軟件包
- 2.創(chuàng)建/pub、/ks 目錄
- 3.設(shè)置httpd服務(wù)開機自啟
- 八、配置ks腳本
- 1.將光盤自動掛載到/var/www/html/pub
- 2.將 ks 文件移動到共享目錄
- 3.編輯ks腳本
- 4.修改ks.cfg權(quán)限
- 九、重啟所有相關(guān)服務(wù)
- 十、測試PXE安裝系統(tǒng)
一、環(huán)境介紹
1.PXE服務(wù)器版本
[root@PXE ~]# cat /etc/redhat-release CentOS Linux release 8.2.2004 (Core)2.掛載光盤
[root@PXE ~]# mount /dev/cdrom /mnt/cdrom/ mount: /mnt/cdrom: WARNING: device write-protected, mounted read-only. [root@PXE ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 12M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/mapper/cl-root 17G 5.0G 13G 30% / /dev/sda1 976M 193M 717M 22% /boot tmpfs 376M 4.6M 371M 2% /run/user/0 tmpfs 376M 4.0K 376M 1% /run/user/1000 tmpfs 376M 1.2M 375M 1% /run/user/42 /dev/sr0 7.7G 7.7G 0 100% /mnt/cdrom3.配置yum倉庫
[development] name=rhel8 baseurl=file:///mnt/cdrom/BaseOS baseurl=file://mnt/cdrom/AppStream enabled=1 gpgcheck=0 [root@PXE yum.repos.d]# yum clean all 0 files removed [root@PXE yum.repos.d]# yum makecache rhel8 170 MB/s | 5.7 MB 00:00 Last metadata expiration check: 0:00:01 ago on Tue 10 Aug 2021 08:12:33 PM CST. Metadata cache created.二、部署DHCP服務(wù)器
1.安裝相關(guān)軟件包
[root@PXE yum.repos.d]# yum -y install dhcp-server.x86_64 tftp-server.x86_64 Last metadata expiration check: 0:02:19 ago on Tue 10 Aug 2021 08:23:28 PM CST. Dependencies resolved.2.編輯DHCP配置文件
[root@PXE dhcp]# cp /usr/share/doc/dhcp-server/dhcpd.conf.example /etc/dhcp/dhcpd.conf cp: overwrite '/etc/dhcp/dhcpd.conf'? yes [root@PXE dhcp]#vim /etc/dhcp/dhcpd.conf# A slightly different configuration for an internal subnet. subnet 192.168.3.0 netmask 255.255.255.0 {range 192.168.3.100 192.168.3.200;option domain-name-servers 192.168.3.1, 192.168.3.201;option domain-name "example.com";option routers 192.168.3.1;option broadcast-address 192.168.3.255;default-lease-time 600;max-lease-time 7200;3.重啟dhcp服務(wù)
[root@PXE dhcp]# systemctl status dhcpd ● dhcpd.service - DHCPv4 Server DaemonLoaded: loaded (/usr/lib/systemd/system/dhcpd.service; enabled; vendor preset: disabled)Active: active (running) since Tue 2021-08-10 20:53:18 CST; 9s agoDocs: man:dhcpd(8)man:dhcpd.conf(5)Main PID: 35901 (dhcpd)Status: "Dispatching packets..."Tasks: 1 (limit: 23644)Memory: 5.5MCGroup: /system.slice/dhcpd.service└─35901 /usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --n>Aug 10 20:53:18 PXE dhcpd[35901]: ** Ignoring requests on virbr0. If this is not what Aug 10 20:53:18 PXE dhcpd[35901]: you want, please write a subnet declaration Aug 10 20:53:18 PXE dhcpd[35901]: in your dhcpd.conf file for the network segment Aug 10 20:53:18 PXE dhcpd[35901]: to which interface virbr0 is attached. ** Aug 10 20:53:18 PXE dhcpd[35901]: Aug 10 20:53:18 PXE dhcpd[35901]: Listening on LPF/ens33/00:0c:29:cd:cd:e1/192.168.3.0/24 Aug 10 20:53:18 PXE dhcpd[35901]: Sending on LPF/ens33/00:0c:29:cd:cd:e1/192.168.3.0/24 Aug 10 20:53:18 PXE dhcpd[35901]: Sending on Socket/fallback/fallback-net Aug 10 20:53:18 PXE dhcpd[35901]: Server starting service. Aug 10 20:53:18 PXE systemd[1]: Started DHCPv4 Server Daemon.4.放行防火墻端口
[root@PXE dhcp]# firewall-cmd --permanent --add-port=67/udp success [root@PXE dhcp]# firewall-cmd --reload success [root@PXE dhcp]# firewall-cmd --list-ports 67/udp5.關(guān)閉selinux
[root@PXE ~]# setenforce 0 [root@PXE ~]# getenforce Permissive三、部署TFTP服務(wù)器
1.安裝相關(guān)包
[root@PXE ~]# yum -y install tftp-server.x86_64 [root@PXE ~]# yum -y install xinetd.x86_64 Last metadata expiration check: 0:38:36 ago on Tue 10 Aug 2021 08:30:02 PM CST. Dependencies resolved. ============================================================================================Package Architecture Version Repository Size ============================================================================================ Installing:xinetd x86_64 2:2.3.15-24.el8 development 135 kTransaction Summary ============================================================================================ Install 1 PackageTotal size: 135 k Installed size: 379 k Downloading Packages: Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transactionPreparing : 1/1 Installing : xinetd-2:2.3.15-24.el8.x86_64 1/1 Running scriptlet: xinetd-2:2.3.15-24.el8.x86_64 1/1 Verifying : xinetd-2:2.3.15-24.el8.x86_64 1/1 Installed products updated.Installed:xinetd-2:2.3.15-24.el8.x86_64 Complete!2.修改TFTP服務(wù)配置文件
[root@PXE ~]# vim /etc/xinetd.d/tftpservice tftp {socket_type = dgramprotocol = udpwait = yesuser = rootserver = /usr/sbin/in.tftpdserver_args = -s /var/lib/tftpbootdisable = noper_source = 11cps = 100 2flags = IPv4 }3.重啟服務(wù)
[root@PXE ~]# systemctl enable --now xinetd [root@PXE ~]# systemctl restart xinetd [root@PXE ~]# systemctl enable dhcpd [root@PXE ~]# systemctl restart dhcpd4.放行防火墻
[root@PXE ~]# firewall-cmd --permanent --add-port=69/udp success [root@PXE ~]# firewall-cmd --reload success5.檢查相關(guān)服務(wù)運行端口
[root@PXE ~]# netstat -tunlp |grep 69 udp 0 0 0.0.0.0:69 0.0.0.0:* 38484/xinetd [root@PXE ~]# netstat -tunlp |grep 67 udp 0 0 0.0.0.0:67 0.0.0.0:* 37672/dhcpd udp 0 0 0.0.0.0:67 0.0.0.0:* 1492/dnsmasq [root@PXE ~]#四 、在 dhcp 配置文件中加入 tftp 服務(wù)相關(guān)參數(shù)
[root@PXE ~]# vim /etc/dhcp/dhcpd.conf # option definitions common to all supported networks... option domain-name "example.org"; option domain-name-servers ns1.example.org, ns2.example.org;next-server 192.168.3.150; filename "pxelinux.0"default-lease-time 600; max-lease-time 7200;五、配置tftp下服務(wù)文件
1.安裝 syslinux軟件包
[root@PXE ~]# yum -y install syslinux Last metadata expiration check: 1:42:48 ago on Tue 10 Aug 2021 08:30:02 PM CST. Dependencies resolved. ============================================================================================Package Architecture Version Repository Size ============================================================================================2.將 pxelinux.0 復制到/var/lib/tftpboot
[root@PXE ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ [root@PXE ~]#3.將光盤 isolinux 目錄所有內(nèi)容,拷貝到/var/lib/tftpboot 中
[root@PXE ~]# cp -r /mnt/cdrom/isolinux/* /var/lib/tftpboot/4.創(chuàng)建/var/lib/tftpboot/pxelinux.cfg目錄
[root@PXE ~]# mkdir /var/lib/tftpboot/pxelinux.cfg [root@PXE ~]#5.將 isolinux.cfg 文件拷貝并改名為 default
[root@PXE ~]# cp /var/lib/tftpboot/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default [root@PXE ~]#六、編輯 pxe 網(wǎng)絡(luò)安裝啟動菜單條
1.創(chuàng)建安裝系統(tǒng)對應(yīng)目錄
[root@PXE tftpboot]# ls boot.cat initrd.img ldlinux.c32 memtest splash.png vmlinuz boot.msg isolinux.bin libcom32.c32 pxelinux.0 TRANS.TBL grub.conf isolinux.cfg libutil.c32 pxelinux.cfg vesamenu.c32 [root@PXE tftpboot]# mkdir ./rhel8.0 [root@PXE tftpboot]# ls boot.cat initrd.img ldlinux.c32 memtest rhel8.0 vesamenu.c32 boot.msg isolinux.bin libcom32.c32 pxelinux.0 splash.png vmlinuz grub.conf isolinux.cfg libutil.c32 pxelinux.cfg TRANS.TBL2.掛載安裝所需系統(tǒng)的RHEL8.0光盤
[root@PXE tftpboot]# mount /dev/cdrom /mnt/cdrom/ mount: /mnt/cdrom: WARNING: device write-protected, mounted read-only. [root@PXE tftpboot]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 10M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/mapper/cl-root 17G 5.1G 12G 30% / /dev/sda1 976M 193M 717M 22% /boot tmpfs 376M 1.2M 375M 1% /run/user/42 tmpfs 376M 4.6M 371M 2% /run/user/0 /dev/sr0 6.7G 6.7G 0 100% /mnt/cdrom3.拷貝相關(guān)系統(tǒng)啟動文件到/var/lib/tftpboot/rhel8.0/下
[root@PXE pxeboot]# pwd /mnt/cdrom/images/pxeboot [root@PXE pxeboot]# ls initrd.img TRANS.TBL vmlinuz [root@PXE pxeboot]# cp initrd.img vmlinuz /var/lib/tftpboot/rhel8.0/ [root@PXE pxeboot]# ls /var/lib/tftpboot/rhel8.0/ initrd.img vmlinuz [root@PXE pxeboot]#4.修改開機啟動菜單
label linuxmenu label ^Install CentOS Linux 8kernel vmlinuzappend initrd=initrd.img inst.stage2=hd:LABEL=CentOS-8-2-2004-x86_64-dvd quietlabel rhel8.0menu label ^Install Red Hat Enterprise Linux 8.0kernel /rhel8.0/vmlinuzappend initrd=/rhel8.0/initrd.img ks=http://192.168.3.150/ks/ks.cfg quiet5.客戶端開機pxe引導測試
七、安裝httpd服務(wù)
1.安裝httpd軟件包
[root@PXE ~]# yum -y install httpd Last metadata expiration check: 1:58:48 ago on Tue 10 Aug 2021 08:30:02 PM CST. Dependencies resolved. ============================================================================================Package Arch Version Repository Size2.創(chuàng)建/pub、/ks 目錄
[root@PXE ~]# mkdir /var/www/html/pub [root@PXE ~]# mkdir /var/www/html/ks [root@PXE ~]#3.設(shè)置httpd服務(wù)開機自啟
[root@PXE ~]# systemctl enable --now httpd Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service. [root@PXE ~]#八、配置ks腳本
1.將光盤自動掛載到/var/www/html/pub
[root@PXE ~]# mount /dev/cdrom /var/www/html/pub/ mount: /var/www/html/pub: WARNING: device write-protected, mounted read-only. [root@PXE tftpboot]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Tue Aug 10 03:43:55 2021 # # Accessible filesystems, by reference, are maintained under '/dev/disk/'. # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info. # # After editing this file, run 'systemctl daemon-reload' to update systemd # units generated from this file. # /dev/mapper/cl-root / xfs defaults 0 0 UUID=77cba1b9-3e8e-48d8-8469-5ca1be92fcfd /boot ext4 defaults 1 2 /dev/mapper/cl-swap swap swap defaults 0 0/dev/cdrom /var/www/html/pub iso9660 defaults 0 02.將 ks 文件移動到共享目錄
[root@PXE ~]# cp anaconda-ks.cfg /var/www/html/ks/ks.cfg cp: overwrite '/var/www/html/ks/ks.cfg'? yes [root@PXE ~]# ls /var/www/html/ks/ ks.cfg3.編輯ks腳本
#version=RHEL8 ignoredisk --only-use=sda autopart --type=lvm # Partition clearing information clearpart --all --initlabel --drives=sda # Use graphical install url --url="http://192.168.3.150/pub/" # Use CDROM installation media# Keyboard layouts keyboard --vckeymap=us --xlayouts='us' # System language lang en_US.UTF-8# Network information network --bootproto=dhcp --device=ens33 --ipv6=auto --activate network --hostname=localhost.localdomain repo --name="AppStream" --baseurl=file:///run/install/repo/AppStream # Root password rootpw --iscrypted $6$ReprMjobTM5tQxpl$Mx.0WCWlwaemvuV6Vpw55laOrJDyzNCFM8iUnGUUwjVWLEEumGgBWFn9lhJHDCeKHBtRLOkF8nDeXpZ40HhcL/ # X Window System configuration information xconfig --startxonboot # Run the Setup Agent on first boot firstboot --enable # Systemservices --disabled="chronyd" # System timezone timezone Asia/Shanghai --isUtc --nontp%packages @^graphical-server-environment kexec-tools%end%addon com_redhat_kdump --enable --reserve-mb='auto'%end%anaconda pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok4.修改ks.cfg權(quán)限
[root@PXE ~]# ll /var/www/html/ks/ total 4 -rw-------. 1 root root 1262 Aug 13 23:48 ks.cfg [root@PXE ~]# chmod a+r /var/www/html/ks/ks.cfg [root@PXE ~]# ll /var/www/html/ks/ total 4 -rw-r--r--. 1 root root 1262 Aug 13 23:48 ks.cfg九、重啟所有相關(guān)服務(wù)
[root@PXE ~]# systemctl restart httpd [root@PXE ~]# systemctl restart xinetd.service [root@PXE ~]# systemctl restart dhcpd [root@PXE ~]#十、測試PXE安裝系統(tǒng)
總結(jié)
以上是生活随笔為你收集整理的通过PXE服务器批量安装系统的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Dokcer容器实战之部署论坛
- 下一篇: Linux基础之网络配置