How to Install Nagios in Ubuntu 22.04/20.04 – Part 1

Essential networking devices, network services, and applications need constant monitoring to lessen the troubleshooting complexities that many server administrators have to endure or overcome.

One reputable tool for managing such networking footprints is Nagios. Its active monitoring functionality can detect network devices, services, and application faults on a server it is tasked to monitor. Once such faults are detected, the administrative user is notified of the underlying suspicious activity on the network.

The machine that hosts Nagios should embrace a Server/Agent architecture for it to comfortably communicate with remote hosts that need constant monitoring.

This Nagios network monitoring tool makes use of agents like Nagios Remote Plugin Executor for swift communication with remote hosts. Moreover, Nagios generates final reports from visually represented user interface logs.

Requirements

Before this article walks us through the installation and configuration of Nagios on Ubuntu 22.04 and Ubuntu 20.04, we must obey the following prerequisites:

  • You are under an Ubuntu 22.04/20.04 server environment that is fully up-to-date.
  • You have Sudoer user privileges on the Ubuntu server environment.

Installing Nagios Core in Ubuntu Server

First, update your Ubuntu system and then retrieve several packages that are valid Nagios dependencies.

$ sudo apt update
$ sudo apt install wget unzip curl openssl build-essential libgd-dev libssl-dev libapache2-mod-php php-gd php apache2 -y

Since we have also installed the Apache web server as one of the needed dependencies, make sure it is running.

$ sudo systemctl status apache2
Check Apache Status in Ubuntu
Check Apache Status in Ubuntu

To install the latest Nagios Core release, first, download the Nagios Core release or use the following download command.

$ wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.6.tar.gz

We now need to extract the Nagios Core compressed file.

$ sudo tar -zxvf nagios-4.4.6.tar.gz

We can now navigate to the main Nagios directory and configure the script associated with Nagios Core.

$ cd nagios-4.4.6
$ sudo ./configure
Configure Nagios in Ubuntu
Configure Nagios in Ubuntu
Nagios Configuration Summary
Nagios Configuration Summary

As suggested on the above screen capture, we will proceed and compile the main program.

$ sudo make all
Compile Nagios in Ubuntu
Compile Nagios in Ubuntu

Configure Nagios group and user and link Nagios group with the www-data directory.

$ sudo make install-groups-users
$ sudo usermod -a -G nagios www-data

Now proceed to install Nagios.

$ sudo make install
Install Nagios in Ubuntu
Install Nagios in Ubuntu

The installation configuration scripts need initialization, execute the following command:

$ sudo make install-init
Initialize Nagios in Ubuntu
Initialize Nagios in Ubuntu

The configs directory needs certain permissions installed and configured.

$ sudo make install-commandmode

We will need Nagios sample config files for reference.

$ sudo make install-config
Install Nagios Config Files in Ubuntu
Install Nagios Config Files in Ubuntu

Install Apache (webserver) files and enable rewrite and CGI modules.

$ sudo make install-webconf
$ sudo a2enmod rewrite
$ sudo a2enmod cgi

Finally, restart the Apache webserver.

$ sudo systemctl restart apache2

Next, create a Nagios admin user with your preferred password.

$ sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users admin
Create Nagios Admin in Ubuntu
Create Nagios Admin in Ubuntu

Installing Nagios Plugins in Ubuntu

To install the latest Nagios Plugins release, first, download the Nagios Plugins release or use the following download command.

$ wget https://nagios-plugins.org/download/nagios-plugins-2.3.3.tar.gz

Extract the downloaded Nagios Plugins files and configure them:

$ sudo tar -zxvf nagios-plugins-2.3.3.tar.gz
$ cd nagios-plugins-2.3.3/
$ sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios
Configure Nagios Plugins in Ubuntu
Configure Nagios Plugins in Ubuntu

Compile the Nagios plugins:

$ sudo make
Compile Nagios Plugins in Ubuntu
Compile Nagios Plugins in Ubuntu

Install the Nagios plugins:

$ sudo make install
Install Nagios Plugins in Ubuntu
Install Nagios Plugins in Ubuntu

Verifying Nagios Configuration in Ubuntu

Nagios Core configuration can be verified with the following command:

$ sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Verify Nagios in Ubuntu
Verify Nagios in Ubuntu

To start the Nagios service, run the command:

$ sudo systemctl start nagios

You might also need to enable Nagios for it to keep on running even after a system reboot.

$ sudo systemctl enable nagios

Finally, access Nagios from your web server at the following URL.

http://server-ip/nagios
Nagios Login in Ubuntu
Nagios Login in Ubuntu

I will use the admin user I created with its associated password to gain entry to Nagios’ dashboard.

Nagios Dashboard in Ubuntu
Nagios Dashboard in Ubuntu

In the next article piece, we will handle how to add remote Linux hosts to the Nagios server so that you can view/monitor their devices, applications, and services performances.

Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.