​ 公司生产环境每次安装新服务器之后都会安装salt,配置hostname、bond等。刚好自己最近在学习shell。然后就有了下面的脚本。(如果有需要还可以扩展安装zabbix-agent、Megacli等。)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
#=========set hostname====================
stty erase ^H #避免read交互是按退格键出现 ^H
read -p "Please enter hostname:" hostname
hostnamectl set-hostname $hostname

#=========config bond=====================
stty erase ^H
read -p "Please enter your IP:" ip
GW=`echo $ip |awk -F "." '{print $1"."$2"."$3"."1}'`

/usr/bin/ping -c 3 $ip > /dev/null 2>&1
if [ $? -eq 0 ];then
echo "$ip existing"
exit 1
else
echo "ip ok!"
fi

cat > /etc/sysconfig/network-scripts/ifcfg-eth0 << EOF
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
MASTER=bond0
SLAVE=yes
EOF

cat > /etc/sysconfig/network-scripts/ifcfg-bond0 << EOF
DEVICE=bond0
ONBOOT=yes
BOOTPROTO=static
IPADDR=$ip
NETMASK=255.255.255.0
GATEWAY=$GW
DNS1=114.114.114.114
EOF

cat > /etc/sysconfig/network-scripts/ifcfg-eth1 << EOF
DEVICE=eth1
ONBOOT=yes
BOOTPROTO=static
MASTER=bond1
SLAVE=yes
EOF

cat > /etc/sysconfig/network-scripts/ifcfg-bond1 << EOF
DEVICE=bond1
ONBOOT=yes
BOOTPROTO=static
EOF

cat > /etc/modprobe.d/bonding.conf << EOF
alias bond0 bonding
options bond0 miimon=100 mode=0
alias bond1 bonding
options bond1 miimon=100 mode=0
EOF

systemctl stop NetworkManager
systemctl disable NetworkManager
systemctl restart network
sleep 3

#===================install salt=====================
yum install -y salt-minion
sleep 1
sed -i 's/#master: salt/master: ip/g' /etc/salt/minion #这里的ip替换成你的masterip地址
sed -i "s/#id:/id: $hostname/g" /etc/salt/minion
sleep 1

systemctl enable salt-minion
systemctl start salt-minion