Install Nagios Core on Ubuntu 24.04: Complete Guide

Setting up Nagios on Ubuntu 24.04 gives you access to Nagios Core, a free and open-source monitoring system for networks, services, and applications. It leverages the Nagios Remote Plugin Executor (NRPE), which uses a server-agent model to connect with remote machines and monitor key metrics like CPU usage, disk utilization, and network traffic. Nagios gathers this data regularly and presents it in a user-friendly web-based interface.

This guide walks you through the full installation of Nagios on Ubuntu 24.04 and explains how to configure monitoring for a remote system.

Requirements

Before starting, make sure you have the following:

  • Two Ubuntu 24.04 systems — one for the Nagios server and the other as the remote host.

Build and Set Up Nagios Core from Source

Since Nagios Core is not included in Ubuntu 24.04’s standard repositories, you’ll need to compile and install it manually. Follow these instructions to get started.

Start by connecting to the server designated for Nagios via SSH.

Install Dependencies

Begin by installing all necessary package dependencies:

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

Prepare the Project Directory

Navigate to your home directory:

Create a directory to store Nagios Core files:

Move into the newly created directory:

Download the Source Code

Grab the most recent version of the Nagios Core source code from the official repository:

$ wget -O nagioscore.tar.gz https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.5.7.tar.gz

Extract the downloaded archive:

$ tar xzf nagioscore.tar.gz

Verify the extracted files are in the directory:

You should see an entry similar to:

nagioscore.tar.gz nagioscore-nagios-4.5.7

Enter the extracted Nagios source folder (adjust the version as needed):

$ cd nagioscore-nagios-4.5.7/

Configure and Compile Nagios

Execute the configuration script to set up a Nagios virtual host within Apache:

$ sudo ./configure --with-httpd-conf=/etc/apache2/sites-enabled

Build the Nagios Core software:

Create a dedicated Nagios group and user for the software:

$ sudo make install-groups-users

Finally, add the www-data user to the Nagios group to allow Apache access to Nagios resources:

$ sudo usermod -a -G nagios www-data

Install Nagios on the Server

Use the instructions below to install Nagios along with all its necessary components on your designated server. This includes setting up Apache modules and configuring user access for the Nagios web dashboard.

Install Core Nagios Components

Begin by installing the Nagios Core application:

Set up configuration scripts and start the Nagios daemon:

$ sudo make install-daemoninit

Install the component that enables external commands through the web interface:

$ sudo make install-commandmode

Install the Nagios configuration files:

$ sudo make install-config

Add the required Apache configuration files:

$ sudo make install-webconf

Activate the Apache rewrite module:

Activate the Apache CGI module:

Create a new basic auth user nagiosadmin and set a secure password when prompted:

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

Restart Apache to apply the changes:

$ sudo systemctl restart apache2

Install Nagios Plugins

The following steps guide you through installing Nagios plugins to monitor the local server system.

Install Plugin Dependencies

Install the required packages for building Nagios plugins:

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

Move to your home directory:

Download and Compile the Plugins

Download the latest release of Nagios plugins:

$ wget --no-check-certificate -O nagios-plugins.tar.gz https://github.com/nagios-plugins/nagios-plugins/archive/release-2.4.12.tar.gz

Unpack the downloaded archive:

$ tar zxf nagios-plugins.tar.gz

Change to the extracted directory:

$ cd nagios-plugins-release-2.4.12

Execute the setup script:

Configure the build process:

Compile the plugin binaries:

Install the compiled plugin binaries:

Validate and Start Nagios

Check the Nagios configuration for syntax errors:

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

Expected Output:

Total Warnings: 0
Total Errors: 0

Things look okay – No serious problems were detected during the pre-flight check

Enable the Nagios service to launch on startup:

$ sudo systemctl enable nagios

Start the Nagios service:

$ sudo systemctl start nagios

Access the Nagios Web Monitoring Dashboard

Use the steps below to access the Nagios monitoring interface via a web browser using the public IP address of your Nagios server.

Check Firewall Status and Configure UFW

Start by checking if the firewall is currently active:

If it is not active, enable UFW and permit SSH access to avoid being locked out:

$ sudo ufw allow ssh && sudo ufw enable

