Set up Nagios Core 4.5 distributed monitoring with NRPE for remote host checks

Intermediate 45 min May 07, 2026 84 views
Ubuntu 24.04 Debian 12 AlmaLinux 9 Rocky Linux 9

Configure Nagios Core server with NRPE agents for distributed monitoring across multiple servers. Set up remote host checks, service monitoring, and centralized alerting for comprehensive infrastructure oversight.

Prerequisites

  • Root or sudo access
  • Multiple Linux servers to monitor
  • Basic knowledge of systemctl and Apache
  • Email server or SMTP relay for notifications

What this solves

Nagios Core provides centralized monitoring for servers, services, and network devices across your infrastructure. This setup uses NRPE (Nagios Remote Plugin Executor) to run checks on remote hosts, giving you visibility into CPU usage, disk space, memory consumption, and custom services from a single dashboard.

Step-by-step installation

Update system packages

Start by updating your package manager on both the Nagios server and remote hosts.

sudo apt update && sudo apt upgrade -y
sudo dnf update -y

Install build dependencies on Nagios server

Install the packages needed to compile Nagios Core from source.

sudo apt install -y wget build-essential apache2 php libapache2-mod-php7.4 php-gd libgd-dev unzip
sudo dnf groupinstall -y "Development Tools"
sudo dnf install -y httpd php php-cli gcc glibc glibc-common wget unzip gd gd-devel

Create Nagios user and group

Create a dedicated system user for running Nagios services.

sudo groupadd nagios
sudo useradd -g nagios -d /home/nagios -s /bin/bash nagios
sudo usermod -a -G nagios www-data

Download and compile Nagios Core 4.5

Download the latest Nagios Core source code and compile it.

cd /tmp
wget https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.5.0.tar.gz
tar xzf nagios-4.5.0.tar.gz
cd nagioscore-nagios-4.5.0

Configure and compile the source code.

sudo ./configure --with-httpd-conf=/etc/apache2/sites-enabled
sudo make all
sudo make install
sudo make install-init
sudo make install-config
sudo make install-webconf

Download and install Nagios plugins

Install the official Nagios monitoring plugins for basic system checks.

cd /tmp
wget https://github.com/nagios-plugins/nagios-plugins/archive/release-2.4.6.tar.gz
tar xzf release-2.4.6.tar.gz
cd nagios-plugins-release-2.4.6
sudo ./tools/setup
sudo ./configure
sudo make
sudo make install

Create Nagios web interface user

Set up authentication for the Nagios web interface.

sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Enter a strong password when prompted. This user will have full access to the Nagios web interface.

Configure Apache web server

Enable required Apache modules and start the web server.

sudo a2enmod rewrite
sudo a2enmod cgi
sudo systemctl enable apache2
sudo systemctl start apache2
sudo systemctl enable httpd
sudo systemctl start httpd

Start and enable Nagios service

Configure Nagios to start automatically and verify the configuration.

sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

If the configuration check passes, start the service.

sudo systemctl enable nagios
sudo systemctl start nagios

Configure NRPE on remote hosts

Install NRPE daemon on remote hosts

Install NRPE and monitoring plugins on each server you want to monitor.

sudo apt install -y nagios-nrpe-server nagios-plugins-basic
sudo dnf install -y epel-release
sudo dnf install -y nrpe nagios-plugins-all

Configure NRPE daemon

Edit the NRPE configuration to allow connections from your Nagios server.

allowed_hosts=127.0.0.1,203.0.113.10

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,.05 -c .30,.25,.20
command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1
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
command[check_disk_root]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /
command[check_memory]=/usr/lib/nagios/plugins/check_mem -w 80 -c 90

Replace 203.0.113.10 with your Nagios server's IP address.

Configure firewall for NRPE

Open port 5666 for NRPE communication on remote hosts.

sudo ufw allow from 203.0.113.10 to any port 5666
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="203.0.113.10" port protocol="tcp" port="5666" accept'
sudo firewall-cmd --reload

Start NRPE service on remote hosts

Enable and start the NRPE daemon on each remote host.

sudo systemctl enable nrpe
sudo systemctl start nrpe

Configure distributed monitoring on Nagios server

Install check_nrpe plugin

Install the NRPE plugin on your Nagios server to communicate with remote hosts.

sudo apt install -y nagios-nrpe-plugin
sudo dnf install -y nrpe

Define NRPE command

Add the check_nrpe command definition to your Nagios configuration.

define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

Create host configuration for remote servers

Create a configuration file for your remote hosts.

