Install Nagios NRPE Agents on Ubuntu 22.04/Ubuntu 20.04

0
4

This guide describes how to easily install Nagios NRPE Agents on Ubuntu 22.04/Ubuntu 20.04. If you want to monitor your Ubuntu hosts using Nagios server, then you need to have the NRPE agents installed on these hosts. Nagios Remote Plugin Executor (NRPE) allows you to remotely execute Nagios plugins on other Linux/Unix machines to query machine metrics such as disk usage, CPU load, etc.

Before you can now start to monitor hosts using Nagios server, you need to add them hosts to Nagios server.

Follow the guide below to add hosts to Nagios server for monitoring.

Add Hosts to Nagios Server For Monitoring

Install Nagios NRPE Agents on Ubuntu 22.04/Ubuntu 20.04

Nagios NRPE agents:

Install Nagios NRPE Agent From Default Ubuntu Repos

NRPE agents are available on the default Ubuntu repositories.

On Ubuntu 22.04;

apt-cache policy nagios-nrpe-server
nagios-nrpe-server:
  Installed: (none)
  Candidate: 4.0.3-1ubuntu2
  Version table:
     4.0.3-1ubuntu2 500
        500 http://ke.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages

NRPE 4.0.3, which is the current stable latest release as of this writing is available for installation.

apt install nagios-nrpe-server

On Ubuntu 20.04

On Ubuntu 20.04, the default repos do not have the latest version of NRPE.

apt-cache policy nagios-nrpe-server
nagios-nrpe-server:
  Installed: (none)
  Candidate: 4.0.0-2ubuntu1
  Version table:
     4.0.0-2ubuntu1 500
        500 http://ke.archive.ubuntu.com/ubuntu focal/universe amd64 Packages

To ensure you install the latest version of Ubuntu 20.04, then you need to build from the source.

Install Nagios NRPE Agent from Source Code

You can as well build Nagios NRPE agent from the source code.

To install Nagios NRPE from source code;

Install Required Build Packages

apt update
apt install -y autoconf automake gcc libc6 libmcrypt-dev make libssl-dev wget

Download NRPE Source Archive

Next, download the current release version of NRPE source code from the releases page.

wget https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-4.0.3/nrpe-4.0.3.tar.gz

Install Nagios NRPE Agent from Source Code

Extract the source archive

tar xzf nrpe-4.0.3.tar.gz

Compile the agent;

cd nrpe-4.0.3/
./configure --enable-command-args

Sample summary;

*** Configuration summary for nrpe 4.0.3 2020-04-28 ***:

 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.
make all

Create NRPE nagios user and group;

make install-groups-users

Install NRPE binary files;

make install

Install NRPE configuration files;

make install-config

The configs are placed under /usr/local/nagios/etc directory as nrpe.cfg.

Update services file to define NRPE service and respective port on which it listens on;

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

Install NRPE service;

make install-init

This creates a systemd unit file, /lib/systemd/system/nrpe.service.

Hence you can start and enable NRPE to run on boot;

systemctl enable --now nrpe

Install Nagios Plugins on Ubuntu 22.04/Ubuntu 20.04

Download plugins from downloads page.

wget https://nagios-plugins.org/download/nagios-plugins-2.3.3.tar.gz
tar xzf nagios-plugins-2.3.3.tar.gz
cd nagios-plugins-2.3.3
./configure
make
make install

The plugins are installed under /usr/local/nagios/libexec/ directory.

How to Configure NRPE Agent

When installed from the APT repos, the default Nagios NRPE configuration is /etc/nagios/nrpe.cfg.

When installed from the source, the default configuration file is /usr/local/nagios/etc/nrpe.cfg.

The configuration files are well commented. This is how the config looks like with no comments;

grep -vE "^.*#|^$" /usr/local/nagios/etc/nrpe.cfg
log_facility=daemon
debug=0
pid_file=/usr/local/nagios/var/nrpe.pid
server_port=5666
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=127.0.0.1,::1
dont_blame_nrpe=0
allow_bash_command_substitution=0
command_timeout=60
connection_timeout=300
disable_syslog=0
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -r -w .15,.10,.05 -c .30,.25,.20
command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200

In most cases, the configs above would suffice to monitor the host agent metrics.

However, there are a few parameters that you might want to update:

allowed_hosts=127.0.0.1,::1

Update this parameter to include the IP address of the monitoring server. For example, in my setup, the IP address of the Nagios server is 192.168.56.124. Hence, this parameter is updated such that it looks like;

allowed_hosts=127.0.0.1,192.168.56.124

The others include the commands to check various metrics. Below are my updated commands based on host agent.

command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -r -w 15,10,5 -c 30,25,20
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200

The NRPE installed from the APT, the plugins path is set to /usr/lib/nagios/plugins/. The commands above would look like;

