NRPE Installation and Configuration on the client machine


1) Install the required packages in preparation to install NRPE.
[root@MACHINE1 ~]# yum install -y gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel

2) Add nagios username and update the password.
[root@MACHINE1 ~]# useradd nagios
[root@MACHINE1 ~]# passwd nagios
Changing password for user nagios.
New password: mypassword
Retype new password: mypassword
passwd: all authentication tokens updated successfully.

3) Create nagios directory to store the downloaded packages.

[root@MACHINE1 ~]# mkdir /root/nagios
[root@MACHINE1 ~]# cd /root/nagios

4) Download/extract the nagios-plugins-2.0.3.tar.gz or the latest installer.
[root@MACHINE1 nagios]# wget https://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz
[root@MACHINE1 nagios]# tar -zxvf nagios-plugins-2.0.3.tar.gz

5) Compile nagios plugin.

[root@MACHINE1 nagios]# cd nagios-plugins-2.0.3
[root@MACHINE1 nagios-plugins-2.0.3]# ./configure
[root@MACHINE1 nagios-plugins-2.0.3]# make
[root@MACHINE1 nagios-plugins-2.0.3]# make install

6) Change ownership on nagios installation directory to “nagios.nagios”.

[root@MACHINE1 nagios-plugins-2.0.3]# chown nagios.nagios /usr/local/nagios
[root@MACHINE1 nagios-plugins-2.0.3]# chown -R nagios.nagios /usr/local/nagios/libexec

7) Install xinetd.
[root@MACHINE1 nagios-plugins-2.0.3]# yum install xinetd

8) Download and compile NRPE installer.
[root@MACHINE1 nagios-plugins-2.0.3]# cd /root/nagios
[root@MACHINE1 nagios]# wget http://liquidtelecom.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz
[root@MACHINE1 nagios]# tar -zxvf nrpe-2.15.tar.gz
[root@MACHINE1 nagios]# cd nrpe-2.15
[root@MACHINE1 nrpe-2.15]# ./configure
[root@MACHINE1 nrpe-2.15]# make all
[root@MACHINE1 nrpe-2.15]# make install-plugin
[root@MACHINE1 nrpe-2.15]# make install-daemon
[root@MACHINE1 nrpe-2.15]# make install-daemon-config
[root@MACHINE1 nrpe-2.15]# make install-xinetd
[root@MACHINE1 nrpe-2.15]# vi /etc/xinetd.d/nrpe
#Change localhost ip to 192.168.168.92 which is the Nagios server.
only_from       = 192.168.168.92

9) Add the line at the most bottom part of /etc/services.

[root@MACHINE1 nrpe-2.15]# vi /etc/services
nrpe            5666/tcp                # NRPE

10) Restart xinetd.

[root@MACHINE1 nrpe-2.15]# service xinetd restart

11) Check if nrpe is listening after restarting xinetd.

[root@MACHINE1 nrpe-2.15]# netstat -at | grep nrpe
tcp        0      0 *:nrpe                      *:*                         LISTEN

12) Test if it works. If you encounter the error “Could not complete SSL handshake”. Please proceed to step 13.

[root@MACHINE1 nrpe-2.15]# /usr/local/nagios/libexec/check_nrpe -H 192.168.168.92
CHECK_NRPE: Error – Could not complete SSL handshake.

13) Add tcp port 5666 to iptables/firewall.

[root@MACHINE1 nrpe-2.15]# iptables -A INPUT -p tcp -m tcp –dport 5666 -j ACCEPT

[root@MACHINE1 nrpe-2.15]# service iptables save

14) Define the services that you want to monitor in NRPE.

[root@MACHINE1 nrpe-2.15]# vi /usr/local/nagios/etc/nrpe.cfg

#####################################################################################
#Hard Disk Resources
command[check_root]=/usr/local/nagios/libexec/check_disk -w 30% -c 20% -p /dev/sda2
command[check_var_log]=/usr/local/nagios/libexec/check_disk -w 30% -c 20% -p /dev/sdc1
command[check_home]=/usr/local/nagios/libexec/check_disk -w 30% -c 20% -p /dev/sdb2

#Sample Services
command[check_heartbeat]=/usr/local/nagios/libexec/check_ps.sh  -p heartbeat
command[check_postfix]=/usr/local/nagios/libexec/check_ps.sh -p postfix
command[check_dovecot]=/usr/local/nagios/libexec/check_ps.sh -p dovecot
######################################################################################

15) SSH your Nagios Server and add the line to nagios.cfg.

[root@NAGIOS]# vi /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/MACHINE1.cfg

16) Edit and insert the following code below to MACHINE1.cfg
vi /usr/local/nagios/etc/objects/MACHINE1.cfg

define service {
use                             generic-service
host_name                       MACHINE1
service_description             Heartbeat Service
check_command                   check_nrpe2!192.168.168.10!check_heartbeat
contact_groups                  common

define service {
use                             generic-service
host_name                       MACHINE1
service_description             Heartbeat Service
check_command                   check_nrpe2!192.168.168.10!check_postfix
contact_groups                  common

define service {
use                             generic-service
host_name                       MACHINE1
service_description             Heartbeat Service
check_command                   check_nrpe2!192.168.168.10!check_dovecot
contact_groups                  common

define service {
use                             generic-service
host_name                       MACHINE1
service_description             Root Partition
check_command                   check_nrpe2!192.168.168.10!check_root
contact_groups                  common
}

define service {
use                             generic-service
host_name                       MACHINE1
service_description             Home Partition
check_command                   check_nrpe2!192.168.168.10!check_home
contact_groups                  common
}
define service {
use                             generic-service
host_name                       MACHINE1
service_description             Log Partition
check_command                   check_nrpe2!192.168.168.10!check_var_log
contact_groups                  common
}

17) Wait for approximately 5 minutes and check via nagios web interface.

http://192.168.168.92/nagios/
Username: nagiosadmin
Password: mypassword