Installation of NRPE daemon with its Prerequisites

In this section, you are going to install NRPE Daemon with its required Nagios plug-ins for monitoring of the web server using NRPE (Nagios Remote Plugin Executor). It is to be remembered that the NRPE daemon is a plug-in used by the remote hosts (or servers) and hence, it should be understood that the NRPE daemon will be installed on the remote host.
Log into your web server and create a Nagios user for NRPE agent using the below command.

sudo useradd nagios

Installation of Nagios Plug-ins

Step 1: Updating the Packages

Now, you need to install the NRPE which requires the development libraries as similar to the check_nrpe installation section.
To update the package sources and install NRPE along with its libraries, use the command:

sudo apt update
sudo apt install autoconf gcc libmcrypt-dev make libssl-dev wget dc build-essential gettext

Step 2: Downloading Nagios Plug-ins

NRPE requires the Nagios plug-ins to work properly. Install the Nagios plug-ins from the source and make sure you installed the same plug-ins which you once used to install the Nagios server.
To download the latest stable version of the plug-in bundle, go to nagios-plugins.org/
Download the Nagios plug-ins using the curl command.

curl -L -O https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz

Step 3: Configuring Plug-ins

Extract the Nagios plug-in which you downloaded in the previous step.

tar zxf nagios-plugins-2.2.1.tar.gz

Enter the extracted directory using the below command,

cd nagios-plugins-2.2.1

Next, configure the Nagios plug-in.

./configure

Post configuring the Nagios plug-in, it’s time to install and build the plug-ins.

sudo make
sudo make install
Now, that we have completed installing and configuring the required plug-ins for the installation of NRPE daemon, let us now move forward with the installation process of NRPE daemon.

Installation of NRPE daemon

Step 1: Installing NRPE

Install the latest stable version of NRPE daemon using the curl command.
For the latest stable version of NRPE daemon, https://github.com/NagiosEnterprises/nrpe/releases.

curl -L -O https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-3.2.1/nrpe-3.2.1.tar.gz

Extract the NRPE downloaded file.

tar zxf nrpe-3.2.1.tar.gz

Enter the extracted directory using the below command,

cd nrpe-3.2.1

Step 2: Configuring NRPE

Configure the NRPE using the command:

./configure

Next, build and install NRPE and its startup script using the following commands:

sudo make nrpe
sudo make install-daemon
sudo make install-config
sudo make install-init

Next, check the disk usage and file system to update the Nagios configuration file, using the below command,

df -h /

Post which, you will see an output like below,

Output
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 25G 1.4G 23G 6% /

Now start the NRPE configuration using the following configuration file,

/usr/local/nagios/etc/nrpe.cfg

Open the NRPE configuration file using the below command,

sudo nano /usr/local/nagios/etc/nrpe.cfg

Now, you need to find the following directives in nrpe.cfg file.

server_Address
allowed_hosts
command[check_hda1]

Note: 

  1. Server_Address: You need to set the IP address of your web server you wish to monitor. 
  2. Allowed_Host: Here, add your IP address of the Nagios server.
  3. Command[check_hda1]: Check the disk

Now, you need to change the filesystem type which you observed in the above sections using the df -h command.
Locate those lines and update the corresponding values.

