
A Step-by-Step Guide to Installing Nagios Core from Source on Ubuntu
Proactive network monitoring is the cornerstone of a stable and reliable IT infrastructure. Instead of reacting to failures after they occur, a robust monitoring system allows you to identify and address potential issues before they impact your users. Nagios Core is a powerful, open-source industry standard for monitoring systems, applications, and services, providing you with the alertness and insight needed to maintain high availability.
Installing Nagios Core from the source code gives you maximum control over the configuration and a deeper understanding of its components. This guide provides a comprehensive walkthrough for compiling and setting up Nagios Core and its essential plugins on an Ubuntu server.
Prerequisites
Before we begin, ensure you have the following ready:
- An Ubuntu server (these instructions are tailored for 18.04 but are highly adaptable for newer versions like 20.04 and 22.04).
- A user with
sudoor root privileges. - A basic LAMP (Linux, Apache, MySQL, PHP) stack installed. At a minimum, you will need Apache and PHP.
Step 1: Install Required Dependencies
First, we need to install the development tools and libraries required to compile the source code. These packages include the C compiler, development libraries for web server integration, and graphics libraries for rendering maps and reports.
Open your terminal and run the following command to install all necessary prerequisites:
sudo apt update
sudo apt install -y build-essential apache2 php openssl libssl-dev libgd-dev libapache2-mod-php unzip
Step 2: Create a Dedicated Nagios User and Group
For security purposes, Nagios should run under its own user and group. This isolates its processes and limits its permissions on the system. We will also create a group for external commands and add both the Nagios user and the Apache user to it.
sudo useradd nagios
sudo groupadd nagcmd
sudo usermod -a -G nagcmd nagios
sudo usermod -a -G nagcmd www-data
Step 3: Download and Compile Nagios Core
Now it’s time to download the Nagios Core source code. You can find the latest stable version on the official Nagios Core downloads page.
Navigate to your home directory and download the source code using
wget.cd ~ wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.14.tar.gzExtract the downloaded archive:
tar xzf nagios-4.4.14.tar.gz cd nagios-4.4.14Configure the build process. The
--with-httpd-confflag tells the script where to place the Apache web server configuration file../configure --with-httpd-conf=/etc/apache2/sites-enabledCompile and install the software. The following commands will compile the main program and CGIs, install the binaries, set up the init scripts, configure command-mode permissions, and install sample configuration files.
make all sudo make install sudo make install-init sudo make install-commandmode sudo make install-config
Step 4: Configure the Apache Web Interface
To access the Nagios web interface, you need to configure Apache. The installation script has already created a configuration file, but we need to enable it along with some required Apache modules.
Install the web configuration file and enable the necessary Apache modules.
sudo make install-webconf sudo a2enmod rewrite sudo a2enmod cgiCreate a web administrator user. You will use this account,
nagiosadmin, to log into the Nagios web interface. Be sure to use a strong, unique password for this account.sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadminRestart Apache to apply all the changes.
sudo systemctl restart apache2
Step 5: Download and Compile Nagios Plugins
Nagios Core is the engine, but the plugins are what perform the actual checks on hosts and services. Without them, Nagios can’t monitor anything.
Navigate back to your home directory and download the latest Nagios Plugins source code.
cd ~ wget https://nagios-plugins.org/download/nagios-plugins-2.4.6.tar.gzExtract the archive, then compile and install the plugins.
tar xzf nagios-plugins-2.4.6.tar.gz cd nagios-plugins-2.4.6 ./configure make sudo make install
Step 6: Final Configuration and Service Start
The final step is to configure your administrative email and verify that all configuration files are correct before starting the Nagios service.
Set up your notification email. Open the contacts configuration file and replace the default email address with your own.
sudo nano /usr/local/nagios/etc/objects/contacts.cfgFind the
emaildirective for thenagiosadmincontact definition and update it:define contact{ contact_name nagiosadmin use generic-contact alias Nagios Admin email [email protected] ; <<-- UPDATE THIS LINE }Verify the Nagios configuration files. This command will check for any syntax errors before you attempt to start the service.
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfgIf there are no errors, you’re ready to go.
Start the Nagios service and enable it to launch automatically on boot.
sudo systemctl start nagios sudo systemctl enable nagios
Accessing the Nagios Web Interface
You have successfully installed and configured Nagios Core! To access the web interface, open your browser and navigate to http://YOUR_SERVER_IP/nagios.
You will be prompted for a username and password. Enter nagiosadmin and the strong password you created in Step 4. You should now see the Nagios dashboard, ready for you to begin adding hosts and services to monitor.
Essential Security Recommendations
- Configure a Firewall: Use
ufwor another firewall to restrict access to your server. At a minimum, allow traffic on port 80 (HTTP) or 443 (HTTPS).
bash
sudo ufw allow Apache
sudo ufw enable
- Enable HTTPS: The login credentials for Nagios are sent in clear text over HTTP. It is highly recommended to secure your Nagios installation with an SSL/TLS certificate from a service like Let’s Encrypt to encrypt traffic.
- Keep Software Updated: Regularly check for and install updates to Nagios Core, the plugins, and your underlying server operating system to protect against security vulnerabilities.
Source: https://kifarunix.com/how-to-install-and-configure-nagios-core-from-the-source-ubuntu-18-04/


