这么个玩意儿废了我小半天儿,学如逆水行舟啊
[root@galera1 shell_scripts]# cat startdb.sh ##host_list={galera1,galera2,galera3} echo "task start at: $(date +%Y-%m-%d_%H:%M:%S)" bootstrap_tmpfile=/tmp/.db_stat.$(date +%Y%m%d%H%M) stop_db(){ ssh galera3 'systemctl stop mariadb' sleep 1 ssh galera2 'systemctl stop mariadb' sleep 1 ssh galera1 'systemctl stop mariadb' } check_status(){ for host in {galera1,galera2,galera3}; do echo ${host} $(ssh ${host} "sh /root/shell_scripts/local_scripts/check_db_bootstrap.sh") done > ${bootstrap_tmpfile} } start_db(){ if [ $(awk '/ 1/{print $1}' ${bootstrap_tmpfile}|wc -l) = 1 ]; #注意awk关键词里面有个空格 then host1=$(awk '/ 1/{print $1}' ${bootstrap_tmpfile}); else host1=galera1 ssh $host1 "sed -i '/bootstrap/c\safe_to_bootstrap: 1' /var/lib/mysql/grastate.dat" for host in $(awk '{print $1}' ${bootstrap_tmpfile}|grep -v ${host1});do ssh $host "sed -i '/bootstrap/c\safe_to_bootstrap: 0' /var/lib/mysql/grastate.dat" done fi ssh $host1 'galera_new_cluster' sleep 3 for host in $(awk '{print $1}' ${bootstrap_tmpfile}|grep -v ${host1});do ssh $host 'systemctl start mariadb' done } main(){ stop_db check_status start_db rm -f ${bootstrap_tmpfile} echo "task over at: $(date +%Y-%m-%d_%H:%M:%S)" } main [root@galera1 shell_scripts]# ssh galera1 "cat /root/shell_scripts/local_scripts/check_db_bootstrap.sh" awk '/safe_to_bootstrap/{print $NF}' /var/lib/mysql/grastate.dat
标签:galera,tmpfile,galera1,bootstrap,db,可自改,host,集群,ssh From: https://www.cnblogs.com/santia-god/p/17972216