…
server_address=webserver_ip
...
allowed_hosts=127.0.0.1,::1,your_nagios_server_private_ip
...
command[check_vda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/vda1
…

Note: Since the nrpe.cfg file contains lot of attributes, it is better to arrange the above directories as per the ease of identification, to say, at a single place in the file.

Step 3: Restarting NRPE

Once you complete doing the above changes, restart the NRPE service using below command,

sudo systemctl start nrpe.service

To verify the NRPE service, use the command:

sudo systemctl status nrpe.service

For which you’ll get an output like below,

Output
...
Aug 01 06:28:31 client systemd[1]: Started Nagios Remote Plugin Executor.
Aug 01 06:28:31 client nrpe[8021]: Starting up daemon
Aug 01 06:28:31 client nrpe[8021]: Server listening on 0.0.0.0 port 5666.
Aug 01 06:28:31 client nrpe[8021]: Server listening on :: port 5666.
Aug 01 06:28:31 client nrpe[8021]: Listening for connections on port 5666
Aug 01 06:28:31 client nrpe[8021]: Allowing connections from: 127.0.0.1,::1,192.168.2.17

Step 4: Enabling Firewall

To ensure a secure connection, you need to use UFW. For that, you need to allow the NRPE service port number in the firewall. The port number of NRPE is 5666.

sudo ufw allow 5666/tcp

Note: In case, if you want to monitor more hosts, follow the above nrpe.cfg file and create multiple files using those directories. After the successful configuration of NRPE, you need to add the same host details in the Nagios server before you check to access the Nagios web interface.

Step 5: Verifying the Connection Between the Servers

Now, you need to confirm whether the Nagios server and web server do possess the communication. To confirm, make sure you logged into Nagios server,

/usr/local/nagios/libexec/check_nrpe -H webserver_ip

You’ll see the following output:

Output
NRPE v3.2.1

Monitoring Configuration with Nagios Server

Step 1: Creating Files

Here, you need to define the host and service details for the host which you going to monitor.
You need to create a separate file for each host and eventually add the host details on the Nagios web interface.
Create a separate file for each of the hosts in the following directory.

cd /usr/local/nagios/etc/servers/

Next, create a new file using your remote server’s domain name.

sudo nano /usr/local/nagios/etc/servers/remote_host_name.cfg

Step 2: Defining Hosts

After creating the file, add and define the host and service details for your remote host, using the remote_host_name.cfg file.

define host {
use linux-server
host_name remote_host_name
alias My client server
address remote_host_ip_address
max_check_attempts 5
check_period 24x7
notification_interval 30
notification_period 24x7
}

In this code, you need to update the values of host_name, alias and address.

host_name is the domain name of your remote server which you going to monitor,
alias is the name for identification purposes and finally,
address is the IP address of your remote server.
This is just a basic configuration, it shows only whether your remote server is up or down. Hence, it’s not sufficient, so you need to add more services for these hosts. Let’s add the services.

Step 3: Adding Additional Services

Here, add the following services such as Load Average, Disk Usage, CPU Load, Total Processes and Current Users in your remote_host_name.cfg file.
Add the services after your Host Section using the below file,

sudo nano /usr/local/nagios/etc/servers/remote_host_name.cfg
#Host Section
define host {
use linux-server
host_name remote_host_name
alias My client server
address remote_host_ip_address
max_check_attempts 5
check_period 24x7
notification_interval 30
notification_period 24x7
}
#Add the Load Average service
define service {
use generic-service
host_name remote_host_name
service_description Load average
check_command check_nrpe!check_load
}
#Add the Disk Usage service
define service {
use generic-service
host_name remote_host_name
service_description /dev/vda1 free space
check_command check_nrpe!check_vda1
}
#Add the CPU Load service
define service {
use generic-service
host_name remote_host_name
service_description CPU Load
check_command check_nrpe!check_load
}
#Add the Total Process service
define service {
use generic-service
host_name remote_host_name
service_description Total Processes
check_command check_nrpe!check_total_procs
}
#Add the Current Users service
define service {
use generic-service
host_name remote_host_name
service_description Current Users
check_command check_nrpe!check_users
}

Step 4: Testing the Nagios Host

After adding the above services, you need to restart the Nagios service using the following command,

sudo systemctl restart nagios

Next, go to the Nagios web interface and click ‘Hosts’ presents at the left-side panel of your Nagios dashboard.
Post which, you will able to see the host and other services which you are already included in the previous sections.
nagios-monitoring-page-testing-nagios

Conclusion

Hereby, we have successfully installed and configured the Nagios server. Further, we have installed the check_nrpe in the web server and NRPE daemon in the remote server (host) along with it’s required plug-ins. Also, it is to be remembered that we have configured only one remote host if you want to monitor multiple hosts, follow similar procedures as we did for configuring a single remote host. Post the successful activation of Nagios, apart from the monitoring services, it also provides you with the alerting services. This alerting service of Nagios helps you to receive an email notification at the times when a critical error occurs and gets resolved.