MySQL master-slave monitoring script:

Source: Internet
Author: User

In large-scale web site is often the master from the design of the database, if read and write according to the design pattern is only the main library above, then from the server is often the role of intelligent backup, sometimes the backup port when the appropriate time to manually add the good, but if the site did read and write separation, not in time to find that it is disastrous: Generally appear from the library can not keep up with the first to temporarily read also switch to the Lord up. After recovering from the good again cut back): The following according to this gives a master-slave monitoring script:

#!/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=$ (/etc/mysql/bin/mysql-uxiaoluo-pxiaoluo-s/tmp/mysql.sock-e "show slave status\g" | grep-i "Running")

Io_env= ' echo $STATUS | grep "Slave_io_running" | awk ' {print $} '

Sql_env= ' echo $STATUS | grep "Slave_sql_running" | awk ' {print $} '

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" [email protected]

Fi

If ["$IO _env" = "yes"-a "$SQL _env" = "yes"]

Then

echo "Slave is running!"

Else

echo "####### $DATA #########" >>/data/mysql/check_mysql_slave.log

echo "Slave is not running!" >>/data/mysql/check_mysql_slave.log

# echo "Slave is not running!" | Mail-s "warn! $MYSQLIP MySQL Slave is not running "[email protected]

Fi

Here I choose to send to 163 mailbox, now the phone can download a third-party client can be solved. Then to use mail, it is best to pay attention to modify some places: (otherwise it is likely not to send out)

Vi/etc/mail.rc

Set [email protected]
Set smtp=smtp://smtp.163.cn:25
Set [email protected]
Set smtp-auth-password= my password is 123, do you believe it?

After you modify it, you can test that the message has been sent successfully.

MySQL master-slave monitoring script:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.