Tutorials  /  Linux Basics

Nagios Installation and Remote Monitoring on Debian 12

Ccentron Redaktion · April 2025 ·10 min read ·Linux Basics, Tutorial

Installing Nagios on Debian 12 gives you access to a powerful open-source tool for tracking network hosts, services, and application performance. Nagios uses a server-agent framework, where the NRPE (Nagios Remote Plugin Executor) agent facilitates communication with remote systems to observe devices, resource usage, and software status. It executes regular checks on configured targets, returns their statuses, and delivers visual reports via a web-based interface.

This guide outlines the steps to install Nagios on a Debian 12 machine and set it up to monitor a remote system.

System Requirements

Before starting, ensure you have:

  • Two Debian 12 systems—one for the Nagios server and another as the monitored remote machine.
VM

Matching infrastructure at centron

No hardware needed to follow along: ccloud³ VMs with full root access start at €3.12 per month, billed by the hour and ready in seconds. Rent a cloud server →

Build and Install the Nagios Core

Since Nagios is not included in Debian 12’s standard repositories, follow these instructions to manually build and install it from source.

Step 1: Refresh Package Lists

Begin by updating your system’s package index:

Console
$ sudo apt update

Step 2: Install Required Dependencies

Install all the packages Nagios depends on to run and compile properly:

Console
$ sudo apt install -y apache2 php libapache2-mod-php php-gd php-mysql build-essential libgd-dev unzip libssl-dev wget curl autoconf gcc libc6 make apache2-utils

This command installs Apache, PHP, and various development libraries Nagios needs to operate.

Step 3: Prepare the Workspace

Move to your user’s home directory:

Console
$ cd

Create a temporary directory for handling Nagios files:

Console
$ mkdir nagios-temp

Navigate into the newly created directory:

Console
$ cd nagios-temp

Step 4: Download the Nagios Core Source

Download the latest Nagios Core release—version 4.5.8 in this case—using wget:

Console
$ wget https://github.com/NagiosEnterprises/nagioscore/releases/download/nagios-4.5.8/nagios-4.5.8.tar.gz

Step 5: Extract the Archive

Unpack the contents of the archive file:

Console
$ tar xzf nagios-4.5.8.tar.gz

Step 6: Confirm the Extraction

Check that the extraction worked correctly and a new folder appeared:

Console
$ ls

Expected output:

nagios-4.5.8 nagios-4.5.8.tar.gz

Step 7: Access the Source Directory

Move into the Nagios source folder:

Console
$ cd nagios-4.5.8

Step 8: Configure the Build

Execute the configuration script to set up a virtual host for Nagios within Apache’s sites-enabled directory:

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

Step 9: Compile Nagios

Initiate the compilation of the Nagios core source:

Console
$ sudo make all

Install Nagios on Debian 12

Proceed with the following steps to install Nagios and configure necessary Apache modules that allow access to the web interface.

Step 10: Confirm Working Directory

Print your current directory to make sure you're inside the Nagios source folder:

Console
$ pwd

Expected output:

/home/linuxuser/nagios-4.5.8

Step 11: Set Up Nagios User and Permissions

Create the Nagios-specific user and group:

Console
$ sudo make install-groups-users

Grant Apache (www-data user) permission to access Nagios files:

Console
$ sudo usermod -a -G nagios www-data

Step 12: Install Nagios Components

Run the core installation command:

Console
$ sudo make install

Install the Nagios system daemon:

Console
$ sudo make install-daemoninit

Enable the command module to allow external Nagios command execution:

Console
$ sudo make install-commandmode

Apply the default Nagios configuration files:

Console
$ sudo make install-config

Configure the Nagios web interface:

Console
$ sudo make install-webconf

Step 13: Enable Apache Modules

Enable Apache's URL rewrite module:

Console
$ sudo a2enmod rewrite

Activate CGI support in Apache:

Console
$ sudo a2enmod cgi

Step 14: Set Up Web Access Authentication

Create a user account (nagiosadmin) for accessing the web dashboard. Choose a secure password when prompted:

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

Install Nagios Plugins

Nagios plugins include a variety of monitoring scripts that continuously evaluate system performance and relay metrics to the Nagios Core engine. These plugins handle monitoring for resources like CPU load, disk I/O, and network connectivity.

Step 15: Download and Compile Plugins

Move back to your home directory:

Console
$ cd

Download the latest version of Nagios Plugins—version 2.4.12 in this example:

Console
$ wget https://github.com/nagios-plugins/nagios-plugins/releases/download/release-2.4.12/nagios-plugins-2.4.12.tar.gz

Unpack the plugin archive:

Console
$ tar xzf nagios-plugins-2.4.12.tar.gz

Check the contents of your directory:

Console
$ ls

Expected output:

nagios-4.5.8 nagios-4.5.8.tar.gz nagios-plugins-2.4.12 nagios-plugins-2.4.12.tar.gz

Enter the plugin directory:

Console
$ cd nagios-plugins-2.4.12

Run the configuration script to detect server settings and required paths:

Console
$ sudo ./configure

Compile the plugins:

Console
$ sudo make

