简单讲解在Centos上配置一个PXE服务器,批量安装Centos
仅供学习与交流,请勿用于商业用途
什么是PXE? 请读者自己百度!
本文将会讲解怎么实现PXE + DHCP + TFTP + NFS 实现网络批量安装Centos
服务器配置
- CPU - 单核以上
- 内存 - 2G以上
- 存储 - 越快越好
- 操作系统 - Centos7 最小安装
- IP地址 - 192.168.4.100/24
- 关闭防火墙和SElinux(试验环境,我懒得改,生产环境为了安全性,请勿关闭)
配置DHCP服务
安装dhcp服务
yum install dhcp -y
修改DHCP配置文件
vim /etc/dhcp/dhcpd.conf
# DHCP Server Configuration file.
allow booting;
allow bootp;
ddns-update-style interim;
ignore client-updates;
subnet 192.168.4.0 netmask 255.255.255.0 {
option rounter 192.168.4.100
option subnet-mask 255.255.255.0;
option domain-name-servers 192.168.4.100;
range dynamic-bootp 192.168.4.101 192.168.4.200;
default-lease-time 21600;
max-lease-time 43200;
next-server 192.168.4.100;
filename "pxelinux.0";
}
启动服务
systemctl start dhcpd.service && systemctl enable dhcpd.service
配置TFTP
安装TFTP和xinetd服务
yum install tftp-server xinetd -y
修改xinetd配置文件 把tftp的disable改成no 托管tftp服务
vim /etc/xinetd.d/tftp
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot
disable = no
per_source = 11
cps = 100 2
flags = IPv4
启动xinted
systemctl enable xinetd && systemctl start xinetd
配置nfs
修改配置文件并创建nfs共享文件夹,并复制centos.iso的所有内容到该目录下
mkdir -p /nfs/centos7
cp -rf /media/cdrom/* /nfs/centos7/ &
vim /etc/exports
/nfs *(ro)
启动nfs服务
systemctl enable vsftpd.service && systemctl start vsftpd.service
配置PXE boot服务
安装syslinux
yum install syslinux* -y
复制引导和内核到tftp目录
mkdir /var/lib/tftpboot/pxelinux.cfg
mkdir -p /var/lib/tftpboot/centos7
cp /nfs/centos7/isolinux/{initrd.img,vmlinuz} /var/lib/tftpboot/centos7/
创建引导菜单
default vesamenu.c32
timeout 300
menu tabmsg Moulongxiong NIUBI
menu title moulongxiong auto-install system
label Install Centos7
kernel /centos7/vmlinuz
append initrd=/centos7/initrd.img inst.stage2=nfs:192.168.4.100:/nfs/centos7
启动客户端
大功告成!
当然这还需要人工点击开始安装并配置才能安装
有兴趣的可以搜索kickstart实现无人值守安装