1080*80 ad

How to Install Nagios NRPE Agents on Ubuntu 22.04 and 20.04

Setting up effective monitoring for your servers is crucial, and Nagios is a popular choice for many system administrators. To monitor remote Linux machines with Nagios, you typically need to install and configure an agent. The Nagios Remote Plugin Executor, or NRPE, is the standard way to execute plugins on remote Linux/Unix hosts and report the results back to your central Nagios server. This guide will walk you through installing and configuring the NRPE agent on Ubuntu 22.04 and Ubuntu 20.04 systems.

Why Install NRPE?

Nagios works by running checks to see if services or resources are functioning correctly. For local checks on the Nagios server itself (like disk space or CPU load on the Nagios server), this is straightforward. However, to check resources or services on a remote machine, Nagios needs a way to communicate with that machine and run commands locally on the remote machine. NRPE provides this secure communication channel. It listens for requests from the Nagios server, runs the specified plugin (like check_disk or check_users) on the remote machine, and sends the output and return code back to the Nagios server.

Prerequisites

Before you begin, ensure you have:

  • Access to a user account with sudo privileges on the Ubuntu server where you want to install the NRPE agent.
  • A working Nagios monitoring server configured and ready to receive data.
  • Network connectivity between the Ubuntu server and the Nagios server.

Step 1: Update Your Ubuntu System

It’s always a good practice to start by updating your package lists and upgrading installed packages to their latest versions. Open a terminal on your Ubuntu server and run:

sudo apt update
sudo apt upgrade -y

This ensures you have the latest security patches and necessary dependencies.

Step 2: Install NRPE Agent and Dependencies

The easiest and most recommended way to install NRPE on Ubuntu is using the APT package manager. The necessary packages are usually available in the default repositories.

Install the NRPE agent package along with the standard Nagios plugins:

sudo apt install nagios-nrpe-server nagios-plugins -y
  • nagios-nrpe-server: This is the actual NRPE daemon that runs on your Ubuntu server.
  • nagios-plugins: This package contains the common plugins (like check_cpu, check_disk, check_load, etc.) that NRPE will execute.

Step 3: Configure the NRPE Daemon

The main configuration file for NRPE is /etc/nagios/nrpe.cfg. You need to edit this file to allow your Nagios server to connect and potentially define custom commands.

Open the configuration file using your preferred text editor (like nano or vim):

sudo nano /etc/nagios/nrpe.cfg

Identify the allowed_hosts line. By default, it might be commented out or set to 127.0.0.1. You must change this line to include the IP address of your Nagios monitoring server. If you have multiple Nagios servers or specific allowed networks, you can list them separated by commas.

Find this line:

#allowed_hosts=127.0.0.1

Or similar. Change it to:

allowed_hosts=127.0.0.1,your_nagios_server_ip

Replace your_nagios_server_ip with the actual IP address of your Nagios server. Keeping 127.0.0.1 is generally fine if you might run local checks via NRPE, but the critical part is adding your Nagios server’s IP.

Optional: Configure Custom Commands

Further down in the nrpe.cfg file, you will see lines defining commands, like command[check_users]. These lines map a command name (used by the Nagios server) to the actual plugin command that NRPE will execute on the Ubuntu server.

Example:

command[check_users]=/usr/lib/nagios/plugins/check_users $ARG1$
command[check_disk]=/usr/lib/nagios/plugins/check_disk $ARG1$

You can uncomment existing commands or add new ones here if you need to run specific checks that aren’t enabled by default or require custom parameters. Be very careful when defining commands, as this could pose a security risk if not done properly. Ensure the Nagios plugins (check_users, check_disk, etc.) exist in the specified directory, which is typically /usr/lib/nagios/plugins/ or /usr/local/nagios/libexec/.

Save the changes to nrpe.cfg and close the editor.

Step 4: Allow NRPE Through the Firewall (UFW)

If your Ubuntu server is running the UFW (Uncomplicated Firewall), you need to allow incoming connections on the standard NRPE port, which is 5666.

Run the following command:

sudo ufw allow 5666/tcp

If UFW is not active, you might need to enable it first:

sudo ufw enable

Verify the rule was added:

sudo ufw status

You should see the rule allowing traffic on port 5666.

Step 5: Restart the NRPE Service

After making changes to the configuration file and firewall, you need to restart the NRPE service to apply the changes.

sudo systemctl restart nagios-nrpe-server

You can also check the status of the service to ensure it’s running correctly:

sudo systemctl status nagios-nrpe-server

Look for output indicating the service is active (running).

Step 6: Test the NRPE Agent from Your Nagios Server

To confirm the NRPE agent is running and accessible from your Nagios monitoring server, log in to your Nagios server and use the check_nrpe command.

You might need to install the check_nrpe plugin on your Nagios server if you haven’t already:

sudo apt install nagios-plugins-standard check-nrpe -y

(The package name might vary slightly depending on your Nagios server’s OS, but check-nrpe is common).

Now, run a test command, such as checking the NRPE version:

/usr/lib/nagios/plugins/check_nrpe -H your_ubuntu_server_ip

Replace your_ubuntu_server_ip with the actual IP address of the Ubuntu server where you installed the NRPE agent.

If the connection is successful and NRPE is running, this command should return the NRPE version number installed on the Ubuntu server.

You can also test a predefined command, like check_disk:

/usr/lib/nagios/plugins/check_nrpe -H your_ubuntu_server_ip -c check_disk

This should execute the check_disk command on the Ubuntu server via NRPE and return the status and output to your Nagios server.

If these tests are successful, your NRPE agent is correctly installed, configured, and ready for you to define checks for this host within your Nagios server’s configuration.

Conclusion

Installing the Nagios NRPE agent on Ubuntu 22.04 and 20.04 systems is a straightforward process involving installing packages, configuring the daemon to allow connections from your Nagios server, and opening the firewall. With the NRPE agent successfully deployed, you can now leverage the power of Nagios to monitor various aspects of your Ubuntu servers remotely, ensuring the stability and performance of your infrastructure. Remember to add the new host to your Nagios server’s configuration files to start monitoring it officially.

Source: https://kifarunix.com/install-nagios-nrpe-agents-on-ubuntu-22-04-ubuntu-20-04/

900*80 ad

      1080*80 ad