How to Add Remote MySQL Server to Nagios Monitoring

We already have seen two articles for setting up MySQL Monitoring with Nagios and Percona Monitoring Tools for Nagios. Those posts covers configuration of nagios on single instance.

Though following questions came to me: Do you need to setup Nagios again on all servers that we want to monitor? How do you add another MySQL server to this monitoring?

This post is an answer to those questions.

To add remote server to nagios monitoring, We need NRPE (Nagios Remote Plugin Executor) along with Xinetd (Extended Internet Daemon) and Nagios Plugins to be setup.

(This assumes you have already setup the nagios server and adding new host. Refer links in first line of the article)

Steps to add Remote MySQL server to Nagios Monitoring:

– Create MySQL user for Nagios Server to connect (on Remote Server):

GRANT USAGE, REPLICATION CLIENT ON *.* TO 'nagios'@'' IDENTIFIED BY 'nagios';

– Install required dependencies:

yum install xinetd openssl openssl-devel
# OR apt-get install openssl xinetd libssl-dev

– Download & Install Nagios Plugins on remote MySQL Server:

wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz
tar xzf nagios-plugins-2.0.3.tar.gz
cd nagios-plugins-2.0.3
sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios
sudo make
sudo make install

– Download & Install NRPE:

wget http://garr.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz
tar xzf nrpe-2.15.tar.gz
cd nrpe-2.15

##Compile and install the NRPE addon.
./configure

You may face following error:
“checking for SSL libraries… configure: error: Cannot find ssl libraries”

Try specifying ssl & lib path as follows:

./configure --with-ssl=/usr/bin/openssl --with-ssl-lib=/usr/lib/i386-linux-gnu/

If this still doesn’t get resolved make sure you have required openssl and dependencies sorted.

– Proceed further for the NRPE setup:

make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd
service xinetd restart
vi  /etc/xinetd.d/nrpe # Verify following content (Note only_from)

# default: on
	# description: NRPE (Nagios Remote Plugin Executor)
	service nrpe
	{
		flags           = REUSE
		socket_type     = stream
		port            = 5666
		wait            = no
		user            = nagios
		group           = nagios
		server          = /usr/local/nagios/bin/nrpe
		server_args     = -c /usr/local/nagios/etc/nrpe.cfg --inetd
		log_on_failure  += USERID
		disable         = no
		only_from       = 127.0.0.1 192.168.86.129
	}

As we’re going to run NRPE daemon xinetd, we’ll need to add the IP/hostname to the only_from directive.
We need to update allowed_hosts in the file /usr/local/nagios/etc/nrpe.cfg if we’re not going to use NRPE with Xinetd.
Note that allowed_hosts is a comma-delimited list while only_from is space separated.

vi /etc/services # Add following line.
	nrpe            5666/tcp                 NRPE

service xinetd restart
netstat -at | grep nrpe # Confirm that the nrpe is listening.

tcp        0      0 *:nrpe                  *:*                     LISTEN     

– Once setup is done you can check the NRPE:

MySQL-Server]# /usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.15

and also from the Nagios server (replace the IP with that of remote server):

root@Nagios-Server:# /usr/local/nagios/libexec/check_nrpe -H 192.168.86.129 -p 5666 
NRPE v2.15

Some debugging:

If you receive errors as follows:

root@Nagios-Server:# /usr/local/nagios/libexec/check_nrpe -H 192.168.86.129 -p 5666 
CHECK_NRPE: Error - Could not complete SSL handshake.

… make sure to confirm the configuration (only_from), connectivity or the firewall are not blocking the communication.

See to configure firewall. I did a “dirty” stop.

# Stop iptables
/etc/init.d/iptables stop

# Set SELinux permissive
setenforce 0
# Note: To make SElinux changes permanent update /etc/sysconfig/selinux.

– Restart xinetd

[root@MySQL-Server nrpe-2.15]# /etc/init.d/xinetd restart
Stopping xinetd:                                           [  OK  ]
Starting xinetd:                                           [  OK  ]

Configuration on Nagios Server:

– On Nagios Server add following to the hosts definition and update hostgroup to include another MySQL server:

define host{
use mysql-server
host_name mysqldb01
alias MySQLServer
address 192.168.86.129
contact_groups admin
}

define hostgroup{
        hostgroup_name mysql-servers
        alias MySQL Servers
        members localhost, mysqldb01
}

– Restart nagios and all done!

Hope that helps.

1 comment
Leave a Reply

Your email address will not be published. Required fields are marked *