本文共 1482 字,大约阅读时间需要 4 分钟。
目的: 监测mysql的存活状态,一旦监测到mysql down掉,重新启动mysql.
脚本内容:
/usr/local/mysql/bin/mysqladmin -uroot -ppassword ping > /dev/null 2>&1if [ $? -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.logfi
利用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/cronJul 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.log20140722 16:28:14 mysql is restart20140722 16:30:09 mysql is restart20140722 16:34:08 mysql is restart
这样就可以实现mysql停服时自动启动了.
转载地址:http://mznao.baihongyu.com/