mysql如何启动自动监测_一个简单的mysql服务检测启动脚本

目的: 监测mysql的存活状态,一旦监测到mysql down掉,重新启动mysql.

脚本内容:/usr/local/mysql/bin/mysqladmin -uroot -ppassword ping > /dev/null 2>&1

if [ $? -ne 0 ]

then

/etc/init.d/mysql.server restart >/dev/null

echo "`/bin/date '+%Y%m%d %H:%M:%S'`  mysql is restart " >> /root/scripts/mysql_run.log

fi

利用crontab定时任务来执行脚本:[root@Master_mysql scripts]# crontab -l

*/2 * * * * /bin/bash /root/scripts/mysql_ping.sh

手动模拟关闭msyql,然后间隔2分钟,查看cron执行日志"/var/log/cron"和脚本执行日

志"/root/scripts/mysql_run.log"#cron执行日志

[root@Master_mysql scripts]# tail -n 10 /var/log/cron

Jul 22 16:27:01 Master_mysql crontab[5818]: (root) BEGIN EDIT (root)

Jul 22 16:27:07 Master_mysql crontab[5818]: (root) REPLACE (root)

Jul 22 16:27:07 Master_mysql crontab[5818]: (root) END EDIT (root)

Jul 22 16:27:38 Master_mysql crontab[5849]: (root) LIST (root)

Jul 22 16:28:01 Master_mysql crond[3103]: (root) RELOAD (cron/root)

Jul 22 16:28:01 Master_mysql crond[5853]: (root) CMD (/bin/bash /root/scripts/mysql_ping.sh)

Jul 22 16:29:59 Master_mysql crontab[6138]: (root) LIST (root)

Jul 22 16:30:01 Master_mysql crond[6140]: (root) CMD (/bin/bash /root/scripts/mysql_ping.sh)

Jul 22 16:32:01 Master_mysql crond[6394]: (root) CMD (/bin/bash /root/scripts/mysql_ping.sh)

Jul 22 16:34:01 Master_mysql crond[6429]: (root) CMD (/bin/bash /root/scripts/mysql_ping.sh)

#脚本执行日志

[root@Master_mysql scripts]# cat mysql_run.log

20140722 16:28:14  mysql is restart

20140722 16:30:09  mysql is restart

20140722 16:34:08  mysql is restart

这样就可以实现mysql停服时自动启动了.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值