18-Linux 监控pxc集群脚本

2020-04-24  本文已影响0人  吕小凯
#!/bin/sh

#author by xiaokai 2020-04-25
while true
do
sleep 5
count=`ps -ef | grep mysql | grep -v "grep" | wc -l`

time2=$(date "+%Y-%m-%d %H:%M:%S")
#echo $count
if [ $count -lt 2 ]; then
    #进程不存在
    #time2=$(date "+%Y-%m-%d %H:%M:%S")
    #echo "pxc服务宕机,正在重新启动"
    echo 'pxc服务宕机,宕机时间为:'$time2>>error.log
    echo 'pxc服务宕机,宕机时间为:'$time2
    sleep 2
    docker stop node1 node2 && docker rm node1 node2
    echo 'pxc node1 && node2 stop success....'
    sleep 5    
    ####宕机处理
    rm -rf /var/lib/docker/volumes/v1/_data/grastate.dat
    rm -rf /var/lib/docker/volumes/v2/_data/grastate.dat
    echo 'clear data success....'
    sleep 5
    #重启pxc
    echo 'start pxc node1 .....'
    docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=abc123456 -e CLUSTER_NAME=PXC -e XTRABACKUP_PASSWORD=abc123456 -v v1:/var/lib/mysql -v backup:/data --privileged=true --name=node1 --net=net1 --ip 172.18.0.2 pxc
    echo 'start pxc node1 success...'    
    sleep 5
    echo 'start pxc node2 ....'
    docker run -d -p 3307:3306 -e MYSQL_ROOT_PASSWORD=abc123456 -e CLUSTER_NAME=PXC -e XTRABACKUP_PASSWORD=abc123456 -e CLUSTER_JOIN=node1 -v v2:/var/lib/mysql -v backup:/data --privileged --name=node2 --net=net1 --ip 172.18.0.3 pxc
    echo 'start pxc node2 success...'
    sleep 5
    echo 'pxc重新启动成功!!!'
else
    #rest进程存在,杀掉进程
    echo "pxc服务运行正常...持续监控中,当前时间为:"$time2
fi
#time=$(date "+%Y-%m-%d %H:%M:%S")
#echo "本轮监测完毕,当前时间为:"$time
done

上一篇下一篇

猜你喜欢

热点阅读