定时检测mysql状态,实现自动重启 - 易维网

定时检测mysql状态,实现自动重启

分类:随笔(Essays) ; 热度:1349 ; 最后更新于2019 年 10 月 22 日

tohnnystohnnys

最近我这台服务器的数据库频繁宕机,然后上面的站点全遭殃,各种404和无法访问。
临时方案:利用脚本+定时器,自动检测状态并重启数据库。(为什么不直接解决?这台云主机是小内存小硬盘)

#!/bin/bash
pgrep -x mysqld &> /dev/null
if [ $? -ne 0 ]
then
echo “At time: `date +%Y%m%d-%H:%M:%S` MySQL is stop .”>> /wwwroot/shell/mysqlrestart.log
/etc/init.d/mysql start
else
echo “At time: `date +%Y%m%d-%H:%M:%S` MySQL server is running .”>> /wwwroot/shell/mysqlrestart.log
fi

将上面的脚本写入定时器,暂时解决了这个问题,MySQL宕机原因等有空闲时再找到并解决吧…


评论卡