目录
【1】安装dhcp、tftp-server、httpd、syslinux、关闭防火墙、挂载镜像
【1】安装dhcp、tftp-server、httpd、syslinux、关闭防火墙、挂载镜像
[root@pxe~]# yum -y install dhcp tftp-server.x86_64 httpd syslinux
[root@pxe~]# systemctl stop firewalld
[root@pxe~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@pxe~]# mkdir -p /media/cdrom
[root@pxe~]# mount /dev/sr0 /media/cdrom
【2】配置dhcp服务
[root@pxe~]# cat /etc/dhcp/dhcpd.conf
subnet 10.0.0.0 netmask 255.255.255.0 {
range 10.0.0.70 10.0.0.80;
default-lease-time 3600;
filename "pxelinux.0";
next-server 10.0.0.10;
}
[root@pxe~]# systemctl enable --now dhcpd
【3】配置tftp服务
[root@pxe ~]# vim /etc/xinetd.d/tftp
service tftp
{
socket_type = dgram
protocol = udp
wait = no
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}
[root@pxe~]# systemctl enable --now tftp.socket
【4】拷贝pxe服务器的相关文件到tftp的根目录
[root@pxe~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@pxe~]# cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot/
[root@pxe~]# cp /media/cdrom/isolinux/vmlinuz /var/lib/tftpboot/
[root@pxe~]# cp /media/cdrom/isolinux/initrd.img /var/lib/tftpboot/
【5】创建pxelinux.cfg文件
[root@pxe~]# cd /var/lib/tftpboot/
[root@pxe tftpboot]# mkdir pxelinux.cfg
[root@pxe tftpboot]# vim pxelinux.cfg/default
default menu.c32
timeout 300
prompt 0
label 1
menu label ^1) Install CentOS7
menu default
kernel vmlinuz
append initrd=initrd.img method=http://10.0.0.10/centos7 ks=http://10.0.0.10/ks.cfg
【6】配置httpd
[root@pxe tftpboot]# cd /var/www/html/
[root@pxe html]# systemctl start httpd.service
[root@pxe html]# mkdir centos7
[root@pxe html]# mount /dev/cdrom /var/www/html/centos7
- 访问测试(10.0.0.10/centos7)
【7】Kickstart自动化文件
[root@ansible html]# cp /root/anaconda-ks.cfg /var/www/html/
[root@ansible html]# mv anaconda-ks.cfg ks.cfg
[root@ansible html]# chmod +r ks.cfg
- 测试访问(10.0.0.10/ks.cfg),确保能正常访问
- 修改配置ks.cfg
[root@pxe html]# vim ks.cfg
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
#cdrom
url --url http://10.0.0.10/centos7
# Use graphical install
#graphical
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 --onboot=off --ipv6=auto --no-activate
network --hostname=localhost.localdomain
# Root password
rootpw --iscrypted $6$.9w6AEAECYQiRq7S$3IzY2mG/Q4Iw7y2/kT0t3WiJ9hAhASrd0npUOK2077hDUvsfjHOFsU1Pg9PHZza8xOG2xDMwUbDpt5bvaE6vS1
# System services
services --enabled="chronyd"
# System timezone
timezone America/New_York --isUtc
# System bootloader configuration
bootloader --location=mbr --boot-drive=sda
autopart --type=lvm
# Partition clearing information
#clearpart --none --initlabel
clearpart --all --initlabel
%packages
@^minimal
@core
@development
chrony
%end
%addon com_redhat_kdump --disable --reserve-mb='auto'
%end
%anaconda
pwpolicy root --minlen=6 --minquality=50 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=50 --notstrict --nochanges --notempty
pwpolicy luks --minlen=6 --minquality=50 --notstrict --nochanges --notempty
%end
reboot
【8】重启所有服务
[root@pxe ~]# systemctl restart httpd
[root@pxe ~]# systemctl restart tftp.socket
[root@pxe ~]# systemctl restart dhcpd
【9】验证
- 准备一台新的虚拟机,网络模式必须跟服务端相同,客户机内存必要足够(至少2G),光盘设置自动检测
【10】启动
- 等待安装完成(几分钟)
【11】完成