PXE+Kickstart批量无人值守部署

#PXE+TFTP+DHCP+HTTP+KICKSTART

1.关闭防火墙和SELinux
systemctl stop firewalld
setenforce 0

2.DHCP
#DHCP主要是提供客户端网络参数与TFTP的位置,以及boot loader的文件名
yum install dhcp -y
vi /etc/dhcp/dhcpd.conf
subnet 192.168.5.0 netmask 255.255.255.0 { #设置网段
option routers 192.168.5.2; #设置网关
option subnet-mask 255.255.255.0; #设置子网掩码
option domain-name-servers 192.168.5.2; #设置dns服务器地址
range dynamic-bootp 192.168.5.200 192.168.5.205; #IP地址租用的范围
default-lease-time 21600; #默认租约时间
max-lease-time 43200; #最大租约时间
next-server 192.168.5.184; #tftp服务器地址
filename "pxelinux.0"; #tftp服务器根目录下面的文件名
}
systemctl start dhcpd
systemctl enable dhcpd

3.TFTP
#boot loader文件pxelinux.0以及内核相关的配置文件(目录pxelinux.cfg下)主要都是由TFTP来提 供的!
yum install tftp-server xinetd -y
vim /etc/xinetd.d/tftp
disable = no #此项修改,其它不变;保存退出
systemctl restart xinetd
systemctl enable xinetd

4.PXE的bootloader和相关配置文件
#syslinux是一个功能强大的引导加载程序,而且兼容各种介质。更加确切地说:SYSLINUX是一个小型的Linux操作系统,它的目的是简化首次安装Linux的时间,并建立修护或其它特殊用途的启动盘
yum install syslinux -y
cd /var/lib/tftpboot
cp /usr/share/syslinux/pxelinux.0 .
cp /mnt/images/pxeboot/{vmlinuz,initrd.img} .
cp /mnt/isolinux/{vesamenu.c32,boot.msg} .
mkdir pxelinux.cfg
cp /mnt/isolinux/isolinux.cfg pxelinux.cfg/default

vi pxelinux.cfg/default #删除60行之后的,在文件末尾添加以下内容;也可自己编写
label linux
menu label ^Install CentOS 74
kernel vmlinuz
append initrd=initrd.img ks=http:/ /192.168.5.184/config/ks.cfg biosdevname=0 net.ifnames=0

5.HTTP
#通过HTTP协议把光盘镜像内容传给客户端
yum install httpd -y
cp -rf /mnt/* /var/www/html/
mkdir -p /var/www/html/config #新建目录,把自定义的文件、脚本等放置于此

6.Kickstart配置文件
vi /var/www/html/config/ks.cfg
#platform=x86, AMD64 或 Intel EM64T
#version=
# Firewall configuration
firewall --disabled

# Install OS instead of upgrade
install

# Use network installation
url --url="http:// 192.168.5.184/"
#!!!

# Use CDROM installation media
repo --name="yum" --baseurl=http:// 192.168.5.184/
#!!!

# Root password
rootpw --iscrypted $1$mi4lP.ZY$j5UDGX34knfGuSYPwd82u/ #redhat
# openssl passwd -1 # 加密算法

# Use graphical install graphical or text
text

# Run the Setup Agent on first boot
firstboot --disable

# System keyboard
keyboard us

# System language
lang en_US.UTF-8

# SELinux configuration
selinux --disabled

# Reboot after installation
reboot

# System timezone
timezone --isUtc Asia/Shanghai

# Network information
network --bootproto=dhcp --device=eth0 --noipv6 --activate
network --hostname=web
#!!!

# System bootloader configuration
bootloader --location=mbr

# Clear the Master Boot Record
zerombr

# Partition clearing information
clearpart --all --initlabel
#!!!

# Disk partitioning information
part /boot --asprimary --fstype="ext4" --ondisk=sda --size=200
part swap --fstype="swap" --ondisk=sda --size=4096
part / --fstype="ext4" --ondisk=sda --size=20480
#!!!

%packages
@core
wget
%end

%post
#yum_client
cd /etc/yum.repos.d/
rm -rf *
wget http:// 192.168.5.184/config/client.repo‘
yum install httpd -y
cd /var/www/html/
systemctl restart httpd
echo "hello world" >> /var/www/html/index.html
%end

%addon com_redhat_kdump --disable --reserve-mb='auto'
%end

7.测试(客户端启动方式应更改为PXE网络启动!)

猜你喜欢

转载自blog.csdn.net/Wxq960906/article/details/80367439