This tutorial intends to teach you to Install and Configure the Nagios Monitoring Tool on Ubuntu 22.04.
Nagios is a type of tool that is used as a monitoring tool for monitoring the network in several ways. The tool is able to provide all the system-related information to the user and is also used for real-time monitoring of the network and application. The tool is capable of monitoring the server and finding performance bottlenecks. It maintains the server statistics so that performance-related issues can be identified and can be resolved and also send alerts to the user when any issue is identified.
Steps To Install Nagios Monitoring Tool on Ubuntu 22.04
To complete this guide, you must log in to your server as a non-root user with sudo privileges and set up a basic firewall. To do this, you can follow our guide on Initial Server Setup with Ubuntu 22.04.
Install Required Packages for Nagios
First, you must update your local package index with the following command:
sudo apt update
Then, install the required packages and dependencies with the below command:
sudo apt install vim wget curl build-essential unzip openssl libssl-dev apache2 php libapache2-mod-php php-gd libgd-dev
Download the Latest Nagios on Ubuntu 22.04
At this point, you must visit the Nagios Downloads page and get the latest release by using the following commands:
# NAGIOS_VER=$(curl -s https://api.github.com/repos/NagiosEnterprises/nagioscore/releases/latest|grep tag_name | cut -d '"' -f 4)
# wget https://github.com/NagiosEnterprises/nagioscore/releases/download/$NAGIOS_VER/$NAGIOS_VER.tar.gz
Extract your downloaded file by using the following command:
sudo tar xvzf $NAGIOS_VER.tar.gz
Compile and Build Nagios Monitoring Tool on Ubuntu 22.04
Now you should compile your extracted file.
Switch to your Nagios directory with the following command:
Begin the compile process by running the command below:
sudo ./configure --with-httpd-conf=/etc/apache2/sites-enabled
When you are done, you will get the following output:
Review the options above for accuracy. If they look okay,
type 'make all' to compile the main program and CGIs.
Now you need to create a user and group. And the www-data user is also added to the “nagios” group.
# sudo make install-groups-users
groupadd -r nagios
useradd -g nagios nagios
# sudo usermod -a -G nagios www-data
Now compile the main Nagios program and associated packages with the following command:
sudo make all
Then, install the main program, CGIs, and HTML files:
sudo make install
Next, install Nagios daemon files and also configures them to start when the system boots:
sudo make install-daemoninit
After that, add the command mode that installs and configures the external command file:
sudo make install-commandmode
Here you should install the SAMPLE configuration files required as Nagios needs some configuration files to allow it to start on Ubuntu 22.04:
sudo make install-config
Configure Apache To Serve Nagios Web Pages
At this point, you need to configure our Apache to serve Nagios web pages. Nagios developers made it easier to set up Apache. You simply run one command to set up configuration files and then enable specific apache modules.
Install config files:
sudo make install-webconf
Enable Apache rewrite and CGI modules:
sudo a2enmod rewrite cgi
Configure Nagios Apache Authentication on Ubuntu 22.04
In this step, in order to create Nagios Web authentication, you need to create a web user for authentication. The “htpasswd” command rises to the occasion for this task. Please note that Nagios uses the “nagiosadmin” user by default. Run the command below and input your favorable password:
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Re-type new password:
Adding password for user nagiosadmin
When you are done, set the correct permissions to the (/usr/local/nagios/etc/htpasswd.users) file with the following commands:
# sudo chown www-data:www-data /usr/local/nagios/etc/htpasswd.users
# sudo chmod 640 /usr/local/nagios/etc/htpasswd.users
Install Nagios Monitoring Tool Plugins on Ubuntu 22.04
Before you can access your Nagios web interface, you need Nagios Plugins that will help you accomplish a lot of stuff including monitoring the local host. You can find the plugins at Nagios Plugins.
Now follow the steps below to install the latest plugins. First, switch to your home directory:
Then, run the following command to grab the Nagios plugins and extract them on Ubuntu 22.04:
# VER=$(curl -s https://api.github.com/repos/nagios-plugins/nagios-plugins/releases/latest|grep tag_name | cut -d '"' -f 4|sed 's/release-//')
# wget https://github.com/nagios-plugins/nagios-plugins/releases/download/release-$VER/nagios-plugins-$VER.tar.gz
# tar xvf nagios-plugins-$VER.tar.gz
Next, navigate into the new plugins folder then compile and install it:
# cd nagios-plugins-$VER
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
# sudo make
# sudo make install
Configure Firewall For Nagios on Ubuntu 22.04
When you are done, you need to allow ports on the firewall and start Nagios.
# sudo ufw allow 80
# sudo ufw reload
Start Nagios Monitoring Tool on Ubuntu 22.04
Start Nagios and Apache services on Ubuntu 22.04:
# sudo systemctl restart apache2
# sudo systemctl start nagios.service
Access Nagios Monitoring Tool Web Interface
At this point, you can access your Nagios web interface by typing your server’s IP address in your web browser followed by nagios:
You will be prompted for a username and password. The username as you may remember is the one we set in the previous steps, that is “nagiosadmin“. Provide credentials and click sign in.
Now you will see your Nagios dashboard:
If you click on the “Hosts” link, you should see that the localhost is up and hence being monitored thanks to the plugins we installed earlier.
The Nagios monitoring tool is a strong monitoring tool that helps to detect the issues and performance bottlenecks present in the network. The web interface provided by the tool helps to monitor the network and helps to find the issues present in the network component.
At this point, you have learned to Install and Configure the Nagios Monitoring Tool on Ubuntu 22.04.
Hope you enjoy it. You may be like these articles on the Orcacore website: