安装所需软件
yum install -y tftp-server syslinux dhcp httpd system-config-kickstart
安装完将pxe引导文件复制到tftp上,在httpd主页下创建一个文件夹
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
mkdir -p /var/www/html/centos7
#把centos镜像isolinux目录下的所有文件都复制到tftp服务器上(centos7镜像文件事先解压放到了/var/www/html/centos7目录下)
cp -a /var/www/html/centos7/isolinux/* /var/lib/tftpboot/
#启动tftp
systemctl start tftpd
#启动httpd
systemctl start httpd
写入ks文件
vim /var/www/html/centos7/ks_config/centos7-ks.cfg 或者使用 system-config-kickstart命令生成文件
#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$KdnW5OJh$g75gHTLYXgIWoZlXdKxkP1
# System language
lang en_US
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
graphical
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# Firewall configuration
firewall --disabled
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# Use network installation
url --url="http://192.168.10.89/centos7/"
# System bootloader configuration
bootloader --location=none
# Clear the Master Boot Record
zerombr
#network --bootproto=static --device=ens192 --gateway=172.16.80.1 --ip=172.16.80.2 --nameserver=114.114.114.114 --netmask=255.255.255.0 --activate
network --bootproto=dhcp --device=ens192
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="xfs" --size=200
part swap --fstype="swap" --size=2048
part / --fstype="xfs" --size=92160
%packages
vim
%end
#创建一个文件夹,在里面写入默认安装的选项 mkdir -p /var/lib/tftpboot/pxelinux.cfg cp /var/www/html/CentOS7/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
vim /var/lib/tftpboot/pxelinux.cfg/default
#修改成ks.cfg
default ks prompt 0 label ks kernel vmlinuz append initrd=initrd.img ks=http://192.168.10.229/centos7/centos7-ks.cfg
label linux
menu label ^Install CentOS 7
kernel vmlinuz
#append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 quiet
append initrd=initrd.img method=http://192.168.10.229/centos7
tftp配置文件
service tftp { socket_type = dgram protocol = udp wait = yes user = root server = /usr/sbin/in.tftpd server_args = -s /var/lib/tftpboot #tftp的文件存放路径 disable = no per_source = 11 cps = 100 2 flags = IPv4 }
DHCP配置文件
# # DHCP Server Configuration file. # see /usr/share/doc/dhcp*/dhcpd.conf.example # see dhcpd.conf(5) man page # # # ddns-update-style none; #设置DHCP服务器模式 ignore client-updates; #禁止客户端更新 subnet 192.168.10.0 netmask 255.255.255.0 { #ip声明最后一位必须是0,网段需要和当前dhcp服务器做广播的网卡一个网段 range 192.168.10.235 192.168.10.240; #dhcp地址段 option routers 192.168.10.1; #设置网关 option broadcast-address 192.168.10.254; #广播地址 default-lease-time 21600; #默认租约时间 max-lease-time 43200; #最大租约时间 next-server 192.168.10.229; #tftp服务器地址 filename "/pxelinux.0"; #tftp上的pxe引导文件 }
然后将那张网卡设置广播,以让内网的机器获取到ip地址
route add -host 255.255.255.255 dev 网卡名
#启动dhcp
systemctl start dhcpd