Nagios monitoring MySQL master-slave replication by Tian Yi (sery@163.com
)
Cause: Nagios may monitor the running status of the MySQL service, but it cannot monitor whether the master-slave replication of MySQL is normal: Sometimes the synchronization has stopped, but the Administrator does not know.
Start: log on to the MySQL slave server and run mysql> show slave status/g.
Check the output to determine whether the master-slave replication is normal. Below is the output of a slave server:
Mysql> show slave status/g
* *************************** 1. row ***************************
Slave_io_state: Waiting for Master to send event
Master_host: 192.168.93.16
Master_user: rep1
Master_port: 3306
Connect_retry: 60
Master_log_file: mysql-bin.000004
Read_master_log_pos: 1752541
Relay_log_file: hy-mysql3-relay-bin.000088
Relay_log_pos: 2339
Relay_master_log_file: mysql-bin.000004
Slave_io_running: Yes
Slave_ SQL _running: Yes
Replicate_do_db:
The key to this output is "slave_io_running: Yes
"And" slave_ SQL _running: Yes
", The two values are all" yes ", indicating that the master-slave replication is normal, otherwise there is a problem.
Procedure:
1. Add a user to the master database server and grant low permissions.
Mysql> grant replication client on *. * To 'nagios '@' %'
Identified by 'nagios ';
Mysql> flush privileges;
2. log on to the slave server and check whether the server is normal. Operation:
Mysql-unagios-pnagios-e "show slave stutas/g" NOTE: This operation is performed in shell !!
3. Install nrpe on the slave server, and add a line of command [check_mysql_slave] =/usr/local/nrpe/libexec/chech_mysql_slave to the configuration file nrpe. cfg.
4. write the script/usr/local/nrpe/libexec/check_mysql_slave (which is the core of monitoring its function). The content is as follows:
#! /Bin/sh
Declare-A slave_is
Slave_is = ($ (/usr/local/MySQL/bin/MySQL-unagios-pnagios-e "show slave status/g" | grep running | awk '{print $2 }' ))
If ["$ {slave_is [0]}" = "yes"-a "$ {slave_is [1]}" = "yes"]
Then
Echo "OK-slave is running"
Exit 0
Else
Echo "critical-slave is error"
Exit 2
Fi
5. Run the script manually and observe the output.
6. Run check_nrpe-H 192.168.99.102-C check_mysql_slave to observe its output:
7. Modify Nagios and test.
8. Function Testing (omitted)