这篇文章主要介绍“自动监控主从MySQL同步的SHELL脚本分享”,在日常操作中,相信很多人在自动监控主从MySQL同步的SHELL脚本分享问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”自动监控主从MySQL同步的SHELL脚本分享”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #!/bin/bash # check MySQL_Slave Status #crontab time 00:10 MYSQLPORT=`netstat -na|grep "LISTEN" |grep "3306" |awk -F[: " " ]+ '{print $4}' ` MYSQLIP=`ifconfig eth0|grep "inet addr" | awk -F[: " " ]+ '{print $4}' ` STATUS=$(/usr/ local /webserver/mysql/bin/mysql -u yuhongchun -pyuhongchun101 -S /tmp/mysql.sock -e "show slave statusG" | grep -i "running" ) IO_env=`echo $STATUS | grep IO | awk ' {print $2}' ` SQL_env=`echo $STATUS | grep SQL | awk '{print $2}' ` DATA=` date + "%y-%m-%d %H:%M:%S" `
if [ "$MYSQLPORT" == "3306" ] then
echo "mysql is running" else
mail -s "warn!server: $MYSQLIP mysql is down" yuhongchun027@163.com fi
if [ "$IO_env" = "Yes" -a "$SQL_env" = "Yes" ] then
echo "Slave is running!" else
echo "####### $DATA #########" >> /data/data/check_mysql_slave.log
echo "Slave is not running!" >> /data/data/check_mysql_slave.log
echo "Slave is not running!" | mail -s "warn! $MYSQLIP MySQL Slave is not running" yuhongchun027@163.com fi |
建议每十分钟运行一次
*/10 * * * * root /bin/sh /root/mysql_slave.sh
记得在每台MySQL从机上分配一个yuhongchun的用户,权限大些也没关系,只限定在本地运行,如下所示:
1 2 | grant all privileges on *.* to "yuhongchun" @ "127.0.0.1" identified by "yuhongchun101" ; grant all privileges on *.* to "yuhongchun" @ "localhost" identified by "yuhongchun101" ; |
到此,关于“自动监控主从MySQL同步的SHELL脚本分享”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。