Monitor MySQL master-slave synchronization configuration to monitor the script from the library running state

Source: Internet
Author: User

The code is as follows:

[Java]View PlainCopy
  1. #!/bin/bash
  2. #Check MySQL Slave ' s runnning Status
  3. #Crontab time :
  4. Mysqlport= ' Netstat-na|grep "LISTEN" |grep "3306" |awk-f[:""]+ ' {print $} '
  5. mysqlip= ' ifconfig eth0|grep "inet addr" | awk-f[: ""]+ ' {print $4} '
  6. status=$ (/usr/bin/mysql-uroot-p11111-s/var/lib/mysql/mysql.sock-e "show slave status\g" | grep-i "Running")
  7. Io_env= ' echo $STATUS | grep IO | awk ' {print $} '
  8. Sql_env= ' echo $STATUS | grep SQL | awk ' {print $} '
  9. Data= ' date +'%y-%m-%d%h:%m:%s '
  10. function Checkmysqlstatus () {
  11. if [ "$MYSQLPORT" = = "3306"]
  12. Then
  13. /usr/bin/mysql-uroot-p11111--connect_timeout=5-e "show databases;" &>/dev/null 2>& 1
  14. if [$?-ne 0]
  15. Then
  16. Echo "Server: $MYSQLIP MySQL is off, please try the restart MySQL by manual!" >/var/log/mysqlerr
  17. Mail-s "warn! Server: $MYSQLIP MySQL is down. "Admin@yourdomain. com </var/log/mysqlerr
  18. Else
  19. echo "MySQL is running ..."
  20. Fi
  21. Else
  22. Mail-s "warn! Server: $MYSQLIP MySQL is down. "Admin@yourdomain. com
  23. Fi
  24. }
  25. Checkmysqlstatus
  26. If [ "$IO _env" = "Yes"-a "$SQL _env" = "yes"]
  27. Then
  28. echo "MySQL Slave is running!"
  29. Else
  30. echo "####### $DATA #########" >>/data/mysql/mysql_slave_status.log
  31. echo "MySQL Slave is not running!" >>/data/mysql/mysql_slave_status.log
  32. echo "MySQL Slave is not running!" | mail-s "warn! $MYSQLIP MySQL Slave is not running. "Admin@yourdomain. com
  33. Fi


Recommended to run every 10 minutes
*/10 * * * * root/bin/sh/root/mysql_slave_status.sh

Principle:

1) Monitor the running state of MySQL;
2) Slave machine IO and SQL status must be yes, indispensable;

Note that you use it in conjunction with your own actual environment.

Monitor MySQL master-slave synchronization configuration to monitor the script from the library running state

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.