脚本使用
- 修改prefix(ip前三位)
- 修改master,node1, node2 各节点ip号
- 修改gateway地址
- 修改各节点登录账号(本人使用的统一root账号)
执行
注意:执行时会重启节点网络
#!/bin/bash
#prefix="192.168.31"
#prefix="192.168.1"
prefix="192.168.244"
master="$prefix.100"
node1="$prefix.101"
node2="$prefix.102"
gateway="$prefix.92"
# replace ipaddr
sed -i "s/^IPADDR.*$/IPADDR=$master/g" /etc/sysconfig/network-scripts/ifcfg-ens33
echo "replace network[ipaddr] $master"
# replace gateway $prefix.1
# for example 192.168.31.1
sed -i "s/^GATEWAY.*$/GATEWAY=$gateway/g" /etc/sysconfig/network-scripts/ifcfg-ens33
echo "replace network[gateway] $gateway"
# replace hosts
sed -i "s/^192.*k8s-master$/$master k8s-master/g" /etc/hosts
sed -i "s/^192.*k8s-node1$/$node1 k8s-node1/g" /etc/hosts
sed -i "s/^192.*k8s-node2$/$node2 k8s-node2/g" /etc/hosts
echo "replace hosts file"
# restart network service
systemctl restart network
echo "restart network service"
# distribute hosts to cluster
`scp /etc/hosts root@$node2:/etc/hosts`
`scp /etc/hosts root@$node1:/etc/hosts`
echo "distribute hosts to cluster"