2026年11月12日

2026年11月12日

Install and Configure Nagios Core on Ubuntu with NRPE Remote Checks

This article is a localized edition of the Japanese original. Read the Japanese original

Nagios Core is open-source monitoring software that periodically checks servers, network devices and websites and sends notifications when something goes wrong. This article covers installing Nagios Core on the monitoring server (the "Nagios server" below) up to logging in to the web interface, and installing NRPE on the server being monitored (the "monitored host" below) to watch disk usage and load.

The steps follow the Ubuntu 22.x/24.x instructions in "Installing Nagios Core From Source" in the official Nagios knowledge base. The versions are the latest as of November 2026: Nagios Core 4.5.14, Nagios Plugins 2.5 and NRPE 4.2.0. If newer releases are out, check the numbers on each project's GitHub releases page and substitute them.

How Nagios is put together

Component Where it runs Role
Nagios Core Nagios server The core that schedules checks, shows results in the web interface and sends notifications
Nagios Plugins Nagios server (and monitored hosts) Small programs such as check_ping, check_http and check_disk that perform the actual checks
NRPE Monitored host A daemon that runs plugins on the monitored host at the Nagios server's request and returns the results
check_nrpe Nagios server The plugin that asks NRPE to run a check

Things you can check from outside, such as ping and HTTP, can be monitored from the Nagios server alone. Things you can only see from inside, such as disk usage and load, are checked by running plugins on the monitored host through NRPE.

Install Nagios Core on the Nagios server

Run the following on Ubuntu 24.04.

Required packages

sudo apt-get update
sudo apt-get install -y autoconf gcc libc6 make wget unzip apache2 php libapache2-mod-php libgd-dev ufw
sudo apt-get install -y openssl libssl-dev

Download and compile the source

cd /tmp
wget https://github.com/NagiosEnterprises/nagioscore/releases/download/nagios-4.5.14/nagios-4.5.14.tar.gz
tar xzf nagios-4.5.14.tar.gz
cd nagios-4.5.14
sudo ./configure --with-httpd-conf=/etc/apache2/sites-enabled
sudo make all

Install

# Create the nagios user and group, and add Apache's user to the nagios group
sudo make install-groups-users
sudo usermod -a -G nagios www-data

# Install the binaries, the systemd unit, the external command setup, the sample config and the Apache config
sudo make install
sudo make install-daemoninit
sudo make install-commandmode
sudo make install-config
sudo make install-webconf

# Apache modules needed by the web interface CGIs
sudo a2enmod rewrite
sudo a2enmod cgi

Nagios is installed under /usr/local/nagios/. The configuration files are in /usr/local/nagios/etc/, and the Apache configuration is /etc/apache2/sites-enabled/nagios.conf.

Create the web interface login user

The web interface is protected by Basic authentication. Create the admin user nagiosadmin and set its password.

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

-c creates a new file. When you add more users, run the command without -c (with it, the existing users are deleted).

Firewall and startup

sudo ufw allow Apache
sudo ufw reload

sudo systemctl restart apache2.service
sudo systemctl start nagios.service
sudo systemctl enable nagios.service

Open http://NAGIOS_SERVER_IP/nagios/ (replace NAGIOS_SERVER_IP with the Nagios server's IP address) in a browser and log in as nagiosadmin. The plugins aren't installed yet, so the checks will show errors at this point.

The web interface is an admin screen that reveals how your monitored systems are set up. If you expose it to the internet, also enable HTTPS and restrict access by source IP address.

Install Nagios Plugins

sudo apt-get install -y autoconf gcc libc6 libmcrypt-dev make libssl-dev wget bc gawk dc build-essential snmp libnet-snmp-perl gettext iputils-ping

cd /tmp
wget https://github.com/nagios-plugins/nagios-plugins/releases/download/release-2.5/nagios-plugins-2.5.tar.gz
tar zxf nagios-plugins-2.5.tar.gz
cd nagios-plugins-2.5
sudo ./configure
sudo make
sudo make install

The plugins are installed in /usr/local/nagios/libexec/. In the configuration files, $USER1$ points to this directory. You can run a plugin on its own to see that it works.

/usr/local/nagios/libexec/check_ping -H 127.0.0.1 -w 100,20% -c 500,60%

-w is the WARNING threshold and -c the CRITICAL threshold; 100,20% means "100 ms response time, 20% packet loss".

After you restart Nagios, the localhost checks under "Services" in the web interface turn OK.

sudo systemctl restart nagios.service

Install NRPE on the monitored host

From here on, work on the monitored host (Ubuntu in this example). NRPE and the standard plugins are available as Ubuntu packages.

