PXE自动装机(centos7.9)
系统初始化
-
系统类型
系统 IP地址 centos7.9 192.168.5.6 -
关闭防火墙
systemctl stop firewalld systemctl disable firewalld
-
关闭selinux
sed -i 's/^SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
pxe基础环境
-
上传centos7.9镜像到主机
-
安装dhcp服务
yum -y install dhcp
-
配置dhcp
describe:
subnet: 配置为当前服务器网段
range: dhcp范围
next-server: 指定tftp服务地址
cp /etc/dhcp/dhcpd.conf{,.bak} cat >/etc/dhcp/dhcpd.conf<<EOF subnet 192.168.5.0 netmask 255.255.255.0 { range 192.168.5.21 192.168.5.29; next-server 192.168.5.6; filename "pxelinux.0"; } EOF
-
启动dhcp
systemctl start dhcpd
-
安装http服务
yum -y install httpd
-
挂载镜像到http
mkdir /var/www/html/centos7 mount -o loop /opt/CentOS-7-x86_64-DVD-2009.iso /var/www/html/centos7
-
启动http服务
systemctl start httpd
-
安装tftp-server
yum -y install tftp-server
-
启动tftp-server服务
systemctl start tftp
-
将配套文件部署到tftp
cp /var/www/html/centos7/isolinux/* /var/lib/tftpboot/
-
安装syslinux获取pxelinux.0
yum -y install syslinux # 将启动文件部署到tftp cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
-
创建配置目录
mkdir /var/lib/tftpboot/pxelinux.cfg
-
建立默认菜单配置
cp /var/lib/tftpboot/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
pxe_kickstart文件配置
-
ks.cfg文件配置
#version=DEVEL # System authorization information auth --enableshadow --enablemd5 # Use CDROM installation media url --url=http://192.168.5.6/centos7 # Use graphical install 图形化界面式安装 # graphical # Use text install 文本式安装 text # Run the Setup Agent on first boot firstboot --enable # 启用会忽略其他硬盘 # ignoredisk --only-use=sda # Keyboard layouts keyboard --vckeymap=us --xlayouts='us' # System language lang en_US.UTF-8 # Network information network --bootproto=dhcp --device=eth0 --ipv6=auto --activate network --hostname=localhost.localdomain # Root password 不要忘记更改 rootpw --iscrypted $1$8q7ORxjl$v8yGB70WIHiLjNcaJRdCh. # System services services --disabled="chronyd" # System timezone timezone Asia/Shanghai --isUtc --nontp # Partition clearing information clearpart --all --initlabel # System bootloader configuration part /boot --asprimary --fstype="ext4" --size=500 --ondisk=sda #----------------------以下是创建lvm逻辑卷--------------------- # --size=1 --grow参数是以剩余所有空间来分区 # 创建第一个物理卷PV分区,序号是01,大小为剩余所有空间 part pv.01 --size=1 --grow --ondisk=sda # 创建一个逻辑卷组名,名字为root,包含在物理卷PV.01 volgroup root pv.01 # 创建一个LV逻辑卷,挂载到/ ,从root组中创建,大小为剩余space,LV的名字是volume-root logvol / --fstype="ext4" --vgname=root --size=1 --grow --name=volume-root # 创建第二个物理卷PV分区,序号是02,大小为剩余space part pv.02 --size=1 --grow --ondisk=sdb #创建一个逻辑卷组名,名字为data,包含在物理卷PV.02 volgroup data pv.02 #创建一个LV逻辑卷,挂载到/data ,从data组中创建,大小为剩余space,LV的名字是volume-data logvol /data --fstype="ext4" --vgname=data --size=1 --grow --name=volume-data # 最小化安装 %packages @^minimal @core 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
-
复制ks.cfg 到http目录
cp /root/ks.cfg /var/www/html/
-
配置default文件
# vim /var/lib/tftpboot/pxelinux.cfg/default label linux menu label ^Install CentOS 7 menu default kernel vmlinuz append initrd=initrd.img ks=http://192.168.5.6/ks.cfg net.ifnames=0 biosdevname=0 quiet