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.
Matching infrastructure at centron
Ubuntu servers without your own hardware: ccloud³ VMs with full root access from €3.12 per month, billed by the hour and ready in seconds. Rent a cloud server →
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-devPrepare the Project Directory
Navigate to your home directory:
$ cdCreate a directory to store Nagios Core files:
$ mkdir nagios-coreMove into the newly created directory:
$ cd nagios-coreDownload 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.gzExtract the downloaded archive:
$ tar xzf nagioscore.tar.gzVerify the extracted files are in the directory:
$ lsYou 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-enabledBuild the Nagios Core software:
$ sudo make allCreate a dedicated Nagios group and user for the software:
$ sudo make install-groups-usersFinally, add the www-data user to the Nagios group to allow Apache access to Nagios resources:
$ sudo usermod -a -G nagios www-dataInstall 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:
$ sudo make installSet up configuration scripts and start the Nagios daemon:
$ sudo make install-daemoninitInstall the component that enables external commands through the web interface:
$ sudo make install-commandmodeInstall the Nagios configuration files:
$ sudo make install-configAdd the required Apache configuration files:
$ sudo make install-webconfActivate the Apache rewrite module:
$ sudo a2enmod rewriteActivate the Apache CGI module:
$ sudo a2enmod cgiCreate a new basic auth user nagiosadmin and set a secure password when prompted:
$ sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadminRestart Apache to apply the changes:
$ sudo systemctl restart apache2Install 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 gettextMove to your home directory:
$ cdDownload 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.gzUnpack the downloaded archive:
$ tar zxf nagios-plugins.tar.gzChange to the extracted directory:
$ cd nagios-plugins-release-2.4.12Execute the setup script:
$ sudo ./tools/setupConfigure the build process:
$ sudo ./configureCompile the plugin binaries:
$ sudo makeInstall the compiled plugin binaries:
$ sudo make installValidate and Start Nagios
Check the Nagios configuration for syntax errors:
$ sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfgExpected 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 nagiosStart the Nagios service:
$ sudo systemctl start nagiosAccess 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:
$ sudo ufw statusIf it is not active, enable UFW and permit SSH access to avoid being locked out:
$ sudo ufw allow ssh && sudo ufw enableAllow HTTP traffic on port 80 to serve the web interface:
$ sudo ufw allow 80/tcpApply the changes by reloading UFW:
$ sudo ufw reloadOpen 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 -yEnable and start the NRPE service:
$ sudo systemctl enable --now nagios-nrpe-serverAllow Nagios Server Access in NRPE Configuration
Open the NRPE configuration file to define allowed hosts and permitted plugins:
$ sudo nano /etc/nagios/nrpe.cfgUpdate the allowed_hosts line to include your Nagios server's public IP address:
allowed_hosts=127.0.0.1,::1,nagios_server_IPSave and exit the file, then restart the NRPE service to apply changes:
$ sudo systemctl restart nagios-nrpe-serverWith 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.cfgInsert 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.cfgAdd the following line at the bottom of the file to load all configurations from the servers directory:
cfg_dir=/usr/local/nagios/etc/serversApply and Verify Configuration Changes
Restart the Nagios service to load the new host configuration:
$ sudo systemctl restart nagiosCheck the Nagios configuration for errors before finalizing the setup:
$ sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfgExpected 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 nagiosVerify 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
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.