一、需要用到的软件包
DHCP服务器:为 PXE-client 分配 IP ,获得安装程序文件位置。
TFTP服务器:传输安装文件、内核、菜单文件等给 PXE-client。
Kickstart(可选):生成的ks.cfg配置文件。
HTTP/NFS/FTP 服务中的任意一种,本次采用HTTP,用于传送安装源文件给 PXE-client。
二、安装步骤
1.关闭防火墙
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
2.安装依赖
[root@localhost ~]# yum -y install dhcp tftp-server httpd syslinux
3.配置DHCP
[root@localhost ~]# vi /etc/dhcp/dhcpd.conf
subnet 192.168.5.0 netmask 255.255.255.0 { #网段
range 192.168.5.110 192.168.5.150; #具体地址范围
default-lease-time 3600; #默认租期
filename "pxelinux.0"; #指定网卡引导文件名称
next-server 192.168.5.201; #本机IP
}
[root@localhost ~]# systemctl restart dhcpd
4.配置TFTP服务器
[root@localhost ~]# vi /etc/xinetd.d/tftp
# 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 #把这里改成 no
per_source = 11
cps = 100 2
flags = IPv4
}
[root@localhost ~]# systemctl restart tftp.socket
5.拷贝PXE的相关文件至TFTP根目录( /var/lib/tftpboot/)
引导文件 [root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
菜单文件 [root@localhost ~]# cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot/
6.挂载光驱,拷贝引导文件
挂载光驱 [root@localhost ~]# mount /dev/sr0 /mnt/centos7
拷贝引导文件
[root@localhost ~]# cp /mnt/centos7/isolinux/vmlinuz /var/lib/tftpboot/
[root@localhost ~]# cp /mnt/centos7/isolinux/initrd.img /var/lib/tftpboot/
7.在tftpboot下创建pxelinux.cfg文件夹,并在该文件夹下创建default文件。
[root@localhost tftpboot]# mkdir pxelinux.cfg
[root@localhost tftpboot]# cd pxelinux.cfg
[root@localhost pxelinux.cfg]# touch default
8.编辑default文件
[root@localhost pxelinux.cfg]# vi default
default menu.c32
timeout 300 #超时时间
prompt 0 #值为1的话会直接选择默认的选项
label 1
menu label ^ Install Centos 7 #选项名称
menu default
menu titlE ############## PXE ############## #标题
Kernel vmlinuz
append initrd=initrd.img method=http://192.168.5.201/centos7 #需要在http根目录下创建个文件夹用来放安装文件
ks=http://192.168.5.201/ks.cfg #无人值守文件
9.配置HTTP
[root@localhost ~]# cd /var/www/html
[root@localhost html]# mkdir centos7 #创建centos7文件夹,将光驱文件拷贝过来
[root@localhost html]# cp /mnt/centos7/* centos7/
[root@localhost html]# systemctl restart httpd
这一步完成后,可以打开浏览器测试http://192.168.5.201/centos7 (这里是我展示的地址,需要你PXE服务器的IP)是否可以看到系统目录文件
10.编辑ks文件
- 方法1:
每安装好一台Centos机器,Centos安装程序都会创建一个kickstart配置文件,名字叫anaconda-ks.cfg位于/root/anaconda-ks.cfg ,记录真实安装配置。 - 方法2:
Centos提供了一个图形化的kickstart配置工具。在任何一个安装好的Linux系统上运行该工具,就可以很容易地创建你自己的kickstart配置文件。 - 方法3:
阅读kickstart配置文件的手册。用任何一个文本编辑器都可以创建你自己的kickstart配置文件。
这里我们选择方法一,将根目录下的anaconda-ks.cfg拷贝到/var/www/html/下重命名ks.cfg
[root@localhost html]# vi ks.cfg
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
#cdrom
url --url http://192.168.5.201/centos7 #这里需要填写地址
# Use graphical install
graphical #选择图形化安装还是文本
#text
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=vda
# Keyboard layouts
keyboard --vckeymap=cn --xlayouts='cn'
# System language
lang zh_CN.UTF-8
# Network information
network --bootproto=static --device=eth0
--gateway=192.168.5.10
--ip=192.168.5.200 --nameserver=114.114.114.114,8.8.8.8
--netmask=255.255.255.0
--ipv6=auto
--activate
network --hostname=localhost.localdomain
# Root password
rootpw --iscrypted $6$ufLYHJN/ile3T3ko$KPc60Fr7LwgHdnL4Ke6VyTPYgQhADYFGGhomn.1f4bcLWfPifSZ2dLNw1gx/djYpIe8NB5XgCc0o6CNvpzEdl/
# System services
services --enabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=vda
autopart --type=lvm
# Partition clearing information
#clearpart --none --initlabel
clearpart --all --initlabel #清楚所有分区
%packages
@^minimal
@core
chrony
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
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
reboot #安装完重启
11. 客户端从网卡引导

12. 可以把等待时间调快点,或者prompt 值调成1自动跳过。
13.同理,其他版本的系统也可以按照此方法添加。

本文详细描述了如何设置DHCP服务器、TFTP服务器以及配置HTTP服务,以实现PXE方式部署CentOS7,并指导用户进行无人值守安装,包括关闭防火墙、安装依赖、配置网络和使用Kickstart文件等关键步骤。

7167

被折叠的 条评论
为什么被折叠?



