Monitor MySQL Server with Nagios 3.4

0
This document is outdated and it may not work

Nagios is the most widely used open source monitoring tools which help us to monitor the services and application that run’s on Windows,Linux,Routers and other network devices. With the help of Nagios you can monitor basic services and attributes. We can access the Nagios using web interface coming with the bundle and configuration need to be done on the file level ( Editing the conf file using the VI editor).

Prerequisites:

Before installing the Nagios, system need to meet the requirements for installing Nagios; So install the Web Server (httpd) , PHP ,compilers and development libraries. Install all with single command.
yum install httpd php gcc glibc glibc-common gd

User Account:

We required to create the user account for accessing the Nagios installation and configuration files. Before starting become the root user.

su -l

Create a new user in the name of “nagios” and give it a password.

useradd nagios

Set the password.

passwd nagios

Create a new group called nagcmd for allowing the external commands to be excuted through the web interface. change nagios and apache user to the created group.

groupadd nagcmd
usermod -a -G nagcmd nagios

Download Nagios & Plugin:

Download the Nagios and the Nagios plugins using the following command ( For latest version Visit Nagios WebSite )

wget https://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.4.4.tar.gzwget https://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz

Install Nagios:

tar -zxvf nagios-3.4.4.tar.gzcd nagios./configure –with-command-group=nagcmdmake all

make install

make install-init

make install-config

make install-commandmode

Configure Nagios:

Sample configuration files have now been installed in the /usr/local/nagios/etc directory. These sample files should work fine for getting started with Nagios. You’ll need to make just one change before you proceed…

Edit the /usr/local/nagios/etc/objects/contacts.cfg config file with your favorite editor and change the email address associated with the nagiosadmin contact definition to the address you’d like to use for receiving alerts.

vi /usr/local/nagios/etc/objects/contacts.cfg

Change the Email address field to receive the notification.

define contact{contact_name nagiosadmin ; Short name of useruse generic-contact ; Inherit default values from generic-contact template (defined above)alias Nagios Admin ; Full name of user

email [email protected] ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******

Configure Web Interface:

Install the Nagios web config file in the Apache conf.d directory.

make install-webconf

Create a nagiosadmin account for logging into the Nagios web interface. Remember the password you assign to this account – you’ll need it later.

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Restart Apache to make the new settings take effect.

service httpd restart

Install the Nagios Plugins:

Extract the Nagios plugins source code tarball.

tar -zxvf nagios-plugins-1.4.16.tar.gzcd nagios-plugins-1.4.16

Compile and install the plugins. While compiling i got an error for the SSL version; here is the tutorial about Nagios troubleshooting.

./configure –with-nagios-user=nagios –with-nagios-group=nagiosmakemake install

Starting Nagios:

Add it on system start-up using the following command

chkconfig nagios on

Verify the sample Nagios configuration files.

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

If there are no errors, start Nagios.

service nagios start

SELinux Settings:

See if SELinux is in Enforcing mode.

getenforce

Put SELinux on Permissive mode.

setenforce 0

To make this change permanent, you’ll have to modify the settings in /etc/selinux/config and reboot.

Access Web Interface:

Now access the Nagios web interface using the following URL. You’ll be prompted for the username (nagiosadmin) and password you specified earlier.

https://localhost/nagios/

You will redirect to the home page, Click on the Services to view Status of Hosts.

 

Install MySQL Plugin:

MySQL plugin not bundled with default plugins package, it has to be downloaded separately, to get it configured. MySQL plugin requires Perl package, so download and install the Perl package first.
yum install perl* asciidoc
Download the latest MySQL Health Check plugin from the Nagios website, Also you can issue the following command to download in the terminal.
wget https://labs.consol.de/download/shinken-nagios-plugins/check_mysql_health-2.1.8.2.tar.gz
Extract and compile the MySQL Plugin.

tar -zxvf check_mysql_health-2.1.8.2.tar.gz

cd check_mysql_health-2.1.8.2
./configure –prefix=/usr/local/nagios –with-nagios-user=nagios –with-nagios-group=nagios –with-perl=/usr/bin/perl
make
make install

Configure MySQL Plugin:

Create the MySQL user with the password in such a way that he can do all admin task remotely. Use the following command to log in to MySQL Server.

mysql -u root -p
Add the user.
mysql> CREATE USER ‘all’@’%’ IDENTIFIED BY ‘all’;

Add the information about the new template file in the Nagios configuration file.

vi /usr/local/nagios/etc/nagios.cfg
Add below line.
cfg_file=/usr/local/nagios/etc/objects/mysqlmonitor.cfg

Open up the command.cfg file.

vi /usr/local/nagios/etc/objects/commands.cfg

Add the following entries in to that.

define command{

command_name check_mysql_health

command_line $USER1$/check_mysql_health -H $ARG1$ –port $ARG2$ –username $ARG3$ –password $ARG4$ –mode $ARG5$
}
Create the new file called mysqlmonitor.cfg under the /usr/local/nagios/etc/object directory.
vi /usr/local/nagios/etc/objects/mysqlmonitor.cfg
Add the following, replace all and all with your MySQL admin user and Password of the MySQL Admin user.

define service{

use local-service
host_name localhost
service_description MySQL connection-time
check_command check_mysql_health!localhost!3306!all!all!connection-time!
}

define service{use local-servicehost_name localhostservice_description MySQL Open Files

check_command check_mysql_health!localhost!3306!all!all!open-files!

}

define service{
use local-service
host_name localhost
service_description MySQL UP Time

check_command check_mysql_health!localhost!3306!all!all!uptime!

}

The above two entries to monitor the uptime and connection time out information, more attributes can be found on the official website; can be put instead of uptime or connection time.

Monitor MySQL:

Now login in to the web interface, click on the services; you will find the above three services with the details.

 

Now you have successfully configured Nagios with MySQL monitoring plugin, More documentation can be found on the plugin page. Nagios has a similar type of plugins for other database servers; you can download it from the official plugin page.

You might also like