command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib/nagios/plugins/check_load -r -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_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

In general, this is how my configuration is like;

log_facility=daemon
debug=0
pid_file=/run/nagios/nrpe.pid
server_port=5666
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=127.0.0.1,::1
dont_blame_nrpe=0
allow_bash_command_substitution=0
command_timeout=60
connection_timeout=300
disable_syslog=0
command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib/nagios/plugins/check_load -r -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_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
include=/etc/nagios/nrpe_local.cfg
include_dir=/etc/nagios/nrpe.d/

Running NRPE on Ubuntu 22.04

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

systemctl enable --now nagios-nrpe-server

To check the status of NRPE agent;

systemctl status nagios-nrpe-server
● nagios-nrpe-server.service - Nagios Remote Plugin Executor
     Loaded: loaded (/lib/systemd/system/nagios-nrpe-server.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2022-05-04 19:16:00 UTC; 1s ago
       Docs: http://www.nagios.org/documentation
   Main PID: 22049 (nrpe)
      Tasks: 1 (limit: 2241)
     Memory: 1.5M
        CPU: 10ms
     CGroup: /system.slice/nagios-nrpe-server.service
             └─22049 /usr/sbin/nrpe -c /etc/nagios/nrpe.cfg -f

May 04 19:16:00 jellyfish systemd[1]: Stopping Nagios Remote Plugin Executor...
May 04 19:16:00 jellyfish nrpe[20779]: Daemon shutdown
May 04 19:16:00 jellyfish systemd[1]: nagios-nrpe-server.service: Deactivated successfully.
May 04 19:16:00 jellyfish nrpe[22049]: Starting up daemon
May 04 19:16:00 jellyfish systemd[1]: Stopped Nagios Remote Plugin Executor.
May 04 19:16:00 jellyfish nrpe[22049]: Server listening on 0.0.0.0 port 5666.
May 04 19:16:00 jellyfish systemd[1]: Started Nagios Remote Plugin Executor.
May 04 19:16:00 jellyfish nrpe[22049]: Server listening on :: port 5666.
May 04 19:16:00 jellyfish nrpe[22049]: Listening for connections on port 5666
May 04 19:16:00 jellyfish nrpe[22049]: Allowing connections from: 127.0.0.1,192.168.56.124

if you installed from the source, then the service name is nrpe.service.

systemctl start nrpe
systemctl status nrpe
● nrpe.service - Nagios Remote Plugin Executor
     Loaded: loaded (/lib/systemd/system/nrpe.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2022-05-04 19:18:41 UTC; 2s ago
       Docs: http://www.nagios.org/documentation
   Main PID: 46858 (nrpe)
      Tasks: 1 (limit: 2281)
     Memory: 668.0K
     CGroup: /system.slice/nrpe.service
             └─46858 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -f

May 04 19:18:41 ubuntu20 systemd[1]: Started Nagios Remote Plugin Executor.
May 04 19:18:41 ubuntu20 nrpe[46858]: Starting up daemon
May 04 19:18:41 ubuntu20 nrpe[46858]: Server listening on 0.0.0.0 port 5666.
May 04 19:18:41 ubuntu20 nrpe[46858]: Server listening on :: port 5666.
May 04 19:18:41 ubuntu20 nrpe[46858]: Listening for connections on port 5666
May 04 19:18:41 ubuntu20 nrpe[46858]: Allowing connections from: 127.0.0.1,192.168.56.124

Open NRPE Port on Firewall

NRPE uses port TCP 5666 by default. If firewall is running, open this port to allow external checks from Nagios Monitoring server.

ufw allow from <NAGIOS_IP> to any port 5666 proto tcp comment "Allow Connection from Nagios Server for Metrics check"

If you are using your IP tables;

apt install iptables-persistent -y
iptables -I INPUT -p tcp -s <NAGIOS_IP> --dport 5666 -j ACCEPT
iptables-save > /etc/iptables/rules.v4

Check to see if port 5666/tcp is listening;

ss -altnp | grep 5666
LISTEN    0         5                  0.0.0.0:5666             0.0.0.0:*        users:(("nrpe",pid=10345,fd=4))                                                
LISTEN    0         5                     [::]:5666                [::]:*        users:(("nrpe",pid=10345,fd=5))

If you already added hosts to Nagios and defined the services, then such is the example of how they should look on Nagios dashboard.

Hosts;

Install Nagios NRPE Agents on Ubuntu 22.04

Services;

Install Nagios NRPE Agents on Ubuntu 22.04

That is just it on how to install Nagios NRPE agents on Ubuntu 22.04.

Further Reading

Nagios Core Documentation

Other Tutorials

Install Nagios NRPE Agent on Rocky Linux 8

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

LEAVE A REPLY

Please enter your comment!
Please enter your name here