Allow HTTP traffic on port 80 to serve the web interface:

Apply the changes by reloading UFW:

Open the Nagios Dashboard in a Browser

Access the Nagios interface by entering the server’s public IP address into a browser:

http://SERVER-IP/nagios

Use the nagiosadmin account and the password you previously set to log in.

Explore the Nagios Interface

Once logged in, navigate to the Hosts section from the menu on the left side. The dashboard initially shows the monitoring status of the local machine (localhost).

To expand monitoring, you will now install plugins on a remote machine and configure the Nagios server accordingly.

Install and Configure NRPE on a Remote Host

Nagios uses the NRPE agent to monitor remote systems. This agent listens for requests from the Nagios server and provides relevant system metrics. Follow these steps to set it up on a separate Ubuntu 24.04 host.

Install NRPE and Plugins on the Remote System

First, connect to the remote server via SSH. Then install NRPE along with the required plugins:

$ sudo apt install nagios-plugins nagios-nrpe-server -y

Enable and start the NRPE service:

$ sudo systemctl enable --now nagios-nrpe-server

Allow Nagios Server Access in NRPE Configuration

Open the NRPE configuration file to define allowed hosts and permitted plugins:

$ sudo nano /etc/nagios/nrpe.cfg

Update the allowed_hosts line to include your Nagios server’s public IP address:

allowed_hosts=127.0.0.1,::1,nagios_server_IP

Save and exit the file, then restart the NRPE service to apply changes:

$ sudo systemctl restart nagios-nrpe-server

With this setup, the Nagios server is now authorized to connect to the remote machine and collect system metrics for monitoring purposes.

Configure the Nagios Server to Monitor Remote Hosts

After installing the NRPE service on a remote machine, you need to update your Nagios server’s configuration to enable monitoring of that remote system. Follow the steps below while connected to the Nagios server via SSH.

Create Configuration Directory for Remote Hosts

Begin by creating a dedicated directory to store remote host configurations:

$ sudo mkdir -p /usr/local/nagios/etc/servers/

Next, create a new configuration file to define the remote host’s details:

$ sudo nano /usr/local/nagios/etc/servers/host.cfg

Insert the following configuration into the file. Replace centron and remote-host-ip with the hostname and IP address of your actual remote host:

define host {
        use                             linux-server
        host_name                       centron
        alias                           First Remote Host
        address                         remote-host-ip
        max_check_attempts              5
        check_period                    24x7
        notification_interval           30
        notification_period             24x7
}

This configuration includes the following:

  • max_check_attempts: Number of retry attempts before marking the host as unreachable.
  • check_period: Time window when checks should run.
  • notification_interval: Time (in minutes) between alert notifications.
  • notification_period: Schedule when notifications are allowed.

Enable Remote Host Configuration

Edit the main Nagios configuration file to include your new directory:

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

Add the following line at the bottom of the file to load all configurations from the servers directory:

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

Apply and Verify Configuration Changes

Restart the Nagios service to load the new host configuration:

$ sudo systemctl restart nagios

Check the Nagios configuration for errors before finalizing the setup:

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

Expected Output:

Total Warnings: 0
Total Errors: 0

Things look okay – No serious problems were detected during the pre-flight check

Restart the Nagios service one more time to confirm all changes are in effect:

$ sudo systemctl restart nagios

Verify Remote Host on the Dashboard

In your browser, revisit the Nagios web dashboard:

http://SERVER-IP/nagios

Navigate to the Hosts section. You should now see both the localhost and the newly added remote host listed.

Conclusion

You’ve successfully installed and configured Nagios on Ubuntu 24.04 to monitor both local and remote systems. The web interface now provides a centralized view of all

Source: vultr.com

Create a Free Account

Register now and get access to our Cloud Services.

Posts you might be interested in:

Moderne Hosting Services mit Cloud Server, Managed Server und skalierbarem Cloud Hosting für professionelle IT-Infrastrukturen

Install and Use Gradle on Ubuntu 24.04

Tutorial, Ubuntu

Linux file permissions with this comprehensive guide. Understand how to utilize chmod and chown commands to assign appropriate access rights, and gain insights into special permission bits like SUID, SGID, and the sticky bit to enhance your system’s security framework.