Install the compiled plugins:

Console
$ sudo make install

Step 16: Verify Nagios Setup

Check the configuration file for syntax issues and warnings:

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

Sample output:

Nagios Core 4.5.8
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 2024-11-19
License: GPL

....................
Total Warnings: 0
Total Errors:   0

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

Step 17: Launch and Enable Nagios

Start the Nagios service manually:

Console
$ sudo systemctl start nagios

Enable Nagios to start on system boot:

Console
$ sudo systemctl enable nagios

Restart Apache so changes take effect:

Console
$ sudo systemctl restart apache2

Access the Nagios Web Dashboard

By default, Nagios listens for incoming connections on HTTP port 80. Its web dashboard presents real-time statistics and alerts for network services, hosts, and system performance. Use the following steps to allow traffic through port 80 and access the monitoring interface.

Step 18: Check Firewall Status

Confirm if the firewall (UFW) is active:

Console
$ sudo ufw status

If the firewall is inactive, enable it and allow SSH access:

Console
$ sudo ufw allow ssh && sudo ufw enable

Allow access to HTTP traffic:

Console
$ sudo ufw allow 80/tcp

Reload UFW to apply the changes:

Console
$ sudo ufw reload

To access the Nagios web dashboard, go to the following URL in your browser:

http://SERVER-IP/nagios

Use the login credentials created earlier:

  • User: nagiosadmin
  • Password: your previously set password

After logging in, go to the “Hosts” section in the sidebar to view all registered hosts.

Set Up Remote Host Monitoring

Nagios leverages the NRPE agent to gather performance data from remote systems. This agent executes defined checks like disk usage, CPU load, and memory usage. Follow these steps to install and configure NRPE on a remote Debian 12 machine and enable monitoring from the main Nagios server.

Step 19: Prepare the Remote System

Connect to the remote server using SSH:

Console
$ ssh user@remotehost

Install the NRPE server and required plugins:

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

Open the NRPE configuration file:

Console
$ sudo nano /etc/nagios/nrpe.cfg

Include the Nagios server’s IP address in the allowed_hosts line:

Code
allowed_hosts=127.0.0.1,nagios_server_ip

Then add a custom disk monitoring command:

Code
command[check_disk]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /

This command checks root partition usage and defines warning and critical thresholds.

Enable NRPE to run at startup:

Console
$ sudo systemctl enable nagios-nrpe-server

Restart the service to apply your configuration changes:

Console
$ sudo systemctl restart nagios-nrpe-server

Step 20: Register the Remote Host on the Nagios Server

Create a folder to hold remote host definitions:

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

Make a configuration file for the remote system:

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

Add the following content (adjust IP and host names as needed):

Code
define host {
    use                     linux-server
    host_name               centron
    alias                   Remote Server
    address                 
    max_check_attempts      5
    check_period            24x7
    notification_interval   30
    notification_period     24x7
}

Open the main Nagios configuration file:

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

Append this line to include the remote configuration:

Code
cfg_file=/usr/local/nagios/etc/servers/remote-host.cfg

Step 21: Validate and Reload Nagios

Run a configuration check to ensure there are no issues:

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

Sample output:

Checking for circular paths...
        Checked 2 hosts
        Checked 0 service dependencies
        Checked 0 host dependencies
        Checked 5 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...

Total Warnings: 0
Total Errors:   0

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

Restart the Nagios service to apply these updates:

Console
$ sudo systemctl restart nagios

Visit http://SERVER-IP/nagios in your browser again to see the new remote host listed under “Hosts”.

Conclusion

You've now successfully installed and configured Nagios on Debian 12 and set it up to monitor a remote host. Nagios keeps track of system health and performance metrics, delivering them in a centralized dashboard. For more detailed setups and customization, refer to the official Nagios documentation.

Jetzt 200 € Guthaben sichern

Testen Sie Ihr Setup auf ccloud³

Registrieren Sie sich in der ccloud³ und erhalten Sie 200 € Startguthaben für Ihr Projekt – z. B. für eine PostgreSQL-VM mit automatischen Backups.

centron Redaktion Technische Redaktion

Das Redaktionsteam von centron schreibt Anleitungen aus dem Betriebsalltag: getestet auf unserer eigenen Plattform, betrieben im Rechenzentrum in Hallstadt bei Bamberg.

Kategorie Linux Basics
Teilen
Noch offene Fragen?

Our team will help you with your specific setup - in German or English, by people who run the platform themselves.

War dieses Tutorial hilfreich?

Your answer is stored anonymously and helps us improve our tutorials.

Kommentare

No comments yet - be the first to ask a question about this tutorial.

Sign in to comment

Comments are open to centron customers. Sign in to your account to ask a question about this tutorial.

Weiterlesen

Das könnte Sie auch interessieren

Jetzt kostenlos anfangen

Melden Sie sich an und erhalten Sie in den ersten 60 Tagen ein Guthaben von 200 € bei centron.

Dieses Werbeangebot gilt nur für neue Konten. Angebot ausschließlich für Gewerbetreibende.

Jetzt loslegen Sales kontaktieren