define host{
use linux-server
host_name web-server-01
alias Web Server 01
address 203.0.113.20
max_check_attempts 5
check_period 24x7
notification_interval 30
notification_period 24x7
}

define hostgroup{
hostgroup_name remote-servers
alias Remote Linux Servers
members web-server-01
}

Define service checks for remote hosts

Configure specific service checks that will run via NRPE.

define service{
use generic-service
host_name web-server-01
service_description CPU Load
check_command check_nrpe!check_load
}

define service{
use generic-service
host_name web-server-01
service_description Current Users
check_command check_nrpe!check_users
}

define service{
use generic-service
host_name web-server-01
service_description Root Disk Usage
check_command check_nrpe!check_disk_root
}

define service{
use generic-service
host_name web-server-01
service_description Total Processes
check_command check_nrpe!check_total_procs
}

Include remote server configuration

Add your remote server configuration to the main Nagios config file.

# Add this line to include remote server configurations
cfg_file=/usr/local/nagios/etc/objects/remote-servers.cfg

Configure contact groups and notifications

Set up email notifications for monitoring alerts.

define contact{
contact_name nagiosadmin
use generic-contact
alias Nagios Admin
email admin@example.com
}

define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members nagiosadmin
}

Configure alerting and notifications

Install mail transport agent

Install a mail server to send notification emails.

sudo apt install -y postfix mailutils
sudo dnf install -y postfix mailx
sudo systemctl enable postfix
sudo systemctl start postfix

Configure Postfix as a satellite system when prompted during installation.

Test email notifications

Verify that email notifications work properly.

echo "Test email from Nagios server" | mail -s "Nagios Test" admin@example.com

Configure notification commands

Ensure notification commands are properly defined in your commands configuration.

define command{
command_name notify-host-by-email
command_line /usr/bin/printf "%b" " Nagios \n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mail -s " $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ " $CONTACTEMAIL$
}

define command{
command_name notify-service-by-email
command_line /usr/bin/printf "%b" " Nagios \n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/bin/mail -s " $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ " $CONTACTEMAIL$
}

Restart Nagios and verify configuration

Check the configuration and restart all services.

sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

If no errors are reported, restart the services.

sudo systemctl restart nagios
sudo systemctl restart apache2

Set up monitoring dashboards

Configure firewall for web interface

Allow HTTP traffic to access the Nagios web interface.

sudo ufw allow 'Apache Full'
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

Access the web interface

Open your web browser and navigate to the Nagios web interface.

http://your-nagios-server-ip/nagios

Log in with the username nagiosadmin and the password you set earlier. You should see the main Nagios dashboard with your hosts and services.

Create custom service groups

Organize your services into logical groups for better dashboard organization.

define servicegroup{
servicegroup_name system-resources
alias System Resources
members web-server-01,CPU Load,web-server-01,Root Disk Usage
}

define servicegroup{
servicegroup_name processes
alias Process Monitoring
members web-server-01,Total Processes,web-server-01,Current Users
}

Verify your setup

Test the complete monitoring setup with these verification commands.

# Check Nagios service status
sudo systemctl status nagios

# Verify NRPE connectivity from Nagios server
/usr/lib/nagios/plugins/check_nrpe -H 203.0.113.20

# Test specific NRPE commands
/usr/lib/nagios/plugins/check_nrpe -H 203.0.113.20 -c check_load
/usr/lib/nagios/plugins/check_nrpe -H 203.0.113.20 -c check_disk_root

# Check configuration syntax
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

All checks should return OK status. If you encounter issues, check the centralized logging setup to help troubleshoot problems across your infrastructure.

Common issues

SymptomCauseFix
NRPE connection refusedFirewall blocking port 5666Open port 5666 on remote host firewall
CHECK_NRPE: Socket timeoutNRPE daemon not runningsudo systemctl start nrpe on remote host
NRPE: Command not definedCommand missing in nrpe.cfgAdd command definition in /etc/nagios/nrpe.cfg
Nagios web interface 403 errorApache configuration issueCheck /etc/apache2/sites-enabled/nagios.conf permissions
Email notifications not workingPostfix not configuredConfigure Postfix relay host and test with mail command
Service checks return criticalIncorrect plugin pathVerify plugin paths in /etc/nagios/nrpe.cfg

Next steps

Running this in production?

Want this handled for you? Setting this up once is straightforward. Keeping it patched, monitored, backed up and tuned across environments is the harder part. See how we run infrastructure like this for European SaaS and e-commerce teams.

Automated install script

Run this to automate the entire setup

Need help?

Don't want to manage this yourself?

We handle managed devops services for businesses that depend on uptime. From initial setup to ongoing operations.