In this tutorial, we want to show you to Install and Configure the Nagios Core Monitoring Tool on Ubuntu 20.04.
Nagios is a free and open-source software application for computer systems. It is used for monitoring the systems, networks, and infrastructure.
This software application is written in C language, which was mainly designed to run under the Linux operating system. But it can also run under Unix and Windows operating systems.
This software application is available in the following two variants:
- Nagios Core: The Nagios is also known as a Nagios Core. It is an open-source product.
- Nagios XI: It is an extended version of Nagios. It provides advanced components and tools for monitoring. This variant needs a software license.
Steps To Install Nagios Monitoring Tool on Ubuntu 20.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 20.04.
In this guide, you will learn to Install Nagios Core on Ubuntu 20.04.
Set up Nagios Monitoring Tool on Ubuntu 20.04
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 -y
Download Nagios For Ubuntu 20.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
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:
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
Output 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
Output *** Init script installed ***
After that, add the command mode that installs and configures the external command file:
sudo make install-commandmode
Output *** External command directory configured ***
Here you should install the SAMPLE configuration files required as Nagios needs some configuration files to allow it to start on Ubuntu 20.04:
sudo make install-config
Output *** Config files installed ***
At this point, you need to configure your 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
Output *** Nagios/Apache conf file installed ***
Enable Apache rewrite and CGI modules:
sudo a2enmod rewrite cgi
Configure Nagios Apache Authentication on Ubuntu 20.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
Output New password: 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 20.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 20.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 20.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 20.04
Now start Nagios and Apache services on Ubuntu 20.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 Core Monitoring Tool on Ubuntu 20.04.
Hope you enjoy it. You may be interested in these articles: