CentOS7配置PXE自动安装

本文档详细介绍了如何在CentOS7中配置PXE进行自动安装,包括环境配置、软件安装、配置修改、服务启动和测试,以及最终的安装文件准备和测试。通过内部网络和VirtualBox进行实验,确保 PXE 客户端能够通过DHCP获取IP,并从TFTP和HTTP服务器下载安装文件,实现无人值守安装。
摘要由CSDN通过智能技术生成

CentOS7配置PXE自动安装

文章说明

测试PXE自动安装

环境配置

  • 软件:使用VirtualBox5版本
  • 操作系统:CentOS7

配置过程

初始配置

  • 在virtualbox中安装centos7操作系统;要求使用两个网卡
    一个网卡使用“网络地址转换(NAT)”,用于访问公网及使用SSH
    一个网卡使用“内部网络”,用于测试;要测试的服务器也用“内部网络”,并选择上“设置–》系统–》网络”;
  1. 第一个网卡配置dhcp,第二个网卡配置静态地址;如下:(仅显示需要修改的部分
[root@10 ~]# more /etc/sysconfig/network-scripts/ifcfg-enp0s8|grep -E 'ONBOOT|BOOTPROTO|IPADDR|PREFIX'
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.168.1.1
PREFIX=24
[root@10 ~]# more /etc/sysconfig/network-scripts/ifcfg-enp0s3|grep -E 'ONBOOT|BOOTPROTO|IPADDR|PREFIX'
BOOTPROTO=dhcp
ONBOOT=yes
[root@10 ~]#

安装软件

dhcp是自动分配IP
tftp-server、xinetd是提供pxe内核
httpd提供安装操作系统的文件
关闭防火墙、重启网卡等

yum install dhcp tftp-server httpd xinetd -y
sed -i 's/=enforcing/=disabled/g' /etc/selinux/config
setenforce 0
systemctl stop firewalld
systemctl disable firewalld
yum install net-tools -y
systemctl restart network

修改配置及启动

这里配置了两个文件,dhcpd.conf及tftp配置文件

sed -i  "/disable/ s/yes/no/"  /etc/xinetd.d/tftp
echo 'this is test 测试文件' > /var/lib/tftpboot/test
cat > /etc/dhcp/dhcpd.conf << EOF
db-time-format local;
log-facility local7;
subnet 192.168.1.0 netmask 255.255.255.0 {
  range 192.168.1.26 192.168.1.130;
  option routers 192.168.1.1;
  option broadcast-address 192.168.1.255;
  default-lease-time 600;
  max-lease-time 7200;
  next-server 192.168.1.1;
  filename "pxelinux.0";
}
EOF
systemctl enable tftp dhcpd xinetd httpd
systemctl start tftp dhcpd xinetd httpd

测试dhcp及tftp

  • 找一台新的空白机器,设置网络启动,测试dhcp是否正常
  • 找一台新的机器,安装tftp,tftp客户端的系统,必须关闭防火墙,这里导致卡住很长时间
yum install tftp -y
systemctl stop firewalld
修改网卡为内部网卡
systemctl restart network
tftp 192.168.1.1 -c get test
cat test

dhcpd及tftp日志说明

rpm -ql dhcp #查看安装的软件的各种配置,包含日志、配置文件、配置模板等
tftp的日志,必须在/lib/systemd/system/tftp.service的命令行中加上-v 参数
两者的部分日志都在/var/log/messages中

配置其他部分

首先挂载CentOS7的镜像(设置–》存储–》没有盘片–》选择centos7的ISO的镜像)

mount /dev/cdrom /mnt
yum install syslinux -y
cp /mnt/images/pxeboot/{initrd.img,vmlinuz}  /var/lib/tftpboot/
cp /mnt/isolinux/{vesamenu.c32,boot.msg,splash.png} /var/lib/tftpboot/
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot
mkdir /var/lib/tftpboot/pxelinux.cfg
cp /mnt/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default

下面配置ks文件

mkdir /var/www/html/ks
cat > /var/www/html/ks/ks1.cfg << EOF
install
url --url=http://192.168.1.1/centos/
lang en_US.UTF-8
keyboard us
network --onboot yes --device bootif --bootproto dhcp --noipv6
rootpw 123456
firewall --disabled
authconfig --enableshadow --passalgo=sha512
selinux --disabled
timezone Asia/Shanghai
text
reboot
services --enabled kdump
bootloader --location=mbr --append="biosdevname=0 nodmraid console=tty0 console=ttyS0,115200"
zerombr
bootloader --location=mbr
clearpart --all --drives=sda
ignoredisk --only-use=sda
part swap --fstype=swap --ondisk=sda --size=535
part /boot --size=500
part pv.01 --size=6000 --grow --ondisk=sda
volgroup hfos pv.01
logvol /home --vgname=hfos --size=1200 --name=homevol
logvol / --vgname=hfos --size=4000 --grow --name=rootvol

%packages --ignoremissing
@base
@core
@development
@core
vim
unzip
tree
sysstat
sysbench
smem
rpcbind
procps
perf
openssl-devel
openssh-devel
openssh-clients
ntp
nfs-utils
net-tools
nc
lvm2
lshw
kdump
iproute
iperf
gcc-c++
gcc
ftp
fio
bzip2
blktrace
bc
sudo
kexec-tools
%end


%post
%end
EOF
chown -R apache:apache /var/www/html/ks

配置装机的文件

cat > /var/lib/tftpboot/pxelinux.cfg/default <<EOF
default vesamenu.c32
timeout 300
 display boot.msg
# Clear the screen when exiting the menu, instead of leaving the menu displayed.
# For vesamenu, this means the graphical background is still displayed without
# the menu itself for as long as the screen remains in graphics mode.
menu clear
menu background splash.png
menu title CentOS 7
 menu tabmsg Press Tab for full configuration options on menu items.
menu separator # insert an empty line
 label linux
  menu label ^Install CentOS 7
  kernel vmlinuz
  menu default
  append initrd=initrd.img ks=http://192.168.1.1/ks/ks1.cfg
 menu end
EOF

挂载硬盘

mkdir /var/www/html/centos
mount /dev/cdrom /var/www/html/centos

重启所有的服务

systemctl restart tftp dhcpd xinetd httpd

最终测试

新建一个虚拟机,配置20G硬盘,2G内网,网络安装;网络选择内部网络。
开机,让它自动安装

ISO镜像中的安装的时候选择的不同的参数,如“minimal或GNOME Desktop或Server with GUI”,这些
选择安装的软件都在ISO的下面的文件中。

[root@10 ~]# mount /dev/cdrom /mnt/
[root@10 ~]# more /mnt/repodata/cca56f3cffa18f1e52302dbfcf2f0250a94c8a37acd8347ed6317cb52c8369dc-c7-x86_64-comps.xml

数据来自B站视频
时间:2021-06-16

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值