Nagios is a powerful open-source monitoring tool that helps us to monitor your servers, services, and overall network infrastructure. The Nagios Remote Plugin Executor (NRPE) is a client-side application that used to execute program on remote systems for monitoring. Nagios server connects to NRPE client with instruction to execute a command, NRPE executed that command and send result back to Nagios server.
This tutorial will help you through the installation and configuration of the Nagios NRPE client on Ubuntu 22.04 Linux system, the same instructions can be used with other Ubuntu versions.
Prerequisites
- Ubuntu 22.04 server with sudo access
- Nagios server up and running (for further instructions, consult the Nagios documentation)
Step 1: Update Your System
Before installing any software, it’s essential to update your system. Open a terminal and run the following command:
sudo apt update && sudo apt upgrade -y
Step 2: Install Nagios NRPE Client
The Nagios Remote Plugin Executor (NRPE) packages are readily available in the default repositories on Ubuntu systems. To install them, open a terminal and enter the following command:
sudo apt update
sudo apt install nagios-nrpe-server nagios-plugins
The nagios-nrpe-server package installs the NRPE service on the system, while nagios-plugins provides monitoring scripts that are executed by the NRPE client upon request from the Nagios server.
Step 3: Configuring Nagios Client
At very first, you need to configure NRPE client that from which Nagios servers the client accepts requests. For example, if the Nagios server’s IP is 192.168.1.100, add this IP to the allowed hosts list. Edit the NRPE configuration file located at /etc/nagios/nrpe.cfg and make the necessary changes, as shown below:
sudo nano /etc/nagios/nrpe.cfg
Search for `allowed_hosts` and add your Nagios server IP address.
allowed_hosts=127.0.0.1, 192.168.1.100
You can allow multiple Nagios servers by providing a comma-separated list.
Next, restart the NRPE service to apply the changes:
sudo systemctl restart nagios-nrpe-server
Step 4: Verify Connection from Nagios
To verify the connection between the Nagios server and the NRPE client, log in to your Nagios server and check if it can communicate with the NRPE service properly.
Use the check_nrpe command on the Nagios server, located in the plugins directory, to check the connection. The command will be like this, where 192.168.1.11 is the IP address of the client machine:
check_nrpe -H 192.168.1.11
If successful, the output should be “NRPE v4.0.0”, indicating that the Nagios server has successfully communicated with NRPE.
Step 5: Update Command Definitions for NRPE
You must define all the commands to be used by the Nagios server. Some of them are pre-configured with the installation, while others need to be updated or customized as per your system’s configuration.
Edit the `/etc/nagios/nrpe.cfg` configuration file and search for the COMMAND DEFINITIONS section. Here, you can define or update check commands as needed, as shown below:
sudo nano /etc/nagios/nrpe.cfg
Search for below command options and update according to your need.
command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_disk]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda1
command[check_backup_disk]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda2
command[check_zombie_procs]=/usr/lib/nagios/plugins/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/lib/nagios/plugins/check_procs -w 150 -c 200
Save the configuration file and restart the NRPE daemon to apply the changes:
sudo systemctl restart nagios-nrpe-server
Step 6: Adjust Firewall
By default, the NRPE service listens on port 5666. Use the following commands to open the firewall port for the NRPE service:
sudo firewall-cmd --permanent --zone=public --add-port=5666/tcp
sudo firewall-cmd --reload
Conclusion
In conclusion, setting up the Nagios client on an Ubuntu system is a straightforward process that involves installing the NRPE packages, configuring the NRPE client, verifying the connection between the Nagios server and the NRPE client, updating command definitions for NRPE, and adjusting the firewall to allow incoming requests on port 5666. By following the steps outlined in this tutorial, you can easily monitor your Ubuntu system’s performance and health using Nagios, which is a powerful and popular open-source monitoring solution.