sudo apt-get update
sudo apt-get install -y nagios-nrpe-server monitoring-plugins

The configuration file is /etc/nagios/nrpe.cfg, and the plugins go in /usr/lib/nagios/plugins/.

Specify the Nagios server allowed to connect

Add the Nagios server's IP address (192.0.2.5 in the example) to allowed_hosts in /etc/nagios/nrpe.cfg. Requests from hosts not listed here are refused.

allowed_hosts=127.0.0.1,::1,192.0.2.5

Define the commands NRPE may run

NRPE only runs commands defined in its configuration as command[NAME]=. You can put additional configuration files in /etc/nagios/nrpe.d/.

# /etc/nagios/nrpe.d/local.cfg
command[check_load]=/usr/lib/nagios/plugins/check_load -r -w 2,1.5,1 -c 4,3,2
command[check_root_disk]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /
command[check_total_procs]=/usr/lib/nagios/plugins/check_procs -w 250 -c 400

check_disk -w 20% -c 10% goes WARNING when free space drops below 20% and CRITICAL below 10%. check_load -r evaluates the load divided by the number of CPUs.

Apply and open the firewall

NRPE listens on TCP port 5666. Allow connections from the Nagios server only.

sudo systemctl restart nagios-nrpe-server
sudo ufw allow from 192.0.2.5 to any port 5666 proto tcp

Install check_nrpe on the Nagios server

Back on the Nagios server, install only the check_nrpe plugin from the NRPE source.

cd /tmp
wget https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-4.2.0/nrpe-4.2.0.tar.gz
tar xzf nrpe-4.2.0.tar.gz
cd nrpe-4.2.0
sudo ./configure
sudo make all
sudo make install-plugin

Check that you can reach NRPE on the monitored host. In this example the monitored host's IP address is 192.0.2.10.

# If the NRPE version comes back, the connection works
/usr/local/nagios/libexec/check_nrpe -H 192.0.2.10

# Run a command you defined
/usr/local/nagios/libexec/check_nrpe -H 192.0.2.10 -c check_root_disk

If you can't connect, check allowed_hosts and the firewall on the monitored host, and systemctl status nagios-nrpe-server.

Register the monitored host in Nagios

Define check_nrpe as a command

Append the following to the end of /usr/local/nagios/etc/objects/commands.cfg.

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

Define the host and services

Keeping each monitored host's configuration in a separate directory makes it easier to manage. In /usr/local/nagios/etc/nagios.cfg, remove the leading # from the following line.

cfg_dir=/usr/local/nagios/etc/servers

Create the directory and write the monitored host's configuration.

sudo mkdir -p /usr/local/nagios/etc/servers
# /usr/local/nagios/etc/servers/web01.cfg
define host {
    use                     linux-server
    host_name               web01
    alias                   WordPress Web Server
    address                 192.0.2.10
}

define service {
    use                     generic-service
    host_name               web01
    service_description     PING
    check_command           check_ping!100.0,20%!500.0,60%
}

define service {
    use                     generic-service
    host_name               web01
    service_description     HTTP
    check_command           check_http
}

define service {
    use                     generic-service
    host_name               web01
    service_description     Root Disk
    check_command           check_nrpe!check_root_disk
}

define service {
    use                     generic-service
    host_name               web01
    service_description     Load
    check_command           check_nrpe!check_load
}

linux-server and generic-service are templates defined in the sample templates.cfg installed by make install-config; they hold defaults such as check intervals and notification contacts. The values after ! are passed to $ARG1$, $ARG2$ in the command definition.

Validate and apply the configuration

Whenever you change the configuration, validate it before applying, because Nagios won't start if there are errors.

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

If the output ends with "Total Warnings: 0" and "Total Errors: 0", you're fine. Otherwise fix the file and line number shown in the error, then restart Nagios.

sudo systemctl restart nagios.service

web01 appears under "Hosts" in the web interface and the four checks under "Services", with results within a few minutes.

Cautions

  • Widening NRPE's allowed_hosts, or setting dont_blame_nrpe=1 so arguments can be passed in from outside, risks letting outsiders do something close to running arbitrary commands. Leave the defaults unless you need to change them.
  • Checking too often increases the load on the monitored host. Start with the intervals in the sample templates and shorten them only where needed.
  • To get email notifications, change the email address of nagiosadmin in contacts.cfg and make sure the Nagios server can send mail.

Notification setup is covered in "How to set up availability monitoring and alerts in Nagios", and adding your own checks in "How to add Nagios plugins for custom monitoring".

Questions about WordPress? The publisher of this site is based in Japan and replies in Japanese. Contact (Japanese)

お気軽にご相談ください

お見積りへ お問い合わせへ
▲