How to Install Nagios on Ubuntu 24.04


Nagios is an open-source, powerful monitoring system that helps an organization keep a close eye on the IT infrastructure. It works as a watchdog that checks on servers, services, and applications to ensure everything is working smoothly. Nagios will quickly let the technical team know about the problem in the system so that they can fix it before it gets worse or affects the system.

If you are searching for a system that helps monitor your system health and applications, install Nagios on your newly installed Ubuntu 24.04 system.

Use this guide to learn:

How to Install Nagios on Ubuntu 24.04

You can install Nagios on Ubuntu 24.04 using the following steps:

Step 1: Install Dependencies for Nagios on Ubuntu

First, you must install some dependencies needed for Nagios installation on Ubuntu, you can do this using the following command:

sudo apt install make unzip apache2 autoconf gcc libc6 php libssl-dev -y

Step 2: Create a Dedicate User and Group for Nagios

Nagios requires a dedicated user and group to operate; to create a dedicated Nagios user on Ubuntu, you can use the following command:

sudo useradd nagios

To create a dedicated group for Nagios on Ubuntu, simply run the below-given command:

sudo groupadd nagcmd

Then add the nagios user to the group nagcmd using the following command:

sudo usermod -a -G nagcmd nagios

Step 3: Download and Compile Nagios on Ubuntu

Now, navigate to the Nagios official website, and click the Download button under Nagios Core:

Then provide your desired information and Submit it:

After that, select the desired Nagios version you want to download. Ensure downloading the latest version of Nagios Core for Ubuntu 24.04, which is 4.5.1 at the time of writing this blog.

You can directly download the Nagios Core version 4.5.1 on Ubuntu using the following command:

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

Now, extract the Nagios source file content on Ubuntu using the below-given command:

sudo tar xzf nagios-4.5.1.tar.gz

Note: Ensure to replace the tar.gz file name if you have downloaded a different version of Nagios on Ubuntu.

Then navigate to the Nagios source directory using the cd command with the name of the directory:

cd nagios-4.5.1

Note: You can use the ls command to find the name of the Nagios source directory.

Now, configure the Nagios installation files with the dedicated username and group through the following command:

./configure --with-nagios-group=nagios --with-command-group=nagcmd

After the configuration, simply run the below-given command to compile the files:

sudo make all

Step 4: Perform Nagios Binaries and Service Installation

Once you complete the Nagios compilation, you can install its binaries using the below-given command:

sudo make install

Also install init scripts for Nagios through the following command:

sudo make install-init

Besides that, install configuration files for Nagios through the provided command:

sudo make install-config

Additionally, you should also install some external command files for Nagios on Ubuntu using the following command:

sudo make install-commandmode

Step 5: Install Web Configuration Files for Web Interface

Now, to access the Nagios web interface, you must install the web configuration files on Ubuntu. These web configuration files set up the necessary configuration for Apache web server, thus, allowing you to access the web interface.

To install the Nagios web configuration files on Ubuntu, use the below-given command while ensuring you are in the Nagios source directory.

sudo make install-webconf

Also, set username and password for Nagios web interface using the following command:

sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

When you run the above command, it will ask you to set up a new password for the created user:

Once you enter the password, it will successfully add your desired username:

Further, you should also enable the cgi module and Apache2 on Ubuntu so that users will be able to interact with the Nagios web interface.

To enable cgi module on Ubuntu, you can run the following command:

sudo a2enmod rewrite cgi

Then restart the Apache service on Ubuntu through the below-given command:

sudo systemctl restart apache2

Step 6: Install Nagios Plugins on Ubuntu

To monitor the services on Ubuntu through Nagios, you are required to install Nagios plugins. For that purpose, navigate to the Nagios plugins download page and download the latest tar.gz source file. At the time of writing this blog, the latest version of Nagios plugins is 2.4.9, which can be downloaded using the following command:

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

After downloading the desired Nagios plugins source file, extract its content using the tar command:

tar xzf nagios-plugins-2.4.9.tar.gz

Note: Ensure to replace the source file name in case you have downloaded a different version of Nagios plugins.

Then navigate to the Nagios plugins directory via the cd command with the directory name:

cd nagios-plugins-2.4.9

Inside the directory, configure the setup files for Nagios plugins using the following command:

./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl

Once the files are configured, run the make install command to install those files on the system:

sudo make install

To ensure everything is done correctly, you can verify the Nagios configuration from the below-given command:

sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

It will return the results after the successful execution:

Step 7: Start and Enable Nagios Service

Now, start the Nagios service on Ubuntu through the following command:

sudo systemctl start nagios.service

Also, enable the Nagios service through the below-given command so that it will be able to run at system startup:

sudo systemctl enable nagios.service

Step 8: Access the Nagios Web Interface

Once you have completed the above steps successfully, you can access the Nagios web interface on any browser using the following address:

http://IP-address/nagios

Note: Replace the IP-address with the IP address of your Ubuntu system, which you can find using the hostname -I command.

When you enter the desired address in the browser, it will ask you to enter the username and password, which you have set up in Step 5:

After entering the correct login credentials, you will be able to access the Nagios web interface:

You can then be able to monitor services on the web interface:

Conclusion

Nagios is a robust monitoring system used to monitor services, servers, and applications. Setting up Nagios on Ubuntu 24.04 is a straightforward process that requires installing some dependencies, adding a user and a group, and downloading the Nagios source file. Once the source file is downloaded, configure and install the files on the system. Also, install some configuration files, init scripts, web interface files, and Nagios plugins that help access the Nagios web interface on the browser. After accessing the web interface, you will be able to use the Nagios on Ubuntu to streamline your monitoring capabilities.

Categories