
A Comprehensive Guide to Installing the Nagios NRPE Agent on RHEL, CentOS, & Oracle Linux
Effective system monitoring is the cornerstone of a stable and reliable IT infrastructure. Nagios Core stands as a powerful, open-source solution for this, but its true strength lies in its ability to monitor remote systems. This is made possible by the Nagios Remote Plugin Executor, or NRPE.
NRPE acts as an agent on the remote Linux machines you want to monitor. It listens for check requests from the main Nagios server, executes local plugins to gather data (like CPU load, memory usage, or disk space), and sends the results back. This guide provides a clear, step-by-step process for installing and configuring the NRPE agent on popular RPM-based distributions like RHEL, CentOS, and Oracle Linux.
Prerequisites: Enabling the EPEL Repository
Before we can install NRPE, we need to ensure our system has access to the Extra Packages for Enterprise Linux (EPEL) repository. This repository contains many additional software packages, including NRPE, that are not included in the default system repositories.
To install the EPEL repository, open your terminal and execute the following command:
sudo dnf install epel-release -y
This command will install and enable the repository, giving you access to the necessary packages for the next steps.
Step 1: Installing the NRPE Agent and Plugins
With the EPEL repository in place, the installation process is straightforward. We will install both the NRPE agent and the standard Nagios monitoring plugins, which NRPE uses to perform its checks.
Execute this command to install both packages:
sudo dnf install nrpe nagios-plugins-all -y
This command downloads and installs the NRPE daemon, its default configuration file, and a comprehensive suite of plugins for checking everything from disk and process status to network services.
Step 2: Configuring the NRPE Agent
The core of the NRPE setup lies in its configuration file, located at /etc/nagios/nrpe.cfg
. This file dictates how the agent behaves, and most importantly, which monitoring servers are allowed to connect to it.
For security, the most critical directive you must change is allowed_hosts
. By default, it is often set to only allow connections from the local machine (127.0.0.1
), which is not useful for remote monitoring.
Open the configuration file with your preferred text editor (like
nano
orvi
):sudo vi /etc/nagios/nrpe.cfg
Find the
allowed_hosts
line.Add the IP address of your primary Nagios monitoring server to this list, separated by a comma. Do not leave any spaces after the comma.
For example, if your Nagios server’s IP is 192.168.1.100
, the line should look like this:
allowed_hosts=127.0.0.1,::1,192.168.1.100
Security Tip: Never set allowed_hosts
to a wildcard or an overly broad IP range. Be specific and only list the IP addresses of your trusted Nagios servers to prevent unauthorized access.
Save and close the file after making your changes.
Step 3: Adjusting Firewall Rules
By default, modern Linux distributions run a firewall (like firewalld
) that will block incoming connections to the NRPE agent. We must create a rule to allow traffic on the default NRPE port, which is 5666/tcp.
Execute the following commands to permanently open the port and apply the new rules:
sudo firewall-cmd --permanent --add-port=5666/tcp
sudo firewall-cmd --reload
The first command adds the rule to the permanent configuration, and the second reloads the firewall to make the change effective immediately.
Step 4: Starting and Enabling the NRPE Service
Now that the agent is installed and configured, we need to start the service and enable it to launch automatically on system boot. This ensures your monitoring continues uninterrupted even after a server reboot.
Use the following systemctl
commands:
# To start the NRPE service immediately
sudo systemctl start nrpe
# To enable the service to start on boot
sudo systemctl enable nrpe
To confirm the service is running correctly, you can check its status:
sudo systemctl status nrpe
You should see an “active (running)” status in the output.
Step 5: Verifying the Installation
The final step is to verify that the agent is working and accessible from your Nagios server.
Local Test (On the Agent Machine):
You can first run a quick test on the remote machine itself to confirm the agent is responding. The check_nrpe
command is not installed by default with the agent, but you can confirm the basic pre-defined commands are working. A successful installation of the plugins will place them in /usr/lib64/nagios/plugins/
.
Remote Test (From the Nagios Server):
This is the definitive test. Log in to your primary Nagios server and execute the check_nrpe
command, pointing it at the IP address of the new host you just configured.
/usr/local/nagios/libexec/check_nrpe -H <IP_OF_YOUR_NEW_HOST>
Replace <IP_OF_YOUR_NEW_HOST>
with the actual IP address.
A successful connection will return the NRPE version number, like this:
NRPE v4.1.0
If you receive this response, congratulations! You have successfully installed, configured, and secured the Nagios NRPE agent. The remote host is now ready to be added to your Nagios monitoring configuration for detailed service checks.
Source: https://kifarunix.com/how-to-install-nagios-nrpe-agent-on-rhel-centos-oracle-linux/