Sitemap
Muhammad Rafay

Muhammad Rafay

DevOps Engineer

How to install Nagios on Ubuntu 22.04

6 min readSep 10, 2023

--

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

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

sudo apt update
Press enter or click to view image in full size

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
Press enter or click to view image in full size
Press enter or click to view image in full size

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
Press enter or click to view image in full size

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

 ls
Press enter or click to view image in full size

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
Press enter or click to view image in full size

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
Press enter or click to view image in full size
Press enter or click to view image in full size

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

sudo make all
Press enter or click to view image in full size
Press enter or click to view image in full size

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
Press enter or click to view image in full size
Press enter or click to view image in full size

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

sudo make install-commandmode
Press enter or click to view image in full size

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

sudo make install-config
Press enter or click to view image in full size

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

Get Muhammad Rafay’s stories in your inbox

Join Medium for free to get updates from this writer.

Firstly, install the web interface of Nagios as follows:

sudo make install-webconf
Press enter or click to view image in full size

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

sudo a2enmod rewrite

sudo a2enmod cgi

Set the UFW to allow upcoming connections from apache.

 sudo ufw allow apache
Press enter or click to view image in full size

Enable and reload the firewall as follows.

 sudo ufw enable
sudo ufw reload
Press enter or click to view image in full size

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

sudo systemctl restart apache2
Press enter or click to view image in full size

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
Press enter or click to view image in full size

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
Press enter or click to view image in full size

Extract the tar.gz file.

sudo tar -zxvf nagios-plugins-2.3.3.tar.gz
Press enter or click to view image in full size
Press enter or click to view image in full size

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
Press enter or click to view image in full size
Press enter or click to view image in full size

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

sudo make install
Press enter or click to view image in full size
Press enter or click to view image in full size

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
Press enter or click to view image in full size

The output prints the installed version which is 4.4.6.

Press enter or click to view image in full size
Press enter or click to view image in full size

--

--