MySQL master-slave synchronization, monitoring slave database running status scripts

Source: Internet
Author: User

Add a script to monitor the slave database running status in the MYSQL master-slave synchronization configuration.

The Code is as follows:

  1. #! /Bin/bash
  2. # Check MySQL Slave's Runnning Status
  3. # Crontab time00:10
  4. MYSQLPORT = 'netstat-na | grep"LISTEN"| Grep"3306"| Awk-F [:""] +'{Print $5 }''
  5. MYSQLIP = 'ifconfig eth0 | grep"Inet addr"| Awk-F [:""] +'{Print $4 }''
  6. STATUS = $ (/usr/bin/mysql-uroot-p11111-S/var/lib/mysql. sock-e"Show slave status \ G"| Grep-I"Running")
  7. IO_env = 'echo $ STATUS | grep IO | awk'{Print $2 }''
  8. SQL _env = 'echo $ STATUS | grep SQL | awk'{Print $2 }''
  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[$? -Ne0]
  15. Then
  16. Echo"Server: $ MYSQLIP mysql is down, please try to 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"-"$ 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
We recommend that you run the task every 10 minutes.
*/10 * root/bin/sh/root/mysql_slave_status.sh

Principle:

1) Monitor the running status of MYSQL;
2) The IO and SQL statuses of the Server Load balancer must be YES;

Note: use it in combination with your actual environment.

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.