Monitor MySQL Server with Nagios 3.4
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:
User Account:
We required to create the user account for accessing the Nagios installation and configuration files. Before starting become the root user.
Create a new user in the name of “nagios” and give it a password.
Set the password.
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.
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 )
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.
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.
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.
Install the Nagios Plugins:
Extract the Nagios plugins source code tarball.
Compile and install the plugins. While compiling i got an error for the SSL version; here is the tutorial about Nagios troubleshooting.
Starting Nagios:
Add it on system start-up using the following command
Verify the sample Nagios configuration files.
If there are no errors, start Nagios.
SELinux Settings:
See if SELinux is in Enforcing mode.
Put SELinux on Permissive mode.
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.
You will redirect to the home page, Click on the Services to view Status of Hosts.
Install MySQL Plugin:
tar -zxvf check_mysql_health-2.1.8.2.tar.gz
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.
Add the information about the new template file in the Nagios configuration file.
Open up the command.cfg file.
Add the following entries in to that.
define command{
command_name check_mysql_health
define service{
define service{use local-servicehost_name localhostservice_description MySQL Open Files
check_command check_mysql_health!localhost!3306!all!all!open-files!
}
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.