Nagios monitoring mysql master-slave Replication

Source: Internet
Author: User

The master-slave synchronization of Mysql and the LAMP environment were set up before the experiment, and then the nagios server was set up, and then configured on the slave side.

1. Add a user to the master database server
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:
[Root @ slave libexec] # mysql-uroot-p123456-e "show slave status \ G"
* *************************** 1. row ***************************
Slave_IO_State: Reconnecting after a failed master event read
Master_Host: 192.168.56.105
Master_User: rep
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000009
Read_Master_Log_Pos: 645
Relay_Log_File: mysql-relay-bin.000002
Relay_Log_Pos: 705
Relay_Master_Log_File: mysql-bin.000009
Slave_IO_Running: Yes
Slave_ SQL _Running: Yes

 

3. Install nrpe on the slave server, and add a line in the configuration file nrpe. cfg
The installation process will not be repeated here, only about configuration)

 

Configurations on slave

1) Configure nrpe
Add the following command
[Root @ slave ~] # Vim/usr/local/nagios/etc/nrpe. cfg
Command [check_mysql_slave] =/usr/local/nagios/libexec/check_mysql_slave

 

Restart nrpe after configuration is complete.
[Root @ localhost nagios] # netstat-nultp | grep nrpe
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
Tcp 0 0 0.0.0.0: 5666 0.0.0.0: * LISTEN 3730/nrpe

[Root @ localhost nagios] # kill 3730

[Root @ localhost nagios] #/usr/local/nagios/bin/nrpe-c/usr/local/nagios/etc/nrpe. cfg-d


2) create a script (from the server)
[Root @ slave ~] # Vim/usr/local/nagios/libexec/check_mysql_slave

#! /Bin/sh
Declare-a slave_is
Slave_is = ($ (/usr/local/mysql/bin/mysql-uroot-p123456-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

 

[Root @ slave ~] # Chmod + x/usr/local/nagios/libexec/check_mysql_slave

 

Test script running status:
[Root @ localhost libexec] #./check_mysql_slave
OK-slave is running

 

======================
Server Configuration:
Test whether the master-slave synchronization operation can be obtained through nrpe
[Root @ localhost libexec] #/usr/local/nagios/libexec/check_nrpe-H 192.168.56.102-c check_mysql_slave
OK-slave is running

 

First, configure the monitoring slave Host:
[Root @ localhost etc] # vim/usr/local/nagios/etc/hosts/slave. cfg
Define host {
Use linux-server, hosts-pnp
Host_name slave
Alias slave
Address 192.168.56.102
}

 

Configure the Monitoring Service:
[Root @ localhost etc] # vim/usr/local/nagios/etc/services/slave. cfg
Define service {
Use generic-service, services-pnp
Host_name slave
Service_description ping
Check_command check_ping! 100.0, 20%! 500.0, 60%
Max_check_attempts 5
Normal_check_interval 1
}
Define service {
Use generic-service, services-pnp
Host_name slave
Service_description tcp
Check_command check_tcp! 22
Max_check_attempts 5
Normal_check_interval 1
}
......
Define service {
Use generic-service, services-pnp
Host_name slave
Service_description check_mysql_slave
Check_command check_nrpe! Check_mysql_slave
Max_check_attempts 5
Normal_check_interval 1
}

 

Reload nagios Configuration
[Root @ localhost etc] # service nagios reload
Running configuration check... done.
Reloading nagios configuration... done

On the nagios service page, you can see that the master-slave replication has been successfully monitored.

650) this. width = 650; "title =" clipboard.png "src =" http://www.bkjia.com/uploads/allimg/131227/1I1055404-0.png "/>


When a simulated fault occurs, the master server fails and the Master/Slave replication fails. Check whether nagios can monitor the following:
[Root @ client ~] # Service mysqld stop
Shutting down MySQL... SUCCESS!

Mysql> show slave status \ G;
* *************************** 1. row ***************************
Slave_IO_State: Reconnecting after a failed master event read
Master_Host: 192.168.56.105
Master_User: rep
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000009
Read_Master_Log_Pos: 645
Relay_Log_File: mysql-relay-bin.000002
Relay_Log_Pos: 705
Relay_Master_Log_File: mysql-bin.000009
Slave_IO_Running: Connecting
Slave_ SQL _Running: Yes
......

650) this. width = 650; "title =" clipboard.png "src =" http://www.bkjia.com/uploads/allimg/131227/1I1053535-1.png "/>

The experiment is now complete!

 

Here is a question: as shown in the above experiment, nagios only monitors the normal operation of mysql master-slave replication. If I want to monitor whether the master-slave replication is synchronized in real time or whether the synchronization is complete, what should I do?

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.