千家信息网

自动监控主从MySQL同步的SHELL脚本分享

发表于:2025-02-09 作者:千家信息网编辑
千家信息网最后更新 2025年02月09日,这篇文章主要介绍"自动监控主从MySQL同步的SHELL脚本分享",在日常操作中,相信很多人在自动监控主从MySQL同步的SHELL脚本分享问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法
千家信息网最后更新 2025年02月09日自动监控主从MySQL同步的SHELL脚本分享

这篇文章主要介绍"自动监控主从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 2grant all privileges on *.* to "yuhongchun"@"127.0.0.1" identified by "yuhongchun101"; grant all privileges on *.* to "yuhongchun"@"localhost" identified by "yuhongchun101";

到此,关于"自动监控主从MySQL同步的SHELL脚本分享"的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!

0