PXE下无人值守配置阵列及安装CentOS7
猫先生 • 2019 年 09 月 24 日
客户采购200台联想服务器,现在需要安装系统, 一台一台的用优盘安装,显然不是最佳办法,PXE安装肯定是首选,但是还是得一台一台配置阵列,这样,明显效率不高。我百度、谷歌了下,发现pxe下可以配置阵列,但是都比较复杂,大致思路都是先用一个类似于live os引导进去,先执行相应的命令,然后再重启。再次引导pxe 进行安装,这显然也很麻烦,我整理了一套非常简单的方法。
原理:利用kickstart文件中的pre执行命令,在安装前调用阵列卡的配置程序,用命令配置阵列。配置完阵列,然后安装系统,都不用重启,也不用引导精简版的Linux。
安装PXE服务器的文档,充斥在全网的各个角落,我就不写了,我这里只贴出我的配置文件作为参考
1,dhcp配置文件option space PXE;
option PXE.mtftp-ip code 1 = ip-address;
option PXE.mtftp-cport code 2 = unsigned integer 16;
option PXE.mtftp-sport code 3 = unsigned integer 16;
option PXE.mtftp-tmout code 4 = unsigned integer 8;
option PXE.mtftp-delay code 5 = unsigned integer 8;
option client-system-arch code 93 = unsigned integer 16;
allow booting;
allow bootp;
default-lease-time 3600;
max-lease-time 21600;
subnet 192.168.70.0 netmask 255.255.255.0{
range 192.168.70.10 192.168.70.200;
option routers 192.168.70.1;
class "pxeclients" {
match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
next-server 192.168.70.2;
if option client-system-arch = 00:07 or option client-system-arch = 00:09 {
filename "uefi/bootx64.efi";
} else {
filename "pxelinux.0";
}
}
}
2,kickstart配置文件#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use network installation
url --url="http://192.168.70.1/centos76/"
# Use graphical install
graphical
# Run the Setup Agent on first boot
firstboot --disable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard 'us'
# System language
lang zh_CN.UTF-8
#config raid
%pre
wget http://192.168.70.1/rdconfig/rdconfig.sh
cp rdconfig.sh /tmp/
chmod a+x /tmp/rdconfig.sh
/tmp/rdconfig.sh
sleep 12
%end
# Network information
network --bootproto=dhcp --onboot=on --noipv6
network --hostname=server
# Reboot after installation
reboot
# Root password
rootpw --iscrypted $6$sgwDN64lfSiJ2b01$Q3k/pI26guRqkmTu14gn1T6auyqYSPTvxQJUValIdAQv7eHEiXbjjBgpMahTJbUCr1sGC3sq0DQnTPp985IUd1
# System services
services --enabled="chronyd"
# System timezone
timezone Asia/Shanghai
user --name=admin --password=$6$Co8MpRTqRc1LZ2CY$hWwoGvJ1xzFmYDPeZPTx9HIY/zrXpud6LMRLYfbg..RhMSYybpB8Y2Pz/qRlu4MOl3Q1h68OSfFsXnP.eTU6Z. --iscrypted --gecos="admin"
# X Window System configuration information
xconfig --startxonboot
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot/efi --fstype="efi" --ondisk=sda --size=500 --fsoptions="umask=0077,shortname=winnt"
part /boot --fstype="xfs" --ondisk=sda --size=1024
part pv.168 --fstype="lvmpv" --ondisk=sda --grow --size=1
volgroup centos --pesize=4096 pv.168
logvol swap --fstype="swap" --size=20480 --name=swap --vgname=centos
logvol / --fstype="xfs" --size=204800 --name=root --vgname=centos
logvol /data --fstype="xfs" --name=data --vgname=centos --grow --size=1
#Accept license
eula --agreed
%packages
@^graphical-server-environment
@base
@core
@desktop-debugging
@dial-up
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@hardware-monitoring
@input-methods
@internet-browser
@multimedia
@print-client
@x11
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
#config yum
%post
wget http://192.168.70.1/script/script.sh
cp script.sh /tmp/
chmod a+x /tmp/script.sh
/tmp/script.sh
rm -fr /tmp/script.sh
%end
3,rdconfig配置文件 配置raidwget http://192.168.70.1/rdconfig/storcli /
sleep 3
cp /storcli /usr/bin
chmod +x /usr/bin/storcli
sleep 3
storcli /c0 add vd type=raid5 size=all names=raid5 drive=62:0-6
sleep 3
storcli /c0/e62/s7 add hotsparedrive
4,自动配置yum脚本#!/bin/bash
#mount nfs
mkdir /yumdata
mkdir /tmp/nfs
mount -t nfs 192.168.70.1:/iso /tmp/nfs
cp -vr /tmp/nfs/centos76/* /yumdata
#config yum
cd /etc/yum.repos.d/
mkdir bak
mv *.repo bak
> local.repo
cat >> local.repo << "EOF"
[local]
name=local
baseurl=file:///yumdata
enabled=1
gpgcheck=0
EOF
umount /tmp/nfs
5,grub.cfg 配置文件set default="0"
function load_video {
insmod efi_gop
insmod efi_uga
insmod video_bochs
insmod video_cirrus
insmod all_video
}
load_video
set gfxpayload=keep
insmod gzio
insmod part_gpt
insmod ext2
set timeout=10
### END /etc/grub.d/00_header ###
search --no-floppy --set=root -l 'CentOS 7 x86_64'
### BEGIN /etc/grub.d/10_linux ###
menuentry 'Install CentOS 7.6' --class fedora --class gnu-linux --class gnu --class os {
linuxefi uefi/vmlinuz inst.repo=http://192.168.70.1/centos76/ inst.ks=http://192.168.70.1/kscfg/ct76ks.cfg
initrdefi uefi/initrd.img
}
备注:配置阵列的命令中用到的eid 和sid 需要提前查看。配置好脚本,服务器开机等着就行,kickstart还能干更多的事,来简化配置工作。