- 一、环境介绍
-
- 1.PXE服务器版本
- 2.挂载光盘
- 3.配置yum仓库
- 二、部署DHCP服务器
-
- 1.安装相关软件包
- 2.编辑DHCP配置文件
- 3.重启dhcp服务
- 4.放行防火墙端口
- 5.关闭selinux
- 三、部署TFTP服务器
-
- 1.安装相关包
- 2.修改TFTP服务配置文件
- 3.重启服务
- 4.放行防火墙
- 5.检查相关服务运行端口
- 四 、在 dhcp 配置文件中加入 tftp 服务相关参数
- 五、配置tftp下服务文件
-
- 1.安装 syslinux软件包
- 2.将 pxelinux.0 复制到/var/lib/tftpboot
- 3.将光盘 isolinux 目录所有内容,拷贝到/var/lib/tftpboot 中
- 4.创建/var/lib/tftpboot/pxelinux.cfg目录
- 5.将 isolinux.cfg 文件拷贝并改名为 default
- 六、编辑 pxe 网络安装启动菜单条
-
- 1.创建安装系统对应目录
- 2.挂载安装所需系统的RHEL8.0光盘
- 3.拷贝相关系统启动文件到/var/lib/tftpboot/rhel8.0/下
- 4.修改开机启动菜单
- 5.客户端开机pxe引导测试
- 七、安装httpd服务
-
- 1.安装httpd软件包
- 2.创建/pub、/ks 目录
- 3.设置httpd服务开机自启
- 八、配置ks脚本
-
- 1.将光盘自动挂载到/var/www/html/pub
- 2.将 ks 文件移动到共享目录
- 3.编辑ks脚本
- 4.修改ks.cfg权限
- 九、重启所有相关服务
- 十、测试PXE安装系统
一、环境介绍
1.PXE服务器版本
[root@PXE ~]
CentOS Linux release 8.2.2004 (Core)
2.挂载光盘
[root@PXE ~]
mount: /mnt/cdrom: WARNING: device write-protected, mounted read-only.
[root@PXE ~]
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/cdrom
3.配置yum仓库
[development]
name=rhel8
baseurl=file:///mnt/cdrom/BaseOS
baseurl=file://mnt/cdrom/AppStream
enabled=1
gpgcheck=0
[root@PXE yum.repos.d]
0 files removed
[root@PXE yum.repos.d]
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服务器
1.安装相关软件包
[root@PXE yum.repos.d]
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: overwrite '/etc/dhcp/dhcpd.conf'? yes
[root@PXE dhcp]
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服务
[root@PXE dhcp]
● 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]
success
[root@PXE dhcp]
success
[root@PXE dhcp]
67/udp
5.关闭selinux
[root@PXE ~]
[root@PXE ~]
Permissive
三、部署TFTP服务器
1.安装相关包
[root@PXE ~]
[root@PXE ~]
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服务配置文件
[root@PXE ~]service tftp
{socket_type = dgramprotocol = udpwait = yesuser = rootserver = /usr/sbin/in.tftpdserver_args = -s /var/lib/tftpbootdisable = noper_source = 11cps = 100 2flags = IPv4
}
3.重启服务
[root@PXE ~]
[root@PXE ~]
[root@PXE ~]
[root@PXE ~]
4.放行防火墙
[root@PXE ~]
success
[root@PXE ~]
success
5.检查相关服务运行端口
[root@PXE ~]
udp 0 0 0.0.0.0:69 0.0.0.0:* 38484/xinetd
[root@PXE ~]
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 服务相关参数
[root@PXE ~]
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下服务文件
1.安装 syslinux软件包
[root@PXE ~]
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 ~]
[root@PXE ~]
3.将光盘 isolinux 目录所有内容,拷贝到/var/lib/tftpboot 中
[root@PXE ~]
4.创建/var/lib/tftpboot/pxelinux.cfg目录
[root@PXE ~]
[root@PXE ~]
5.将 isolinux.cfg 文件拷贝并改名为 default
[root@PXE ~]
[root@PXE ~]
六、编辑 pxe 网络安装启动菜单条
1.创建安装系统对应目录
[root@PXE tftpboot]
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]
[root@PXE tftpboot]
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.TBL
2.挂载安装所需系统的RHEL8.0光盘
[root@PXE tftpboot]
mount: /mnt/cdrom: WARNING: device write-protected, mounted read-only.
[root@PXE tftpboot]
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/cdrom
3.拷贝相关系统启动文件到/var/lib/tftpboot/rhel8.0/下
[root@PXE pxeboot]
/mnt/cdrom/images/pxeboot
[root@PXE pxeboot]
initrd.img TRANS.TBL vmlinuz
[root@PXE pxeboot]
[root@PXE pxeboot]
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 quiet
5.客户端开机pxe引导测试
七、安装httpd服务
1.安装httpd软件包
[root@PXE ~]
Last metadata expiration check: 1:58:48 ago on Tue 10 Aug 2021 08:30:02 PM CST.
Dependencies resolved.
============================================================================================Package Arch Version Repository Size
2.创建/pub、/ks 目录
[root@PXE ~]
[root@PXE ~]
[root@PXE ~]
3.设置httpd服务开机自启
[root@PXE ~]
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: /var/www/html/pub: WARNING: device write-protected, mounted read-only.
[root@PXE tftpboot]
/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 0
2.将 ks 文件移动到共享目录
[root@PXE ~]
cp: overwrite '/var/www/html/ks/ks.cfg'? yes
[root@PXE ~]
ks.cfg
3.编辑ks脚本
ignoredisk --only-use=sda
autopart --type=lvm
clearpart --all --initlabel --drives=sda
url --url="http://192.168.3.150/pub/"
keyboard --vckeymap=us --xlayouts='us'
lang en_US.UTF-8
network --bootproto=dhcp --device=ens33 --ipv6=auto --activate
network --hostname=localhost.localdomain
repo --name="AppStream" --baseurl=file:///run/install/repo/AppStream
rootpw --iscrypted $6$ReprMjobTM5tQxpl$Mx.0WCWlwaemvuV6Vpw55laOrJDyzNCFM8iUnGUUwjVWLEEumGgBWFn9lhJHDCeKHBtRLOkF8nDeXpZ40HhcL/
xconfig --startxonboot
firstboot --enable
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 --emptyok
4.修改ks.cfg权限
[root@PXE ~]
total 4
-rw-------. 1 root root 1262 Aug 13 23:48 ks.cfg
[root@PXE ~]
[root@PXE ~]
total 4
-rw-r--r--. 1 root root 1262 Aug 13 23:48 ks.cfg
九、重启所有相关服务
[root@PXE ~]
[root@PXE ~]
[root@PXE ~]
[root@PXE ~]
十、测试PXE安装系统