Install Nagios NRPE Agent on RHEL/CentOS/Oracle Linux

|
Last Updated:
|
|

In this tutorial, we are going to learn how to install Nagios NRPE Agent on RHEL/CentOS/Oracle Linux. Nagios Remote Plugin Executor (NRPE) is used to remotely execute Nagios plugins on Linux/Unix machines. This makes it easy to monitor remote machine metrics such as disk usage, CPU load, number of running processes, logged in users etc.

You may also want to check our previous article on how to configure Nagios Aviailability monitoring on AlienVault USM/OSSIM.

Installing Nagios NRPE Agent on RHEL/CentOS/Oracle Linux

This tutorial installs NRPE by building it from the source code.

Install Required Build tools

As a prerequisite, ensure that the C compilers and are installed on the server since we are compiling NRPE from the source code;

yum install -y gcc glibc glibc-common openssl openssl-devel

Download NRPE Source File

Navigate to NRPE releases page and grab the latest source code.

Run the command below to download NRPE source file under the /tmp directory.

wget https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-4.1.0/nrpe-4.1.0.tar.gz -P /tmp/

Extract NRPE Source File

Once the download is complete, navigate to the download directory and run the command below to extract the source file.

cd /tmp
tar zxvf nrpe-4.1.0.tar.gz

Installing Nagios NRPE Agent

Configure NRPE

In order to compile NRPE package, you first need to set all the options and dependencies required  for the rest of the build and install process.

Run the command below to configure NRPE program;

cd nrpe-4.1.0
./configure --enable-command-args --with-nrpe-user=nagios --with-nrpe-group=nagios
  • –enable-command-args options enables you to pass arguments through NRPE. If omitted, then the arguments have to be explicitly set on the nrpe configuration file, nrpe.cfg.
  • –with-nrpe-user=nagios –with-nrpe-group=nagios sets the ownership of the configuration files.

If for some reason you encounter an issue during compilation regarding openssl, run thw compilation with –disable-ssl option.

If the compilation is successful, you should see the sample output below.


...
 General Options:
 -------------------------
 NRPE port:    5666
 NRPE user:    nagios
 NRPE group:   nagios
 Nagios user:  nagios
 Nagios group: nagios


Review the options above for accuracy.  If they look okay,
type 'make all' to compile the NRPE daemon and client
or type 'make' to get a list of make options.

Create User And Group

The ownership of the configuration files is set to nagios:nagios above . You therefore need to create the nagios user and group.

make install-groups-users

To confirm that the user and the group is actually created, run id command

id nagios
uid=1000(nagios) gid=989(nagios) groups=989(nagios)

Compile NRPE

If the above compilation options are fine, run the command below to compile the NRPE daemon and client.

make all

Install Nagios NRPE Agent

Once the compilation process is done, continue to install NRPE Daemon and the check_nrpe plugin.

make install

Install NRPE Configuration File and Service

Run the following commands to install NRPE sample configuration file as well as the NRPE service.

make install-config
make install-init

Define NRPE Service, Port and Protocol

Edit the service configuration file and map the nrpe service to its specific port and protocol, 5666/tcp by adding the following line at the bottom.

echo "nrpe            5666/tcp                # NRPE Service" >> /etc/services

Allow NRPE through firewall

NRPE uses port TCP 5666 by default. If firewall is running, open this port.

For Firewalld;

firewall-cmd --add-port=5666/tcp --permanent
firewall-cmd --reload

For IPTables;

iptables -I INPUT -p tcp --dport 5666 -j ACCEPT
iptables-save > /etc/sysconfig/iptables

Start and Enable NRPE to run on System boot

Run the commands below to start and enable nrpe to run on system boot.

systemctl start nrpe
systemctl enable nrpe

You can check the status of NRPE agent as shown below;


