How to add and monitor Linux hosts by using Nagios



NRPE stands for Nagios Remote Plugin Executor. Which allows monitoring the remote Linux hosts.But, we can also install Nagios plugins along with NRPE.

In the last articles, we knew about the installation of Nagios core and Nagios XI on CentOS7 and RHEL 7. In this article, we will be known about the adding a Linux host to Nagios monitoring server by using NRPE plugin. By using Nagios, we not only monitor hosts physical memory, CPU load, free disk space and logged in users information and also we monitor services like DHCP, FTP, SMTP, POP3, IMAP etc. It’s very helpful to system administrators to monitor all the servers from one place.

Client-side configuration

First, install the prerequisite to required for installation of Nagios plugins

#yum install gcc glibc glibc-common gd gd-devel openssl openssl-devel net-snmp 

Now install Xinetd service as follows

#yum -y install xinetd

Create Nagios user

#useradd nagios

Download and install Nagios plugins

#tar -xzvf nagios-plugins-2.1.4.tar.gz
#cd nagios-plugins-2.1.4
#make install

Now download and install NRPE Plugin

#tar -xzvf 3.0.1.tar.gz 
#cd nrpe-3.0.1/
#make all
#make install
cd ./src/; make install
make[1]: Entering directory `/root/nagios-plugins-2.1.4/nrpe-3.0.1/src'
make install-plugin
make[2]: Entering directory `/root/nagios-plugins-2.1.4/nrpe-3.0.1/src'
/usr/bin/install -c -m 755 -d /usr/local/nagios/bin
/usr/bin/install -c -m 755 ../uninstall /usr/local/nagios/bin/nrpe-uninstall
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/libexec
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/libexec
/usr/bin/install -c -m 775 -o nagios -g nagios check_nrpe /usr/local/nagios/libexec
make[2]: Leaving directory `/root/nagios-plugins-2.1.4/nrpe-3.0.1/src'
make install-daemon
make[2]: Entering directory `/root/nagios-plugins-2.1.4/nrpe-3.0.1/src'
/usr/bin/install -c -m 755 -d /usr/local/nagios/bin
/usr/bin/install -c -m 755 ../uninstall /usr/local/nagios/bin/nrpe-uninstall
/usr/bin/install -c -m 755 nrpe /usr/local/nagios/bin
/usr/bin/install -c -m 755 -o nagios -g nagios -d /usr/local/nagios/var
/usr/bin/install -c -m 755 -d /usr/lib/tmpfiles.d
/usr/bin/install -c -m 644 ../startup/tmpfile.conf /usr/lib/tmpfiles.d/nrpe.conf
make[2]: Leaving directory `/root/nagios-plugins-2.1.4/nrpe-3.0.1/src'
make[1]: Leaving directory `/root/nagios-plugins-2.1.4/nrpe-3.0.1/src'
#make install-config
#make install-inetd
#make install-init

Check services file(/etc/services) for nrpe service entry
Edit Nagios.cfg and change server address and allowed hosts. now enable and start the nrpe service

#systemctl restart xinetd
#systemctl enable nrpe
#systemctl start nrpe

Allow the nrpe service for firewall and SELinux

#firewall-cmd --zone=public --add-port=5666/tcp --permanent
#firewall-cmd reload
#setenforce 0

Now check nrpe installed or not by using command

#cd /usr/local/nagios/libexec/
#./check_nrpe -H
NRPE v3.0.1

Server side configuration

First make sure that Nagios core is installed and then install the openssl and openssl-devel packages on Nagios server.

#yum -y install openssl openssl-devel

Download and install the latest version ofcheck_nrpe plugin

#tar -xzvf 3.0.1.tar.gz 
#cd nrpe-3.0.1/
#make check_nrpe
#make install-plugin

Now check the remote system is connected or not

[root@localhost ~]# /usr/local/nagios/libexec/check_nrpe -H
NRPE v3.0.1
[root@localhost ~]# /usr/local/nagios/libexec/check_nrpe -H -c check_users
USERS OK - 1 users currently logged in |users=1;5;10;0
[root@localhost ~]# /usr/local/nagios/libexec/check_nrpe -H -c check_load
OK - load average: 2.35, 2.49, 2.55|load1=2.350;15.000;30.000;0; load5=2.490;10.000;25.000;0; load15=2.550;5.000;20.000;0;

Now create configuration files for remote hosts separately. The sample configuration file for linux hosts is available in /usr/local/nagios/etc/objects directory. copy that file to /usr/local/nagios/etc/ directory.

#cp -f /usr/local/nagios/etc/objects/localhost.cfg /usr/local/nagios/etc/linuxserver1.cfg

Now edit the file and change all the instances of Hostname to the remote system name and address to remote system ip address.

#vi /usr/local/nagios/etc/linuxserver1.cfg

Change hostnames by replace command in vi editor
:1, $ s/localhost/linuxserver1/g

Now edit the nagios configuration file and add entry for linuxserver1.conf file

#vi /usr/local/nagios/etc/nagios.cfg


Now restart the Nagios service by using systemctl command

#systemctl restart nagios

Now access the Nagios webinterface in your favorite browser and check hosts and services

Only basic services are defined for this host, if you want add more services like ftp, dhcp refer commands.conf in objects directory and add it to the linux config file.

define service{
        use                             local-service         ; Name of service template to use
        host_name                       server1
        service_description             FTP
        check_command                   check_ftp
        notifications_enabled           0

Like above we can add any service definition in the linux host configuration file.Explore all the options in the Nagios dashboard to learn more about Linux Host Monitoring by Nagios. if you want to join this discussion, feel free to leave a comment!