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.
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:
$ sudo apt updateStep 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-utilsThis command installs Apache, PHP, and various development libraries Nagios needs to operate.
Step 3: Prepare the Workspace
Move to your user’s home directory:
$ cdCreate a temporary directory for handling Nagios files:
$ mkdir nagios-tempNavigate into the newly created directory:
$ cd nagios-tempStep 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.gzStep 5: Extract the Archive
Unpack the contents of the archive file:
$ tar xzf nagios-4.5.8.tar.gzStep 6: Confirm the Extraction
Check that the extraction worked correctly and a new folder appeared:
$ lsExpected output:
nagios-4.5.8 nagios-4.5.8.tar.gz
Step 7: Access the Source Directory
Move into the Nagios source folder:
$ cd nagios-4.5.8Step 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-enabledStep 9: Compile Nagios
Initiate the compilation of the Nagios core source:
$ sudo make allInstall 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:
$ pwdExpected 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-usersGrant Apache (www-data user) permission to access Nagios files:
$ sudo usermod -a -G nagios www-dataStep 12: Install Nagios Components
Run the core installation command:
$ sudo make installInstall the Nagios system daemon:
$ sudo make install-daemoninitEnable the command module to allow external Nagios command execution:
$ sudo make install-commandmodeApply the default Nagios configuration files:
$ sudo make install-configConfigure the Nagios web interface:
$ sudo make install-webconfStep 13: Enable Apache Modules
Enable Apache's URL rewrite module:
$ sudo a2enmod rewriteActivate CGI support in Apache:
$ sudo a2enmod cgiStep 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 nagiosadminInstall 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:
$ cdDownload 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.gzUnpack the plugin archive:
$ tar xzf nagios-plugins-2.4.12.tar.gzCheck the contents of your directory:
$ lsExpected 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.12Run the configuration script to detect server settings and required paths:
$ sudo ./configureCompile the plugins:
$ sudo makeInstall the compiled plugins:
$ sudo make installStep 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.cfgSample 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 nagiosEnable Nagios to start on system boot:
$ sudo systemctl enable nagiosRestart Apache so changes take effect:
$ sudo systemctl restart apache2Access 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:
$ sudo ufw statusIf the firewall is inactive, enable it and allow SSH access:
$ sudo ufw allow ssh && sudo ufw enableAllow access to HTTP traffic:
$ sudo ufw allow 80/tcpReload UFW to apply the changes:
$ sudo ufw reloadTo 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:
$ ssh user@remotehostInstall the NRPE server and required plugins:
$ sudo apt install -y nagios-nrpe-server nagios-pluginsOpen the NRPE configuration file:
$ sudo nano /etc/nagios/nrpe.cfgInclude the Nagios server’s IP address in the allowed_hosts line:
allowed_hosts=127.0.0.1,nagios_server_ipThen 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-serverRestart the service to apply your configuration changes:
$ sudo systemctl restart nagios-nrpe-serverStep 20: Register the Remote Host on the Nagios Server
Create a folder to hold remote host definitions:
$ sudo mkdir -p /usr/local/nagios/etc/serversMake a configuration file for the remote system:
$ sudo nano /usr/local/nagios/etc/servers/remote-host.cfgAdd 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.cfgAppend this line to include the remote configuration:
cfg_file=/usr/local/nagios/etc/servers/remote-host.cfgStep 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.cfgSample 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 nagiosVisit 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.
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.