● nrpe.service - Nagios Remote Plugin Executor
   Loaded: loaded (/usr/lib/systemd/system/nrpe.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2021-06-23 13:54:18 EAT; 14s ago
     Docs: http://www.nagios.org/documentation
 Main PID: 7719 (nrpe)
    Tasks: 1 (limit: 11387)
   Memory: 728.0K
   CGroup: /system.slice/nrpe.service
           └─7719 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -f

Jun 23 13:54:18 localhost.localdomain systemd[1]: Started Nagios Remote Plugin Executor.
Jun 23 13:54:18 localhost.localdomain nrpe[7719]: Starting up daemon
Jun 23 13:54:18 localhost.localdomain nrpe[7719]: Server listening on 0.0.0.0 port 5666.
Jun 23 13:54:18 localhost.localdomain nrpe[7719]: Server listening on :: port 5666.
Jun 23 13:54:18 localhost.localdomain nrpe[7719]: Listening for connections on port 5666
Jun 23 13:54:18 localhost.localdomain nrpe[7719]: Allowing connections from: 127.0.0.1,::1

Verify that NRPE port 5666 is open;

ss -altn | grep 5666
LISTEN     0      5            *:5666                     *:*                  
LISTEN     0      5           :::5666                    :::*

Install Nagios Plugins on CentOS/RHEL/Oracle/Rocky Linux

In order to monitor various services, NRPE utilizes nagios plugins. Therefore you need to install Nagios Plugins before you can proceed to configure NRPE. You can check our previous article:

Install Nagios Plugins From Source RHEL/CentOS/Oracle Linux

Install Nagios Plugins on Rocky Linux 8

Configure NRPE on CentOS/RHEL/Oracle/Rocky Linux

Once the Nagios plugins are installed, update NRPE configuration file. When installed from source, the configuration file will reside under, /usr/local/nagios/etc/nrpe.cfg, although this can be changed.

Therefore, edit the file and make the following changes.

vim /usr/local/nagios/etc/nrpe.cfg

You may want to define a different IP address on which the service will listen on instead of the loopback. You can do so by changing the following line replacing loopback address with your interface IP address..

...
server_address=127.0.0.1
...

Under allowed hosts, replace the loopback6 address with Nagios Server IP such that the line looks like:

allowed_hosts=127.0.0.1,192.168.43.101

Replace the dont_blame_nrpe=0 setting with dont_blame_nrpe=1 to allow command arguments.

dont_blame_nrpe=1

Next, you need to define the commands that will used to check for various system services. Note that these commands relies on the Nagios plugins installed above. You may comment out the existing commands and define your own, for example;

command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -r -w 8.0,7.5,7.0 -c 11.0,10.0,9.0
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 15% -c 10% /
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 300 -c 400
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 10 -c 5

Save the configuration file once done editing and restrt NRPE service.

systemctl restart nrpe

Test the Plugins

Once you are done with installing the nagios plugins and configuring NRPE, execute the commands below to if all is well.

Check the version of installed NRPE;

/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1

You should get the NRPE version.

NRPE v4.1.0

Check for running processes;

/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_total_procs
PROCS OK: 114 processes | procs=114;300;400;0;

Check for logged in users;

/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_users
USERS OK - 2 users currently logged in |users=2;5;10;0

Perfect, you are all set and good to go. That is all about Installing Nagios NRPE Agent on RHEL/CentOS/Oracle Linux. We hope this was informative.

For other Related guides, see the links below;

Monitor Linux System Metrics with Prometheus Node Exporter

Monitor Squid logs with Grafana and Graylog

Monitor Squid Access Logs with Graylog Server

How to Install Nagios Plugins and NRPE agents on CentOS 7/RHEL 7/Fedora 29

Monitor Linux Hosts using Nagios check_by_ssh Plugin

How to Install Nagios Plugins From Source RHEL/CentOS/Oracle Linux

Install and Setup TIG Stack on Fedora 30

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
koromicha
I am the Co-founder of Kifarunix.com, Linux and the whole FOSS enthusiast, Linux System Admin and a Blue Teamer who loves to share technological tips and hacks with others as a way of sharing knowledge as: "In vain have you acquired knowledge if you have not imparted it to others".

2 thoughts on “Install Nagios NRPE Agent on RHEL/CentOS/Oracle Linux”

Leave a Comment