How To Monitor Remote Linux Host using Nagios

0
834

II. 7 steps to install Nagios Plugins and NRPE on the Remote Server

1. Download Nagios Plugins and NRPE Add-on

Download following files from Nagios.org and move to /home/downloads on the remove server you plan to monitor:

  • nagios-plugins-1.4.15.tar.gz
  • nrpe-2.13.tar.gz

2. Create nagios account

useradd nagios
passwd nagios

3. Install nagios-plugin

cd /home/downloads
tar xvfz nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
export LDFLAGS=-ldl

./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install

chown nagios.nagios /usr/local/nagios
chown -R nagios.nagios /usr/local/nagios/libexec/

4. Install NRPE on the Remote Server

cd /home/downloads
tar xvfz nrpe-2.12.tar.gz
cd nrpe-2.12

./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) on the Remote Server

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.1.2)

only_from       = 127.0.0.1 192.168.1.2

Modify the /etc/services and add the following at the end of the file.

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

/usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.12

6. Modify the /usr/local/nagios/etc/nrpe.cfg on the Remote Server

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:

/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.

Originally posted 2016-01-11 05:52:57.

LEAVE A REPLY

Please enter your comment!
Please enter your name here