CentOS7 PXE kickstart 自动安装
PXE自动安装
CentOS环境
CentOS7 + dhcpd + tftp + kickstart + http
关闭VMnet8的DHCP服务
同一个网段只能由一个DHCP服务
编辑-虚拟网络编辑器-点击"更改设置"按钮-选中"VMnet8"网卡-取消勾选"使用本地DHCP服务将IP地址分配给虚拟机(D)"
关闭SELinux
setenforce 0
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/sysconfig/selinux
关闭防火墙
systemctl disable firewalld
systemctl stop firewalld
systemctl status firewalld
修改源
mv -f /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
curl -o /etc/yum.repos.d/CentOS7-Base-163.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
yum clean all
yum makecache
安装DHCP服务
yum install -y dhcp
配置DHCP
修改网段 192.168.123 为自己的网段
cat > /etc/dhcp/dhcpd.conf << EOF
subnet 192.168.123.0 netmask 255.255.255.0 {
option routers 192.168.123.2; # 网关
option subnet-mask 255.255.255.0; # 子网掩码
option broadcast-address 192.168.123.255; # 广播地址
option domain-name-servers 8.8.8.8,114,114,114,114; # dns服务器
range 192.168.123.100 192.168.123.199; # 分配IP地址段
default-lease-time 7200; # 租约默认两小时
max-lease-time 86400; # 租约最大一天
next-server 192.168.123.10; # tftp服务器的ip地址
filename "pxelinux.0"; # tftp中默认的文件
}
EOF
DHCP服务设置
systemctl enable dhcpd
systemctl start dhcpd
systemctl status dhcpd
安装tftp服务器
yum install -y tftp-server
systemctl enable tftp.socket
systemctl start tftp.socket
systemctl status tftp.socket
安装syslinux
yum install -y syslinux
复制文件
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
挂载CentOS7安装光盘
mkdir -p /var/www/html/CentOS7/
mount /dev/cdrom /var/www/html/CentOS7/
复制文件
cp -a /var/www/html/CentOS7/isolinux/* /var/lib/tftpboot/
安装httpd服务器
yum install -y httpd
systemctl enable httpd
systemctl start httpd
systemctl status httpd
创建自动安装引导文件
创建目录
mkdir -p /var/lib/tftpboot/pxelinux.cfg
引导文件 默认名称: /var/lib/tftpboot/pxelinux.cfg/01-横线连接的小写mac地址
# 注意mac地址都是小写
cat > /var/lib/tftpboot/pxelinux.cfg/01-00-50-56-22-e7-67 << EOF
default 0
prompt 0 # 是否开启
label 0
kernel vmlinuz
append initrd=initrd.img ks=http://192.168.123.10/install/00-50-56-22-e7-67.cfg
EOF
自动安装脚本
创建目录
mkdir -p /var/www/html/install/
创建自动安装脚本
# 注意mac地址都是小写
cat > /var/www/html/install/00-50-56-22-e7-67.cfg << EOF
#version=DEVEL
# Install OS instead of upgrade
install
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
#cdrom
url --url=http://192.168.123.10/CentOS7/
# Use graphical install
#graphical
text
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=cn --xlayouts='cn'
# System language
lang zh_CN.UTF-8
# Network information
network --bootproto=static --gateway=192.168.123.2 --ip=192.168.123.21 --nameserver=8.8.8.8,114.114.114.114 --netmask=255.255.255.0 --ipv6=auto --activate
network --hostname=node21
# Root password
rootpw --iscrypted \$6\$Ar./FLKMHZs4NRKy\$CxuGZfHZFlGlrTjV4pj/cF7kUOOIKWiwM9UuFoyGqmm3GcRkKGP63fY5RrluevWH1ulU7C3DWXWlZ/Wiwhox8.
# System services
services --enabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
autopart --type=lvm
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Reboot after installation
reboot
%packages
@^minimal
@core
chrony
kexec-tools
%end
%addon com_redhat_kdump --enable --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
%pre
# Linux script command executed before system installation
%end
%post
# Linux script command executed after system installation
%end
EOF
加密密码生成
python3 -c 'import crypt; print(crypt.crypt("123456"))'
windows环境
windows + tftpd32 + kickstart + http
关闭VMnet8的DHCP服务
同一个网段只能由一个DHCP服务
编辑-虚拟网络编辑器-点击"更改设置"按钮-选中"VMnet8"网卡-取消勾选"使用本地DHCP服务将IP地址分配给虚拟机(D)"
下载tftpd软件
下载地址 http://tftpd32.jounin.net/tftpd32_download.html
安装目录 C:\tftpd64.462\
创建目录
tftpd根目录 C:\tftpd64.462\root\
pxelinux.cfg目录 C:\tftpd64.462\root\pxelinux.cfg\
配置tftpd
提取文件
打开文件CentOS-7-x86_64-Minimal-1810.iso的images\pxeboot目录
复制 initrd.img vmlinuz 到tftpd根目录 C:\tftpd64.462\root\
pxelinux.0文件
复制pxelinux.0文件到根目录
# 需要找一个安装好的CentOS系统
yum install -y syslinux
文件 /usr/share/syslinux/pxelinux.0
就是
可以在这里下载 http://www.dotcoo.com/upload/pxelinux.0 CentOS7的其他系统没有测试过
创建pxe引导文件
创建文件
C:\tftpd64.462\root\pxelinux.cfg\01-00-50-56-3e-cd-90
文件内容
default 0
prompt 0
label 0
kernel vmlinuz
append initrd=initrd.img ks=http://192.168.123.1/install/01-00-50-56-3e-cd-90.cfg
nginx服务器
下载nginx的windows版本
解压到 C:\nginx-1.14.2
双击 nginx.exe
启动 nginx
解压iso镜像
解压iso镜像到 C:\nginx-1.14.2\html\CentOS7
目录下
创建自动安装文件
创建 C:\nginx-1.14.2\html\install
目录
创建 C:\nginx-1.14.2\html\install\00-50-56-3e-cd-90.cfg
文件
内容如下
#version=DEVEL
# Install OS instead of upgrade
install
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
#cdrom
url --url=http://192.168.123.1/CentOS7/
# Use graphical install
#graphical
text
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=cn --xlayouts='cn'
# System language
lang zh_CN.UTF-8
# Network information
network --bootproto=static --gateway=192.168.123.2 --ip=192.168.123.23 --nameserver=8.8.8.8,114.114.114.114 --netmask=255.255.255.0 --ipv6=auto --activate
network --hostname=node23
# Root password
rootpw --iscrypted $6$Ar./FLKMHZs4NRKy$CxuGZfHZFlGlrTjV4pj/cF7kUOOIKWiwM9UuFoyGqmm3GcRkKGP63fY5RrluevWH1ulU7C3DWXWlZ/Wiwhox8.
# System services
services --enabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
autopart --type=lvm
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Reboot after installation
reboot
%packages
@^minimal
@core
chrony
kexec-tools
%end
%addon com_redhat_kdump --enable --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
%pre
# Linux script command executed before system installation
%end
%post
# Linux script command executed after system installation
%end
提示
安装记得关闭杀毒软件的"实时保护"