1、基础环境:
镜像ISO文件名为:CentOS-7-x86_64-DVD-1804.iso
2、安装需要的软件包
yum install dhcp xinetd syslinux httpd tftp-server -y
dhcpd: 动态分配IP
xinetd: 对服务访问进行控制,这里主要是控制tftp
tftp: 从服务器端下载pxelinux.0、default文件
syslinux: 用于网络引导
httpd: 在网络上提供安装源,也就是镜像文件中的内容
3、配置对应的服务
vi /etc/xinetd.d/tftp
配置 dhcp下发地址
ddns-update-style none;
ignore client-updates;
default-lease-time 259200;
max-lease-time 518400;
option domain-name-servers 114.114.114.114; #dns地址
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.110 192.168.1.115;
option routers 192.168.1.254; #下发的网关
option subnet-mask 255.255.255.0;
next-server 192.168.1.104; #下发的本机ip
# the configuration file for pxe boot
filename "pxelinux.0";
}
systemctl enable dhcpd && systemctl start dhcpd
systemctl enable xinetd && systemctl start xinetd
systemctl enable tftp && systemctl start tftp
systemctl enable httpd && systemctl start httpd
依次执行以下命令,开放防火墙TCP-80端口及UDP-69端口,注意不要搞错了UDP和TCP。
firewall-cmd –zone=public –add-port=80/tcp –permanent
firewall-cmd –zone=public –add-port=69/udp –permanent
firewall-cmd –reload
firewall-cmd –zone=public –list-ports
也可以直接关闭防火墙
关闭selinux
## 以下配置生效需要系统重启##
临时关闭selinux: setenforce 0
mkdir /var/www/html/centos7
创建挂载点
mount -t iso9660 -o loop /dev/cdrom /mnt/
cp -rf /mnt/* /var/www/html/centos7/
建议挂载在/mnt 下(通用挂载点)
mkdir /var/lib/tftpboot/centos7
cp /var/www/html/centos7/images/pxeboot/initrd.img /var/lib/tftpboot/centos7/
cp /var/www/html/centos7/images/pxeboot/vmlinuz /var/lib/tftpboot/centos7/
cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot
mkdir /var/lib/tftpboot/pxelinux.cfg
vi /var/lib/tftpboot/pxelinux.cfg/default
4、创建Kickstart文件ks.cfg
这个需要安装kickstart执行:yum -y install system-config-kickstart
bash#下运行system-config-kickstart,打开kickstart桌面软件,选择安装步骤。
cat/var/www/html/centos7/ks.cfg
#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$grc2urK7$tqnhPtOUV/SFfQT0DTeko0
# Use network installation
url --url="http://192.168.1.104/centos7/"
# System language
lang zh_CN
# System authorization information
auth --useshadow --passalgo=sha512
# Use text mode install
text
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# Firewall configuration
firewall --disabled
# Network information
network --bootproto=dhcp --device=ens33
# Reboot after installation
reboot
# System timezone
timezone Asia/Hong_Kong --isUtc
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
clearpart --all --initlabel #清空分区
part /boot --fstype xfs --size 1024 #/boot分区
part swap --size 1024 #swap分区
part / --fstype xfs --size 1 --grow #根分区
firstboot --disable
%packages
@compat-libraries
@core
@debugging
@development
@fonts
@gnome-apps
@gnome-desktop
@graphics
@ha
@input-methods
@internet-applications
@load-balancer
@mainframe-access
@mariadb-client
@network-tools
@office-suite
@platform-devel
@remote-system-management
@resilient-storage
@system-admin-tools
@system-management
@web-server
crypto-utils
fence-agents-all
%end
%post
cat >>/etc/yum.repos.d/base.repo<<eof
[base]
name=CentOS-$releasever - Base - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
eof
sed -i "s/ONBOOT.*$/ONBOOT=yes/" /etc/sysconfig/network-scripts/ifcfg-ens33 #设置网卡为启动
sed -i "s/rhgb //" /boot/grub/grub.conf # 设置启动系统时不使用图形进度条方
式
sed -i "s/HOSTNAME=.*$/HOSTNAME=xuexi.longshuai.com/" /etc/sysconfig/network #设置主机名
%end
有个小彩蛋,kickstart安装之后默认是起不来软件包选择项的需要修改yum源