Ubuntu

How to install Nagios on Ubuntu 22.04

Nagios is a powerful IT infrastructure monitoring tool intended to provide a smooth execution of processes in an organization. Nagios monitors the ongoing activities of the host and it issues an alert if something bad happens.

The Nagios support is available for Linux and Microsoft-based operating systems. Ubuntu is a widely used distribution of Linux which is equipped with the latest features and an interactive interface. Ubuntu 22.04 is the latest LTS released recently.

Keeping in view the importance of Nagios, this post provides a step-by-step procedure to install Nagios on Ubuntu 22.04.

How to install Nagios on Ubuntu 22.04

This section enlists the recommended steps to install Nagios on Ubuntu 22.04.

Step 1: Firstly, update the Ubuntu system’s packages via the following command.

$ sudo apt update

Step 2: There are a few dependencies that are required to carry out the installation of Nagios. The below-stated command will help in this regard.

Note: It would install the apache, php, openssl, and relevant dependencies. You can install them separately, but it is recommended to get them with a single command.

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

Text Description automatically generated
Text Description automatically generated

Step 3: We are performing a manual installation. To do so, download the tar.gz file via the following command.

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

Text Description automatically generated

Use the “ls” command to ensure the availability of the newly downloaded tar.gz file.

$ ls

Text Description automatically generated

The file is available as “nagios-4.4.6.tar.gz“. We executed the following command to extract it.

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

Text Description automatically generated
Text Description automatically generated

Now change the working directory to nagios-4.4.6 to start building the installation files.

$ cd nagios-4.4.6

Step 4: Make sure, you are inside the directory where the Nagios is extracted. Execute the following command to run the ./configure script to proceed to compilation process.

$ sudo ./configure

Text Description automatically generated
Text Description automatically generated

Now, use the make utility to process the source code files as we did here.

$ sudo make all

Text Description automatically generated
Text Description automatically generated

To use Nagios, you must create a Nagios user and group via the following command.

$ sudo make install-groups-users

After that, add the apache user to the nagios group.

$ sudo usermod -a -G nagios www-data

Step 5: Its time to install Nagios with the help of the following command.

$ sudo make install

Text Description automatically generated
Text Description automatically generated

Meanwhile, install the external command file by issuing the following command.

$ sudo make install-commandmode

A screenshot of a computer Description automatically generated with medium confidence

After then, install the following configurations files by issuing the follwoing command. These configurations are required by Nagios for startup.

$ sudo make install-config

Text Description automatically generated

Step 6: You need to install the apache configurations files.

Firstly, install the web interface of Nagios as follows:

$ sudo make install-webconf

Text Description automatically generated

Now, make use of the a2enmod script to enable the rewrite and cgi modules of apache2.

$ sudo a2enmod rewrite

$ sudo a2enmod cgi

Text Description automatically generated
Text Description automatically generated

Set the UFW to allow upcoming connections from apache.

$ sudo ufw allow apache

A picture containing graphical user interface Description automatically generated

Enable and reload the firewall as follows.

$ sudo ufw enable

$ sudo ufw reload

Graphical user interface Description automatically generated

After doing the changes, restart the apache service via the following command.

$ sudo systemctl restart apache2

Step 7: Create a new Nagios user as we did here. The below-mentioned command creates a user named “linuxhint” and the output will ask you to set a password for “linuxhint” user.

$ sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users linuxhint

The output shows that the password for the “linuxhint” user has been set as well.

Step 8: It is recommended to install the Nagios plugins as you may not be able to get a smooth web usage. We have to install it manually from the Nagios website.

Firstly, download the tar.gz file with the help of the following command.

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

Text Description automatically generated

Extract the tar.gz file.

$ sudo tar -zxvf nagios-plugins-2.3.3.tar.gz

Text Description automatically generated
Text Description automatically generated

Change the working directory to where the plugins are extracted.

$ cd nagios-plugins-2.3.3

Execute the following command to run the configure script for Nagios user and group.

$ sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios

Text Description automatically generated
Text Description automatically generated

You can now use the make utility to install nagios plugins by providing the following command.

$ sudo make install

Text Description automatically generated
Text Description automatically generated

Finally, the Nagios installed and configured on Ubuntu 22.04.

How to use Nagios on Ubuntu 22.04

In the previous section, you would have learned the installation of the Nagios on Ubuntu 22.04. Here, we have presented the procedure to use Nagios right after the installation phase.

Let’s start with checking the version of installed Nagios as follows.

$ sudo /usr/local/nagios/bin/nagios -v

Text Description automatically generated

The output prints the installed version which is 4.4.6.

Conclusion

Nagios is a monitoring tool to enhance the overall performance of the system/network. It can be used to get the system-related information as well. The purpose of the Nagios is to track any bottlenecks or runtime errors in the system. This guide provides an installation guide of Nagios on Ubuntu 22.04. The installation is provided in a step-by-step procedural manner. We have provided the necessary configuration steps of Nagios on Ubuntu 22.04 as well.

About the author

Adnan Shabbir