PXE+Kickstart实现批量化无人值守安装

centos7下进行kickstart配置

配置kickstart时需要pxe芯片,为获取ip地址

1、先安装dhcpd服务器

yum install -y dhcpd

1-1.配置dhcp的配置文件

    # cat /etc/dhcp/dhcpd.conf
subnet 172.16.1.0 netmask 255.255.255.0 {
range 172.16.1.85 172.16.1.95;
option subnet-mask 255.255.255.0;
default-lease-time 21600;
max-lease-time 43200;
next-server 172.16.1.80;
filename "/pxelinux.0";
}

1-2.启动dhcpd服务

systemctl start dhcpd.service

systemctl enable dhcpd.service

1-3.安装lsof软件

yum install -y lsof

1-4.查看dhcpd启动情况

    [root@centos7-4 dhcp]# lsof -i :67
COMMAND PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
dhcpd   7865 dhcpd   7u IPv4 43468     0t0 UDP *:bootps

1-5.挂载光盘

#mount /dev/centos7 /var/www/html/centos7

2、安装tftp服务

yum install -y xinetd tftp-server httpd

2-1、进行xinetd的配置

[root@centos7-4 xinetd.d]# cat /etc/xinetd.d/tftp   #查看tftp在xinetd下的配置
# default: off
# description: The tftp server serves files using the trivial file transfer
# protocol. The tftp protocol is often used to boot diskless
# workstations, download configuration files to network-aware printers,
# and to start the installation process for some operating systems.
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot #/var/lib/tftpboot启动文件目录
disable = no #允许使用xinetd来启动tftp
per_source = 11
cps = 100 2
flags = IPv4
}

2-2、配置好了tftp服务后,并重新启动一下xinetd服务

systemctl restart xinetd #tftp服务受xinetd服务管理的

lsof -i :69

3、拷贝重要的文件

# cd /var/www/html/centos7/isolinux/
# cp vmlinuz /var/lib/tftpboot/ #其中vmlinuz为linux启动的内核文件
# cp initrd.img /var/lib/tftpboot #initrd.img为linux启动的驱动文件
# cp vesamenu.c32 /var/lib/tftpboot/ #启动框架文件

4、安装syslinux软件,取出pxelinux.0文件

#yum install -y syslinux
#rpm -ql syslinux
# cd /usr/share/syslinux/
# mkdir -p /var/lib/tftpboot/pxelinux.cfg #新建目录pxelinux.cfg
# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ #linux启动代码
#cd /var/www/html/centos7/isolinux
# cp isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default #拷贝isolinux.cfg到此目录下,并命令为default
# cp reboot.c32 /var/lib/tftpboot/ #把重启框架文件拷贝到/var/lib/tftpboot目录中

5、配置default文件

# cat /var/lib/tftpboot/pxelinux.cfg/default 
#kickstart centos7 configure by gordon.wang
default linux
timeout 50
prompt 0
label linux #要与default显示的字符一致
kernel vmlinuz
append initrd=initrd.img ks=http://172.16.1.80/ks_config/centos7-ks.cfg ksdevice=eth1 net.ifnames=0 biosdevname=0 #把网卡名由ens变更为eth,并从cento7-ks.cfg中引导启动;

6、配置centos7-ks.cfg文件

# cat  /var/www/html/ks_config/centos7-ks.cfg 
#kickstart centos7 configure by gordon.wang
install
url --url="http://172.16.1.80/centos7/"
text
lang en_US.UTF-8
keyboard us
zerombr #初始化所有可在磁盘中找到的有效分区表
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
network --bootproto=static --device=eth0 --gateway=10.0.0.254 --ip=10.0.0.85 --nameserver=223.5.5.5 --netmask=255.255.255.0 --activate
network --bootproto=static device=eth1 --ip=172.16.1.85 --netmask=255.255.255.0 --activate
network --hostname=kickstart
timezone --utc Asia/Shanghai
authconfig --enableshadow --passalgo=sha512 #authconfig为系统设置认证选项,--enableshadow为使用影子密码
rootpw --iscrypted $6$X20eRtuZhkHznTb4$dK0BJByOSAWSDD8jccLVFz0CscijS9ldMWwpoCw/ZEjYw2BTQYGWlgKsn945fFTjRC658UXjuocwJbAjVI5D6/ #rootpw --iscrypted加密密码参数
加密命令:python -c 'import crypt;print(crypt.crypt("my passwd"))',其中my passwd为要设置的密码
clearpart --all --initlabel #clearpart从系统中删除分区要在生成新分区之前完成;
part /boot --fstype xfs --size 1024
part swap --size 1024
part / --fstype xfs --size 1 --grow #参数--grow是把硬盘所有的容量全部给/
firstboot --disable #禁用initial setup程序在第一次引导系统时启动;
selinux --disabled
firewall --disabled
logging --level=info #logging在安装过程中anaconda出错日志
reboot

%packages
@^minimal
@compat-libraries
@debugging
@development
tree
nmap
sysstat
lrzsz
dos2unix
telnet
wget
vim
bash-completion
net-tools
%end

%post
systemctl disable postfix.service
%end

7、启动httpd服务

#如果没有安装httpd服务,请执行安装服务

#yum install -y httpd

#systemctl start httpd

#lsof -i :80

#curl http://172.16.1.80/centos7 #检查网站

8、现在就进行安装就可以了;

 

原文地址:https://www.cnblogs.com/wang50902/p/11075760.html