编辑ks.cfg
#############
#version v1.1
#Date 2019-05-02
#############
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
Install OS instead of upgrade
install
Use network installation
url --url=“http://192.168.33.10/centos-1708/”
Keyboard layouts
keyboard ‘us’
Root password
rootpw ctyun@8989
System timezone
timezone Asia/Shanghai
System language
lang en_US
Firewall configuration
firewall --disabled
System authorization information
auth --useshadow --passalgo=sha512
Use text mode install
#text
graphical
SELinux configuration
selinux --disabled
Do not configure the X Window System
skipx
System bootloader configuration
bootloader --location=mbr --boot-drive=sda
Partition clearing information
clearpart --all --initlabel
Disk partitioning information
part / --fstype=“xfs” --ondisk=sda --size=51200
part /var --fstype=“xfs” --ondisk=sda --grow --size=1
%packages
@^minimal
@core
@base
chrony
libconfig
lldpad
ntpdate
%end
%post
mkdir /etc/yum.repos.d/C.bak
mv /etc/yum.repos.d/C* /etc/yum.repos.d/C.bak
cat >> /etc/yum.repos.d/base.repo << EOF
[base]
name=base
baseurl=http://136.160.161.14/centos_7.4/
enabled=1
gpgcheck=0
EOF
cat >> /var/spool/cron/root << EOF
0-59/10 * * * * /usr/sbin/ntpdate 136.160.161.14
EOF
wget -P /root http://192.168.33.10/ip.txt 2>> /root/out.txt
v_serial=dmidecode -s system-serial-number | tail -n 1
2>> /root/out.txt
v_line=wc -l /root/ip.txt | cut -d ' ' -f 1
2>> /root/out.txt
NETWORK="/etc/sysconfig/network" 2>> /root/out.txt
let “v_line+=1” 2>> /root/out.txt
for((i=1;i<$v_line;i++));
do
v_ip_serial=cat /root/ip.txt | head -n $i | tail -n 1 | cut -d '/' -f 1
2>> /root/out.txt
if [ “
v
s
e
r
i
a
l
"
=
"
v_serial" = "
vserial"="v_ip_serial” ];then
v_host=cat /root/ip.txt | head -n $i | tail -n 1 | cut -d '/' -f 2
2>> /root/out.txt
v_ip=cat /root/ip.txt | head -n $i | tail -n 1 | cut -d '/' -f 3
2>> /root/out.txt
v_mask=cat /root/ip.txt | head -n $i | tail -n 1 | cut -d '/' -f 4
2>> /root/out.txt
v_gw=cat /root/ip.txt | head -n $i | tail -n 1 | cut -d '/' -f 5
2>> /root/out.txt
fi
done
#mode=1 active-backup
BOND1=“bond1”
mkdir /root/network-backup
for n in $(ip addr|grep mtu|grep -v lo |awk -F ‘[ |:]’ ‘{print $3}’)
do
case
n
i
n
e
m
2
)
c
p
/
e
t
c
/
s
y
s
c
o
n
f
i
g
/
n
e
t
w
o
r
k
−
s
c
r
i
p
t
s
/
i
f
c
f
g
−
n in em2) cp /etc/sysconfig/network-scripts/ifcfg-
ninem2)cp/etc/sysconfig/network−scripts/ifcfg−{n} /root/network-backup/ifcfg-
n
‘
d
a
t
e
+
e
c
h
o
−
e
"
D
E
V
I
C
E
=
{n}_`date +%Y%m%d%H_%H%M%s` &>/dev/null echo -e "DEVICE=
n‘date+echo−e"DEVICE={n}\nTYPE=Ethernet\nONBOOT=yes\nBOOTPROTO=none\nMASTER=KaTeX parse error: Undefined control sequence: \nSLAVE at position 8: {BOND1}\̲n̲S̲L̲A̲V̲E̲=yes" > /etc/sy…{n}
echo -e “bond-
B
O
N
D
1
−
{BOND1}-
BOND1−{n}\n”>>/root/network-backup/bond.cfg
;;
p4p1)
cp /etc/sysconfig/network-scripts/ifcfg-
n
/
r
o
o
t
/
n
e
t
w
o
r
k
−
b
a
c
k
u
p
/
i
f
c
f
g
−
{n} /root/network-backup/ifcfg-
n/root/network−backup/ifcfg−{n}_date +%Y%m%d%H_%H%M%s
&>/dev/null
echo -e “DEVICE=KaTeX parse error: Undefined control sequence: \nTYPE at position 4: {n}\̲n̲T̲Y̲P̲E̲=Ethernet\nONBO…{BOND1}\nSLAVE=yes” > /etc/sysconfig/network-scripts/ifcfg-
n
e
c
h
o
−
e
"
b
o
n
d
−
{n} echo -e "bond-
necho−e"bond−{BOND1}-KaTeX parse error: Undefined control sequence: \n at position 4: {n}\̲n̲">>/root/networ…{BOND1}\nONBOOT=yes\nBOOTPROTO=none\nIPADDR=KaTeX parse error: Undefined control sequence: \nNETMASK at position 7: {v_ip}\̲n̲N̲E̲T̲M̲A̲S̲K̲={v_mask}\nGATEWAY=KaTeX parse error: Undefined control sequence: \nIPV at position 7: {v_gw}\̲n̲I̲P̲V̲6INIT=no\nBONDI…{BOND1}
echo -e “${v_host}” >/etc/hostname
systemctl restart network
rm -rf /root/ip.txt
rm -rf /root/out.txt
systemctl start lldpad
systemctl enable lldpad
for i in ls /sys/class/net/ | grep 'eth\|ens\|eno\|p\|enp\|em'
;
do echo “enabling lldp for interface: $i”;
lldptool set-lldp -i $i adminStatus=rxtx;
lldptool -T -i $i -V sysName enableTx=yes;
lldptool -T -i $i -V portDesc enableTx=yes;
lldptool -T -i $i -V sysDesc enableTx=yes;
lldptool -T -i $i -V sysCap enableTx=yes;
lldptool -T -i $i -V mngAddr enableTx=yes;
done
%end
reboot
#############################################
ip.txt格式
序列号/主机名/ip/netmask/gateway