Monday, May 6, 2013

Nagios Installation on Linux


Nagios is an Open Source monitoring solution that started a phenomenon and continues to provide dependable monitoring to hundreds of thousands of organizations worldwide.

Here I will explain how to install nagios server and clients and its various plugins.

Nagios Server Installation

Install the following dependencies ..

apt-get update
apt-get install gcc make apache2 php5

Now download the latest nagios core and plugin from the link below ..
nagios-3.5.0.tar.gz
nagios-plugins-1.4.16.tar.gz

start installation,



useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios

This group can be used as the group that Nagios uses as a command group.
Add the Nagios user and the user which the webserver (Apache) runs as.
In Debian/Ubuntu, the user is www-data. In Redhat, this is apache.

Add webserver user (www-data/apache) and Nagios user (nagios)

usermod -G nagios nagios
usermod -G www-data,nagios www-data (Debian)
usermod -G apache,nagios apache (Redhat)

Now create Nagios root directory,

mkdir /usr/local/nagios , and we are ready to install..



tar -xzvf nagios-3.5.0.tar.gz
cd nagios-3.5.0/
./configure --prefix=/usr/local/nagios  --with-nagios-group=nagios --with-command-group=nagcmd --with-mail=/usr/bin/sendmail
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf

cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers

check nagios configuration file using the following command,
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

tar -xzvf nagios-plugins-1.4.15.tar.gz
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install

Give php support for the apache  by issuing the below command,

apt-get install libapache2-mod-php5
Add the below mentioned entry in /etc/apache2/apache2.conf

AddType application/x-httpd-php .php

Thus Nagios Web Interface installed to /usr/local/nagios/share, Include this (/etc/httpd/conf.d/nagios.conf ) in the apache configuration file.

Create Web Interface Login User:

We will create user "nagiosadmin"

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

Restart Apache ..
apache2ctl restart

Now start Nagios..
/etc/init.d/nagios start

After correctly following the procedures you should now be able to access your Nagios Core installation from a web browser.
Simply use the following:

http://<nagios-server-ip>/nagios

Nagios client installation

Install the dependencices..
apt-get install openssl-dev xinetd

groupadd nagcmd
useradd -g nagcmd nagios

tar -xzvf nagios-plugins-1.4.15.tar.gz
./configure
make
make install

Now install NRPE,

NRPE allows you to remotely execute Nagios plugins on other Linux/Unix machines. This allows you to monitor remote machine metrics (disk usage, CPU load, etc.)

Download nrpe from the below link
nrpe-2.14.tar.gz

tar -zxvf nrpe-2.14.tar.gz
./configure
make
make install
make install-daemon
make install-xinetd

vim /etc/services
nrpe 5666/tcp


vim /etc/xinetd.d/nrpe ( change the `only_from` ip from 127.0.0.1 to <nagios-server-ip> )


After succesfully installed Nagios Server and client,  we can go through its configurations.

Nagios server has a config file nagios.cfg ( /usr/local/nagios/etc/nagios.cfg ) which holds all the object files. Object configuration files are those in which we define hosts, host groups, contacts, contact groups, services, etc.


Sample object file (showing only the check areas ..)


define service{
        use                              generic-service
        host_name                        client-1.com
        service_description              Disk Usage /opt
        contact_groups                   usadmins
        check_command                    check_nrpe!check_/opt
}

define service{
        use                              generic-service
        host_name                        client-1.com
        service_description              Disk Usage /var
        contact_groups                   usadmins
        check_command                    check_nrpe!check_/var
}

define service{
        use                              generic-service
        host_name                        client-1.com
        service_description              Disk Usage /
        contact_groups                   usadmins
        check_command                    check_nrpe!check_/


Sample nrpe configuration for the above object file ..

command[check_users]=/usr/local/nagios/libexec/check_users -w 8 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 10,8,5 -c 25,15,12
command[check_/]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /root
command[check_/opt]=/usr/local/nagios/libexec/check_disk -w 15% -c 10% -p /opt
command[check_/var]=/usr/local/nagios/libexec/check_disk -w 15% -c 10% -p /var
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 12 -c 15 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 200 -c 250


For monitoring Mysql replication,

At nagios server,

apt-get install  libdbi-perl libdbd-mysql-perl

Download and install the MySQL Plugin:

check_mysql_health-2.1.3.tar.gz

tar -zxvf check_mysql_health-2.1.3.tar.gz
cd check_mysql_health-2.1.3
./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-perl=/usr/bin/perl
make
make install

Create database user at database client,
grant all privileges on *.* to 'nagios'@'<nagios-server-ip>' identified by 'nagios';

Provide email address for nagiosadmin:
[Change contacts.cfg file accordingly.]
vim /usr/local/nagios/etc/objects/contacts.cfg

define contact{
contact_name nagiosadmin
use generic-contact
alias Rinshad ; Full name of user
email rin@tech.com ;
}

Configuring Nagios to Monitor MySQL Server

vim /usr/local/nagios/etc/nagios.cfg
add following line:
cfg_file=/usr/local/nagios/etc/objects/mysqlmonitoring.cfg

Define check_mysql_health command as follows:

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

define command{
command_name check_mysql_health
command_line $USER1$/check_mysql_health -H $ARG4$ --username $ARG1$ --password $ARG2$ --port $ARG5$ --mode $ARG3$
}

Enter services to be monitored in mysqlmonitoring.cfg:

vim /usr/local/nagios/etc/objects/mysqlmonitoring.cfg

define service{
use local-service
host_name <client-ip>
service_description MySQL connection-time
check_command check_mysql_health!nagios!nagios!connection-time!<client-ip>!3306!
}

define service{
use local-service
host_name <client-ip>
service_description MySQL slave-io-running
check_command check_mysql_health!nagios!nagios!slave-io-running!<client-ip>!3306!
}

define service{
use local-service
host_name <client-ip>
service_description MySQL slave-sql-running
check_command check_mysql_health!nagios!nagios!slave-sql-running!<client-ip>!3306!
}

Here we have monitored 3 services: Connection-time, io thread and sql thread (replication) status.

Note: Every time you change configuration file, verify before starting nagios using command:

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

Finally start nagios service and you are done with nagios installation and configuration for monitoring MySQL.


Additional:

For using custom files as nagios plugins, follow the below procedure for checking the harddisk temperature as an example ..

On the client side,
apt-get install hddtemp

Run this daemon as `hddtemp -d`

On the server side download the file check_hddtemp_socket.pl, make it executable and place it in the libexec folder

Enter this in the client object file,

define service{
        use     local-service ; Name of service template to use
        host_name       <client-ip>
        service_description     Hard Disk Temperature
        check_command   check_hddtemp_socket.pl!45!50
        notifications_enabled           1
}

And define check_hddtemp_socket.pl command as follows:

define command{
command_name check_hddtemp_socket.pl
command_line $USER1$/check_hddtemp_socket.pl -D /dev/hda -w $ARG1$ -c $ARG2$
}

Restart nagios service.

Thanks for reading..

cheers /-







No comments:

Post a Comment