准备两台主机:
一台DHCP,HTTPD,TFTP服务器(一个网卡,仅主机),一台测试机(一个网卡,仅主机)
关闭仅主机的vmware中dhcp服务
1、配置环境
yum install httpd tftp-server dhcp syslinux
systemctl start httpd tftp
2、准备yum源
把光盘挂载在http可以访问的位置
mkdir /var/www/html/centos/7/os/x86_64 -pv
mount /dev/sr0 /var/www/html/centos/7/os/x86_64
3、配置ks文件
yum -y install system-config-kickstart
yum -y install xorg-x11-xauth(如果xmanager打不开)
sed -i 's/base/development/' /etc/yum.repos.d/CentOS-Base.repo(centos7需把yum源名字修改一下,如果不行使用本地yum源)
system-config-kickstart
图形界面配置如下:
最后保存为ks7_mini.cfg文件(直接使用下面文本进行修改也可以):
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$9teneOiS$.Dt6KoJ4Rt9R90YpSRcFn0
# System language
lang en_US
# System authorization information
auth --useshadow --passalgo=sha512
# Use text mode install
text
firstboot --disable
# SELinux configuration
selinux --disabled
# Firewall configuration
firewall --disabled
# Network information
network --bootproto=dhcp --device=eth0
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# Use network installation
url --url="http://192.168.175.10/centos/7/os/x86_64/"
# System bootloader configuration
bootloader --append="net.ifnames=0" --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="xfs" --size=200
part swap --fstype="swap" --size=2000
part / --fstype="xfs" --grow --size=1
%packages
@^minimal
%end
%post
mkdir /root/.ssh
chmod 700 /root/.ssh
cat > /root/.ssh/authorized_keys <<EOF
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC9fZkSZq0Id35QE5EsWI3Lg/ET02mxRRIV8dwZ4IN8hdbeH/nfYeom9uQsd4iW93MUHiaHRA5gKH23ds7IrpP4R8Oq2vxmqT6dvrDcL1Jb2gB4cgjY05+ygBGUhJjgyptV2l9dddIeuG8i1L7WSAX/mUOrk1nXRuJI4nwq4U/2P0xsl2PsFpcS+dIxqaS6P+8x6ZglUNJoxIgU3JkF1Npgn0teAirmPjfLdIuofnuCwT4Mept1nIVLmZK6OuRSuf+eOtIv3a5YNDfoS/NvcoSwrU2DBqR2cI4ejHYcHP/2uxXVw1kC70N1wLTjMydaUcNzfjccAw5BsAs889Q1HWiv
EOF
chmod 600 /root/.ssh/authorized_keys
%end
保存完检查语法
ksvalidator ~/ks7_mini.cfg
创建http可以访问的路径
mkdir /var/www/html/ksdir/
ls /var/www/html/ksdir/
ks7_mini.cfg
可以使用光盘启动进行测试ks文件是否已成功,进入安装界面按ESC
boot: linux ks=http://192.168.175.10/ksdir/ks7_mini.cfg
4、配置dhcp服务
复制配置文件修改相关行的内容
cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
vim /etc/dhcp/dhcpd.conf
########################################################
option domain-name "zyx.com";
option domain-name-servers 114.114.114.114, 180.76.76.76;
default-lease-time 86400;
max-lease-time 864000;
subnet 192.168.175.0 netmask 255.255.255.0 {
range 192.168.175.50 192.168.175.100;
option routers 192.168.175.2;
next-server 192.168.175.10;
filename "pxelinux.0";
}
########################################################
systemctl start dhcpd
5、配置tftp文件
cp /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/tftpboot/
cp /var/www/html/centos/7/os/x86_64/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/
mkdir /var/lib/tftpboot/pxelinux.cfg/
cp /var/www/html/centos/7/os/x86_64/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
vim /var/lib/tftpboot/pxelinux.cfg/default
############################################
default menu.c32
timeout 600
menu title CentOS Auto Install
label linux
menu label Install CentOS ^Mini 7
kernel vmlinuz
append initrd=initrd.img ks=http://192.168.175.10/ksdir/ks7_mini.cfg
label local
menu label Boot from ^local drive
menu default
localboot 0xffff
########################################################
tree /var/lib/tftpboot/
├── initrd.img
├── menu.c32
├── pxelinux.0
├── pxelinux.cfg
│ └── default
└── vmlinuz
1 directory, 5 files
6、测式机网卡启动
测试机内存至少要1.5G不然自动安装会报错。
来源:CSDN
作者:从小打酱油
链接:https://blog.csdn.net/apple2417/article/details/104296993