Install and Set Up Nagios on Debian 12

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.

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:

Step 2: Install Required Dependencies

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

$ 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:

Create a temporary directory for handling Nagios files:

Navigate into the newly created directory:

Step 4: Download the Nagios Core Source

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

$ 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:

$ tar xzf nagios-4.5.8.tar.gz

Step 6: Confirm the Extraction

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

Expected output:

nagios-4.5.8 nagios-4.5.8.tar.gz

Step 7: Access the Source Directory

Move into the Nagios source folder:

Step 8: Configure the Build

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

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

Step 9: Compile Nagios

Initiate the compilation of the Nagios core source:


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:

Expected output:

/home/linuxuser/nagios-4.5.8

Step 11: Set Up Nagios User and Permissions

Create the Nagios-specific user and group:

$ sudo make install-groups-users

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

$ sudo usermod -a -G nagios www-data

Step 12: Install Nagios Components

Run the core installation command:

Install the Nagios system daemon:

$ sudo make install-daemoninit

Enable the command module to allow external Nagios command execution:

$ sudo make install-commandmode

Apply the default Nagios configuration files:

$ sudo make install-config

Configure the Nagios web interface:

$ sudo make install-webconf

Step 13: Enable Apache Modules

Enable Apache’s URL rewrite module:

Activate CGI support in Apache:

Step 14: Set Up Web Access Authentication

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

$ 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:

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

$ 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:

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

Check the contents of your directory:

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:

$ cd nagios-plugins-2.4.12

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

Compile the plugins:

Install the compiled plugins:

Step 16: Verify Nagios Setup

Check the configuration file for syntax issues and warnings:

$ 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:

$ sudo systemctl start nagios

Enable Nagios to start on system boot:

$ sudo systemctl enable nagios

Restart Apache so changes take effect:


$ 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:

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

$ sudo ufw allow ssh && sudo ufw enable

Allow access to HTTP traffic:

Reload UFW to apply the changes:

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:

Install the NRPE server and required plugins:

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

Open the NRPE configuration file:

$ sudo nano /etc/nagios/nrpe.cfg

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

allowed_hosts=127.0.0.1,nagios_server_ip

Then add a custom disk monitoring command:

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:

$ sudo systemctl enable nagios-nrpe-server

Restart the service to apply your configuration changes:

$ sudo systemctl restart nagios-nrpe-server

Step 20: Register the Remote Host on the Nagios Server

Create a folder to hold remote host definitions:

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

Make a configuration file for the remote system:

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

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

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:

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

Append this line to include the remote configuration:

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:

$ 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:

$ 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.

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.