
A Step-by-Step Guide to Installing the NRPE Agent on Debian 11 & 10
Expanding your monitoring capabilities with Nagios requires a reliable way to execute checks on remote Linux machines. The Nagios Remote Plugin Executor (NRPE) is the industry-standard agent for this task, allowing your Nagios server to securely request and receive performance data from your Debian systems.
This guide provides a comprehensive walkthrough for installing and configuring the NRPE agent on Debian 11 (Bullseye) and Debian 10 (Buster). By following these steps, you can effectively monitor local resources like CPU load, memory usage, and disk space on your remote Debian servers.
Prerequisites
Before we begin, ensure you have:
- A running instance of Debian 11 or Debian 10.
- Access to a user account with
sudoor root privileges. - The IP address of your central Nagios monitoring server.
Step 1: Install the NRPE Agent and Nagios Plugins
First, we need to update our system’s package repository and install the necessary software. The NRPE server runs on the client machine being monitored, and the Nagios plugins provide the actual scripts used for the checks.
Open your terminal and execute the following commands to update your package lists and install the required packages:
sudo apt update
sudo apt install nagios-nrpe-server nagios-plugins -y
This single command installs both the NRPE daemon (nagios-nrpe-server) and the standard monitoring plugins (nagios-plugins) that NRPE will use to check system metrics.
Step 2: Configure the NRPE Agent
The core of the NRPE configuration resides in a single file. We need to edit this file to allow communication with our Nagios server.
Open the main configuration file using a text editor like nano:
sudo nano /etc/nagios/nrpe.cfg
Inside this file, the most critical directive to modify is allowed_hosts. This setting acts as an access control list, defining which IP addresses are permitted to communicate with the NRPE agent. For security reasons, you should only add the IP address of your Nagios server.
Find the allowed_hosts line and add your Nagios server’s IP address. 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
Adding the localhost addresses (127.0.0.1,::1) is a good practice for local testing. Do not use a wildcard or a broad IP range unless absolutely necessary, as it poses a significant security risk.
Save the file and exit the editor (press Ctrl+X, then Y, then Enter in nano).
Step 3: Review and Define NRPE Commands
NRPE works by accepting a command name from the Nagios server and executing a corresponding script on the local machine. These command definitions are also located in the nrpe.cfg file.
The default installation includes several pre-configured commands for common checks, such as:
check_users: Checks the number of currently logged-in users.check_load: Checks the system load average.check_hda1: Checks disk space on the/dev/hda1partition (you will likely need to adjust this).check_zombie_procs: Checks for zombie processes.
You can customize these or add your own. For example, to create a command that checks the disk space on your root partition (/), you would add a line like this to nrpe.cfg:
command[check_root_disk]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /
This defines a command named check_root_disk that will trigger a warning if the root partition has less than 20% free space and a critical alert if it has less than 10%.
Step 4: Configure the Firewall
For the Nagios server to connect to the NRPE agent, you must open the NRPE port in your firewall. The default port for NRPE is 5666.
If you are using UFW (Uncomplicated Firewall), the best practice is to only allow access from your specific Nagios server IP address. This adds an essential layer of security.
Run the following command, replacing 192.168.1.100 with your Nagios server’s IP:
sudo ufw allow from 192.168.1.100 to any port 5666 proto tcp
After adding the rule, reload UFW to apply the changes:
sudo ufw reload
Step 5: Restart and Enable the NRPE Service
With the configuration complete, you need to restart the NRPE service to apply the changes. It’s also wise to enable the service so it starts automatically on system boot.
sudo systemctl restart nagios-nrpe-server
sudo systemctl enable nagios-nrpe-server
You can verify that the service is running correctly with the following command:
sudo systemctl status nagios-nrpe-server
Look for an “active (running)” status in the output.
Step 6: Verify the Connection from the Nagios Server
The final step is to test the connection from your Nagios monitoring server. Log into your Nagios server’s command line and use the check_nrpe plugin to query the new Debian client.
First, test the basic connection. Replace <debian_client_ip> with the IP address of the Debian machine you just configured:
/usr/lib/nagios/plugins/check_nrpe -H <debian_client_ip>
If successful, you should see the NRPE version number returned, like: NRPE v4.0.3
Next, test one of the configured commands, such as check_load:
/usr/lib/nagios/plugins/check_nrpe -H <debian_client_ip> -c check_load
A successful response will show the system load statistics, confirming that your agent is correctly configured and ready to be integrated into your Nagios monitoring setup. You can now add service checks for this host in your Nagios configuration files.
Source: https://kifarunix.com/install-nagios-nrpe-agents-on-debian-11-debian-10/


