
How to Install Nagios on Ubuntu 24.04: A Step-by-Step Guide
In the world of IT infrastructure, robust monitoring is not a luxury—it’s a necessity. Nagios Core stands as a pillar of open-source monitoring, offering unparalleled flexibility for keeping a watchful eye on your servers, applications, and network services. This comprehensive guide will walk you through the entire process of installing and configuring Nagios Core on a fresh Ubuntu 24.04 server.
By following these steps, you’ll build a powerful monitoring foundation, enabling you to detect and resolve issues before they impact your users.
Prerequisites
Before we begin, ensure you have the following:
- An installed instance of Ubuntu 24.04 Noble Numbat.
- Access to a user account with sudo or root privileges.
Step 1: Update Your System and Install Dependencies
First, it’s crucial to start with an up-to-date system. Open your terminal and run the following commands to refresh your package lists and install all the necessary build tools and web server components.
sudo apt update
sudo apt upgrade -y
sudo apt install -y build-essential apache2 libapache2-mod-php php-gd libgd-dev unzip
This command installs the Apache web server, PHP, and the essential libraries Nagios needs to compile and run its web interface.
Step 2: Create a Dedicated Nagios User and Group
For security best practices, Nagios should run under its own dedicated user and group. This isolates the monitoring service from other processes on your system.
Create the nagios
user and group:
sudo useradd nagios
sudo groupadd nagioscmd
Next, add both the nagios
user and the Apache user (www-data
) to the nagioscmd
group. This allows the web server to interact with Nagios’s external command file.
sudo usermod -a -G nagioscmd nagios
sudo usermod -a -G nagioscmd www-data
Step 3: Download and Compile Nagios Core
Now it’s time to get the main Nagios Core application. We will download the latest stable source code, extract it, and compile it.
Navigate to the
/tmp
directory to keep our download temporary.cd /tmp
Download the latest version of Nagios Core. As of writing, 4.5.1 is the latest stable release.
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.5.1.tar.gz
Extract the downloaded archive:
tar -zxvf nagios-4.5.1.tar.gz
Change into the newly created directory and begin the compilation process. The
configure
script checks your system for all required dependencies.cd nagios-4.5.1 sudo ./configure --with-httpd-conf=/etc/apache2/sites-enabled
Compile and install Nagios and its related components. The
make all
command compiles the main program and CGIs, while the subsequent commands install them, set up initialization scripts, and install the command-mode files.
bash
sudo make all
sudo make install
sudo make install-init
sudo make install-commandmode
sudo make install-config
Finally, install the Apache configuration file for Nagios:
sudo make install-webconf
Step 4: Install the Nagios Plugins
Nagios Core is the engine, but Nagios Plugins are the tools that actually perform the checks. Without plugins, Nagios can’t monitor anything.
Return to your
/tmp
directory and download the latest plugins package.cd /tmp wget https://nagios-plugins.org/download/nagios-plugins-2.4.8.tar.gz
Extract the archive and change into the new directory:
tar -zxvf nagios-plugins-2.4.8.tar.gz cd nagios-plugins-2.4.8
Compile and install the plugins:
bash
sudo ./configure
sudo make
sudo make install
Step 5: Configure the Apache Web Server
To access the Nagios web interface, we need to create an administrative user and enable the necessary Apache modules.
Create a web user account. You will be prompted to create a password for the
nagiosadmin
user. This is the username and password you will use to log in to the Nagios web UI. Choose a strong, secure password.sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Enable the required Apache modules for CGI and URL rewriting, then restart the web server to apply all changes.
bash
sudo a2enmod rewrite
sudo a2enmod cgi
sudo systemctl restart apache2
Step 6: Start and Verify the Nagios Service
Before starting the Nagios service for the first time, it’s a good idea to verify your configuration files for any errors.
Run the verification command:
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
If everything is correct, you will see a message indicating zero warnings and zero errors.
Now, start the Nagios service and enable it to launch automatically on boot:
bash
sudo systemctl start nagios
sudo systemctl enable nagios
Step 7: Access the Nagios Web Interface
Your Nagios monitoring server is now running! You can access it through your web browser.
Find your server’s IP address:
ip addr show
Open your browser and navigate to
http://YOUR_SERVER_IP/nagios
.You will be prompted for a username and password. Enter
nagiosadmin
for the username and the secure password you created in Step 5.
You should now see the Nagios Core dashboard, which by default is monitoring the localhost
(the Nagios server itself).
Important Security Recommendations
Configure a Firewall: Use UFW (Uncomplicated Firewall) to restrict access to your server. At a minimum, you should only allow access on ports for SSH (22), HTTP (80), and HTTPS (443).
sudo ufw allow ssh sudo ufw allow http sudo ufw allow https sudo ufw enable
Secure with SSL/TLS: The default installation uses plain HTTP, which sends your
nagiosadmin
password in clear text. For any production environment, it is highly recommended to configure Apache with an SSL certificate (e.g., from Let’s Encrypt) to enable secure HTTPS access.
Conclusion
Congratulations! You have successfully deployed a powerful Nagios Core monitoring server on Ubuntu 24.04. This is the first step toward building a comprehensive monitoring solution. Your next steps will be to explore the configuration files located in /usr/local/nagios/etc/objects/
to start adding your own hosts and services to monitor. With this setup, you are well-equipped to maintain a healthy and reliable IT infrastructure.
Source: https://kifarunix.com/how-to-install-nagios-server-on-ubuntu-24-04/