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: