十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
这篇文章主要介绍“自动监控主从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脚本分享”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联网站,小编会继续努力为大家带来更多实用的文章!