Commit a9ba7a5b by tingweiwang

自动根据脚本中new_node节点清单,自动配置ansible hosts,需要注意如果节点已加入集群,需要将已加入节点注释掉,然后再执行add_node.sh否则已加入的节点会重新被初始化配置。

1 parent 92495322
Showing with 12 additions and 2 deletions
...@@ -6,13 +6,23 @@ new_node=( ...@@ -6,13 +6,23 @@ new_node=(
192.168.1.58 192.168.1.58
) #可以写多个node。每行一个。 ) #可以写多个node。每行一个。
interface=eno1 interface=eno1
#########################################################sshpass ###############配置节点免密###########
port=22 port=22
password=seetatech password=seetatech
for ip in ${new_node[@]} for ip in ${new_node[@]}
do do
sshpass -p $password ssh-copy-id -i ~/.ssh/id_rsa.pub -p $port -o StrictHostKeyChecking=no root@$ip sshpass -p $password ssh-copy-id -i ~/.ssh/id_rsa.pub -p $port -o StrictHostKeyChecking=no root@$ip
done done
##############根据new_node节点清单自动配置ansible hosts########
for ansible_new_node in ${new_node[@]}
do
if ! grep -qF "$ansible_new_node" /etc/hosts; then
cat >>./hosts<<EOF
$ip
EOF
else echo "您已配置该node:$ip 信息到ansible hosts文件,已跳过该步骤"
fi
done
######################################## ########################################
ansible new_node -m script -a "/root/k8s/script/k8s/backup/1-init.sh" ansible new_node -m script -a "/root/k8s/script/k8s/backup/1-init.sh"
ansible new_node -m shell -a "mkdir /opt/kubernetes/{cfg,bin,ssl,log} -pv" ansible new_node -m shell -a "mkdir /opt/kubernetes/{cfg,bin,ssl,log} -pv"
...@@ -35,7 +45,7 @@ ansible new_node -m shell -a "systemctl daemon-reload" ...@@ -35,7 +45,7 @@ ansible new_node -m shell -a "systemctl daemon-reload"
ansible new_node -m shell -a "service flanneld restart" ansible new_node -m shell -a "service flanneld restart"
ansible new_node -m shell -a "service flanneld status" ansible new_node -m shell -a "service flanneld status"
ansible new_node -m shell -a "systemctl enable flanneld.service" ansible new_node -m shell -a "systemctl enable flanneld.service"
#############################docker############################################ #############################安装docker############################################
echo "当前harbor仓库地址为$harbor_host," echo "当前harbor仓库地址为$harbor_host,"
sed -i s/harbor_host/$harbor_host/g /root/k8s/config/daemon.json sed -i s/harbor_host/$harbor_host/g /root/k8s/config/daemon.json
echo "开始安装docker" echo "开始安装docker"
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!