1.环境准备
服务器 | 作用 |
---|---|
dhcp-server | 为PXE客户端提供IP |
tftp-server | 为PXE客户端提供启动服务 |
httpd-server | 为PXE客户端提供软件包 |
因为资源限制,将dhcp,tftp和httpd集成到一台服务器上
服务器 | IP |
---|---|
Server | 10.1.1.10 |
设置主机名,关闭防火墙以及selinux
[root@Server ~]# hostnamectl set-hostname Server #主机名
[root@Server ~]# systemctl stop firewalld #防火墙关闭
[root@Server ~]# systemctl disable firewalld
[root@Server ~]# setenforce 0 #selinux设置为permissive
[root@Server ~]# getenforce
Permissive
yum源已配置为清华源
安装所需软件包
[root@Server ~]# dnf -y install dhcp-server tftp-server httpd syslinux-nonlinux
2.服务搭建
一.dhcpd
# 复制配置文件
[root@Server ~]# cp -a /usr/share/doc/dhcp-server/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp: overwrite '/etc/dhcp/dhcpd.conf'? y
[root@Server ~]# vim /etc/dhcp/dhcpd.conf
#将以下配置修改
subnet 10.5.5.0 netmask 255.255.255.224 {
range 10.5.5.26 10.5.5.30;
option domain-name-servers ns1.internal.example.org;
option domain-name "internal.example.org";
option routers 10.5.5.1;
option broadcast-address 10.5.5.31;
default-lease-time 600;
max-lease-time 7200;
}
#修改为如下配置
subnet 10.1.1.0 netmask 255.255.255.0 {
range 10.1.1.20 10.1.1.50;
option domain-name-servers 114.114.114.114, 8.8.8.8;
option routers 10.1.1.2;
next-server 10.1.1.10;
filename "pxelinux.0";
}
保存退出
[root@Server ~]# systemctl restart dhcpd # 重启dhcpd
二.httpd
[root@Server ~]# mkdir /var/www/html/RHEL
[root@Server ~]# mount /dev/cdrom /var/www/html/RHEL/
mount: /var/www/html/RHEL: WARNING: device write-protected, mounted read-only.
[root@Server ~]# systemctl restart httpd # 重启httpd
三.tftp
# 拷贝启动所需文件
[root@Server ~]# cp -a /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@Server ~]# cp -a /var/www/html/RHEL/isolinux/{initrd.img,ldlinux.c32,vesamenu.c32,libcom32.c32,vmlinuz,libutil.c32} /var/lib/tftpboot/
# 拷贝引导文件并修改
[root@Server ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@Server ~]# cp /var/www/html/RHEL/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
[root@Server ~]# cat /var/lib/tftpboot/pxelinux.cfg/default
# 修改文件为如下内容
default vesamenu.c32
timeout 600
label linux
menu label ^Manual Install CentOS Linux 8
kernel vmlinuz
append initrd=initrd.img inst.stage2=http://10.1.1.10/RHEL
label linux
menu label ^Install Mini CentOS Linux 8
menu default
kernel vmlinuz
append initrd=initrd.img ks=http://10.1.1.10/ks.cfg
label local
menu label Boot from ^local drive
localboot 0xffff
[root@Server ~]# cp anaconda-ks.cfg /var/www/html/ks.cfg
# 拷贝引导文件并修改
[root@Server ~]# chmod o+r /var/www/html/ks.cfg
# 赋予其他用户添加可读权限
[root@Server ~]# grep -Ev "^$|#" /var/www/html/ks.cfg
# 以下内容可直接删除原文件后复制粘贴
ignoredisk --only-use=sda
zerombr
text
reboot
clearpart --none --initlabel
selinux --disabled
firewall --disabled
url --url="http://10.1.1.10/RHEL" # 记得修改为自己的仓库
keyboard --vckeymap=us --xlayouts='us'
lang en_US.UTF-8
network --bootproto=dhcp --device=ens33 --ipv6=auto --activate
network --hostname=centos8.localdomain
rootpw --iscrypted $6$nufSJTHpF5iL.8Eo$ZvEhY2QC5Undub4aGFV9driy/BieNip5XKXzN.lGEn/G7npJjv8eMBe3ORvh37IeIWxjfTlsFnl0RE0hai.fk/
firstboot --enable
clearpart --all --initlabel
skipx
services --disabled="chronyd"
timezone Asia/Shanghai --isUtc --nontp
part / --fstype="xfs" --ondisk=sda --size=20480
part /boot --fstype="ext4" --ondisk=sda --size=1024
part swap --fstype="swap" --ondisk=sda --size=4096
part /data --fstype="xfs" --ondisk=sda --size=10240
%packages
@^minimal-environment
kexec-tools
%end
%addon com_redhat_kdump --disable --reserve-mb='auto'
%end
%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
[root@Server ~]# systemctl restart tftp # 重启tftp
3.测试服务
新建一台vmware虚拟机,不带iso镜像文件
开启虚拟机
正在安装
安装成功
至此,服务搭建成功