PXE自动化安装CentOS6/7
服务器为centos7
安装前准备:关闭防火墙和SELINUX
虚拟机准备第二块网卡,设置主机模式,关闭虚拟机网络配置中主机模式的DHCP功能,并设置静态IP
nmcli c a con-name ens37-dhcp type ethernet ifname ens37 ipv4.method manual ipv4.addresses 192.168.47.10/24 ipv4.gateway 192.168.47.1 ipv4.dns 114.114.114.114 connection.autoconnect yes
安装软件包
dhcp,httpd,tftp-server,syslinux,system-config-kickstart
配置dhcp:
vim /etc/dhcp/dhcpd.conf
option domain-name "linux123.tech"; 设置域名
option domain-name-servers 114.114.114.114, 8.8.8.8; DNS服务器,可以不要
default-lease-time 8560; 最长租约
max-lease-time 15400; 特殊情况的最长租约
subnet 192.168.47.0 netmask 255.255.255.0 { DHCP服务网段
range 192.168.47.50 192.168.47.100; 分配地址范围
filename "pxelinux.0"; 系统安装文件名
next-server 192.168.47.10; tftp服务器地址
}
systemctl start dhcpd 启动服务
用另一台主机模式的虚拟机自动获取IP,测试DHCP服务是否正常,
配置httpd
在目录下设置创建放置ISO文件和KS文件的目录
cd /var/www/html/
mkdir ksdir 创建ks文件夹
cp /root/ks7-* /var/www/html/ksdir/ 将制作好的ks文件拷入ks7-desktop.cfg,ks7-mini.cfg,ks6-mini.cfg
mkdir centos/7 -p
mkdir centos/6
mount /dev/sr1 centos/7 挂载centos7安装盘到网络路径
mount /dev/sr2 centos/6 挂载centos6
配置tftp
cd /var/lib/tftpboot/
rpm -ql syslinux 找到pxelinux.0和menu.c32的路径
cp /usr/share/syslinux/{pxelinux.0,menu.c32} .
cp /var/www/http/centos/6/isolinux/{vmlinuz,initrd.img} .6/ 从centos6光盘中拷贝驱动文件
cp /var/www/http/centos/7/isolinux/{vmlinuz,initrd.img} .7/ 从centos7光盘中拷贝驱动文件
mkdir pxelinux.cfg
cp /mnt/cd/isolinux/isolinux.cfg pxelinux.cfg/default 启动菜单
vim pxelinux.cfg/default 修改启动菜单项
default menu.c32
timeout 600
label linux
menu label Install ^Desktop CentOS 7
kernel 7/vmlinuz
append initrd=7/initrd.img ks=http://192.168.47.10/ksdir/k7-desktop.cfg
label check
menu label Install ^Mini CentOS 7
kernel 7/vmlinuz
append initrd=7/initrd.img ks=http://192.168.47.10/ksdir/k7-mini.cfg
label check
menu label Install ^Mini CentOS 7
kernel 6/vmlinuz
append initrd=6/initrd.img ks=http://192.168.47.10/ksdir/k6-mini.cfg
label local
menu default
menu label Boot from ^local drive
localboot 0xffff
menu end
最后,确保防火墙和selinux关闭
打开三项服务
systemctl httpd dhcpd tftp.service
空白虚拟机开机,centos7图形虚拟机的内存需要大于1.1G以上,磁盘空间也要大于分区的空间,否则会报错失败。
ks7-desktop.cfg ks7-mini.cfg相比较只是少了几个包,自行删除几个不需要的就可以了。
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
url --url=http://192.168.47.10/centos/7
# Use graphical install
firewall --disabled
selinux --disabled
text
reboot
# Run the Setup Agent on first boot
firstboot --disable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8
# Network information
network --bootproto=dhcp --device=ens33 --onboot=on --ipv6=auto --activate
network --hostname=centos7.magedu.com
# Root password
rootpw --plaintext 1234567890
# System services
services --disabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc --nontp
# X Window System configuration information
xconfig --startxonboot
# System bootloader configuration
bootloader --location=mbr --boot-drive=sda
# Partition clearing information
zerombr
clearpart --all --initlabel
# Disk partitioning information
part swap --fstype="swap" --ondisk=sda --size=2048
part /boot --fstype="xfs" --ondisk=sda --size=1024
part / --fstype="xfs" --ondisk=sda --size=51200
part /app --fstype="xfs" --ondisk=sda --size=20480
eula --agreed
%packages
@base
@core
@dial-up
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@internet-browser
@multimedia
@network-file-system-client
@networkmanager-submodules
@x11
%end
%addon com_redhat_kdump --disable --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
%post
systemctl default multi-user.target
%end
ks6-mini.cfg
# Kickstart file automatically generated by anaconda.
#version=DEVEL
install
reboot
text
url --url=http://192.168.47.10/centos/6/
lang en_US.UTF-8
keyboard us
network --onboot yes --device eth0 --bootproto dhcp --noipv6
rootpw --plaintext 6803154
firewall --disabled
authconfig --enableshadow --passalgo=sha512
selinux --disabled
timezone Asia/Shanghai
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
clearpart --all
zerombr
part /boot --fstype=ext4 --size=1024
part / --fstype=ext4 --size=50000
part /app --fstype=ext4 --size=20000
part swap --size=2048
%packages
@base
@core
@debugging
%end