1) Install the prerequisites
yum install httpd php gcc glibc glibc-common gd gd-devel libssl-dev openssl*
2) Create a new nagios user account and give it a password.
/usr/sbin/useradd -m nagios
passwd nagios
3) Create a new nagcmd group for allowing external commands to be submitted through the web interface.
Add both the nagios user and the apache user to the group.
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -a -G nagcmd nagios
/usr/sbin/usermod -a -G nagcmd apache
4) Now go to http://www.nagios.org and download the files..
wget http://downloads.sourceforge.net/project/nagios/nagios-3.x/nagios-3.4.3/nagios-3.4.3.tar.gz
wget http://downloads.sourceforge.net/project/nagiosplug/nagiosplug/1.4.16/nagios-plugins-1.4.16.tar.gz
5) Compile and Install Nagios
tar zxvf nagios-3.4.3.tar.gz
cd nagios
./configure --with-command-group=nagcmd
make all
make install; make install-init; make install-config; make install-commandmode;
6) Customize Configuration
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.
vim /usr/local/nagios/etc/objects/contacts.cfg
-----------------------------------------------
define contact{
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of user
email sankar.k@gmail.com ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}
7) Configure the 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
8) Compile and Install the Nagios Plugins
tar zxvf nagios-plugins-1.4.16.tar.gz
nagios-plugins-1.4.16
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
9) Start Nagios
chkconfig --add nagios
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
10) Login to the Web Interface using username (nagiosadmin) and password you specified earlier
From your internet browser navigate to the following URL:
http://<your server name or IP>/nagios
Monitor Remote Linux Host using Nagios.
===================================
Follow below steps to monitor a remote Linux host and the various services running on the remote host
6 steps to install Nagios plugin and NRPE on remote host.
1) Download Nagios Plugins and NRPE Add-on
2) Create nagios account
3) Install Nagios Plugins
4) Install NRPE
5) Setup NRPE to run as daemon
6) Modify the /usr/local/nagios/etc/nrpe.cfg
4 Configuration steps on the Nagios monitoring server to monitor remote host:
1) Download NRPE Add-on
2) Install check_nrpe
3) Create host and service definition for remote host
4) Restart the nagios service
Overview
a) Nagios will execute check_nrpe command on nagios-server and request it to monitor disk usage on remote host using check_disk command.
b) The check_nrpe on the nagios-server will contact the NRPE daemon on remote host and request it to execute the check_disk on remote host.
c) The results of the check_disk command will be returned back by NRPE daemon to the check_nrpe on nagios-server.
Following flow summarizes the above explanation:
Nagios Server (check_nrpe) —–> Remote host (NRPE deamon) —–> check_disk
Nagios Server (check_nrpe) <—– Remote host (NRPE deamon) <—– check_disk (returns disk space usage)
Steps to install Nagios Plugins and NRPE on the remote host
1. Download Nagios Plugins and NRPE Add-on.
wget http://downloads.sourceforge.net/project/nagiosplug/nagiosplug/1.4.16/nagios-plugins-1.4.16.tar.gz
wget http://downloads.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.13/nrpe-2.13.tar.gz
2. Create nagios account
useradd nagios
passwd nagios
3. Install nagios-plugin
tar zxvf nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
export LDFLAGS=-ldl
./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-redhat-pthread-workaround
make
make install
chown nagios.nagios /usr/local/nagios
chown -R nagios.nagios /usr/local/nagios/libexec/
4. Install NRPE
tar zxvf nrpe-2.13.tar.gz
cd nrpe-2.13
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd
5. Setup NRPE to run as daemon (i.e as part of xinetd):
==> Modify the /etc/xinetd.d/nrpe to add the ip-address of the Nagios monitoring server to the only_from directive. Note that there is a space after the 127.0.0.1 and the nagios monitoring server ip-address (in this example, nagios monitoring server ip-address is: 192.168.80.70)
vim /etc/xinetd.d/nrpe
---------------------
only_from = 127.0.0.1 192.168.80.70
==> Modify the /etc/services and add the following at the end of the file.
vim /etc/services
-----------------
nrpe 5666/tcp # NRPE
==> Start the service
service xinetd restart
==> Verify whether NRPE is listening
netstat -at | grep nrpe
tcp 0 0 *:nrpe *:* LISTEN
==> Verify to make sure the NRPE is functioning properly
[remotehost]# /usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.13
6. Modify the /usr/local/nagios/etc/nrpe.cfg
The nrpe.cfg file located on the remote host contains the commands that are needed to check the services on the remote host. By default the nrpe.cfg comes with few standard check commands as samples. check_users and check_load are shown below as an example.
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
In all the check commands, the “-w” stands for “Warning” and “-c” stands for “Critical”. for e.g. in the check_disk command below, if the available disk space gets to 20% of less, nagios will send warning message. If it gets to 10% or less, nagios will send critical message. Change the value of “-c” and “-w” parameter below depending on your environment.
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1
Note: You can execute any of the commands shown in the nrpe.cfg on the command line on remote host and see the results for yourself. For e.g. When I executed the check_disk command on the command line, it displayed the following:
[remotehost]#/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1
DISK CRITICAL - free space: / 6420 MB (10% inode=98%);| /=55032MB;51792;58266;0;64741
In the above example, since the free disk space on /dev/hda1 is only 10% , it is displaying the CRITICAL message, which will be returned to nagios server.
Configuration steps on the Nagios monitoring server to monitor remote host
1. Download NRPE Add-on
wget http://downloads.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.13/nrpe-2.13.tar.gz
2. Install check_nrpe on the nagios monitoring server
tar zxvf nrpe-2.13.tar.gz
cd nrpe-2.13
./configure
make all
make install-plugin
==> Verify whether nagios monitoring server can talk to the remotehost.
/usr/local/nagios/libexec/check_nrpe -H 192.168.80.129
NRPE v2.13
Note: 192.168.80.70 in the ip-address of the remotehost where the NRPE and nagios plugin was installed as explained in Section II above.
3. Create host and service definition for remotehost
Create a new configuration file /usr/local/nagios/etc/objects/remotehost.cfg to define the host and service definition for this particular remotehost. It is good to take the localhost.cfg and copy it as remotehost.cfg and start modifying it according to your needs.
Ex :
# vim /etc/hosts
--------------
192.168.80.129 slave.sankar.com slave
# vim /usr/local/nagios/etc/objects/commands.cfg
------------------------------------------------
### Add this below lines in end of the file
# check_nrpe command definition
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -t 30 -c $ARG1$
}
# cp localhost.cfg slave.cfg
# vim slave.cfg
--------------
define host{
use linux-server ; Name of host template to use
; This host definition will inherit all variables that are defined
; in (or inherited by) the linux-server host template definition.
host_name slave.sankar.com
alias slave.sankar.com
address 192.168.80.129
}
# Define a service to "ping" the local machine
define service{
use local-service ; Name of service template to use
host_name slave.sankar.com
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
:%s/localhost/slave.sankar.com/g
# vim /usr/local/nagios/etc/nagios.cfg
---------------------------------------
# Definitions for monitoring the local (Linux) host
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
cfg_file=/usr/local/nagios/etc/objects/slave.cfg
4. Restart the nagios service
Restart the nagios as shown below and login to the nagios web (http://nagios-server/nagios/) to verify the status of the remotehost linux sever that was added to nagios for monitoring.
# service nagios reload
Enjoy............
