Today we are going to learn that how to install Nagios on Ubuntu 20.04. Nagios is an open source monitoring tool used to monitor different Linux Machines or different client hosts. It monitors the HTTP, FTP, SSH, SMTP etc along-with the CPU usage, RAM, Disk Usage and different process that are being running. So, just follow the below steps for an easy installation of Nagios on Ubuntu 20.04.
Step 1: Update Your System
First of all update your system to the latest packages and also install the given packages with the help of below command as Nagios doesn’t in .deb package format.
sudo apt update
sudo apt install -y build-essential apache2 php openssl perl make php-gd libgd-dev libapache2-mod-php libperl-dev libssl-dev daemon wget apache2-utils unzip
Step 2: User Creation
In order to install Nagios you’ve to create user and group for it along-with the Apache user with the help of below commands. Just hit the given commands in your terminal.
sudo useradd nagios
sudo groupadd nagcmd
sudo usermod -a -G nagcmd nagios
sudo usermod -a -G nagcmd www-data
Step 3: Downloading Nagios on Ubuntu 20.04
Now, download the Nagios from official page or you can get it by the below command through terminal. First change to the /tmp directory and then type the below command to download the latest available version (4.4.5).
Then extract the files with the help of tar command.
tar -zxvf /tmp/nagios-4.4.5.tar.gz
And move to the resultant directory.
Step 4: Compiling Nagios on Ubuntu 20.04
After downloading and extracting, compile the Nagios from the source code by running the below commands.
sudo ./configure --with-nagios-group=nagios --with-command-group=nagcmd --with-httpd_conf=/etc/apache2/sites-enabled/
sudo make all
sudo make install
sudo make install-init
sudo make install-config
sudo make install-commandmode
Step 5: Configuring Nagios on Ubuntu 20.04
Now, with the help of your favorite editor edit the /usr/local/nagios/etc/objects/contacts.cfg file to update the email address as shown below.
sudo nano /usr/local/nagios/etc/objects/contacts.cfg
Update the email address to that where you want to get notified.
Note: Replace the nagios@localhost with your email address.
Step 6: Installing Nagios Web Interface on Ubuntu 20.04
Type the following command to install the Nagios Web Interface.
sudo make install-webconf
Then create a user account as “nagiosadmin” for accessing the Nagios web interface. Make sure to save the password you provided on safe place or keep in mind as it will be needed later. To do this run the given command.
sabi@Ubuntu:/tmp/nagios-4.4.5$ sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Re-type new password:
Adding password for user nagiosadmin
After it run the below command.
sudo a2enmod cgi
Then restart the Apache services.
sudo systemctl restart apache2
Step 7: Installing Nagios Plugin
Switch to the /tmp directory and install the Nagios plugin for monitoring purposes. Download the plugin with below command.
Then extract the downloaded package.
tar -zxvf /tmp/nagios-plugins-2.3.3.tar.gz
And switch to the resultant directory.
After it compile the plugin with following command.
sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios
sudo make install
Step 8: Starting Nagios on Ubuntu 20.04
Double check the configuration done above by hitting the given command and make sure all configuration pre-checks are okay.
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
You’ll see the similar output.
sabi@Ubuntu:/tmp/nagios-plugins-2.3.3$ sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Nagios Core 4.4.5
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 2019-08-20
Reading configuration data…
Read main config file okay…
Read object config files okay…
Running pre-flight check on configuration data…
Checked 8 services.
Checked 1 hosts.
Checked 1 host groups.
Checked 0 service groups.
Checked 1 contacts.
Checked 1 contact groups.
Checked 24 commands.
Checked 5 time periods.
Checked 0 host escalations.
Checked 0 service escalations.
Checking for circular paths…
Checked 1 hosts
Checked 0 service dependencies
Checked 0 host dependencies
Checked 5 timeperiods
Checking global event handlers…
Checking obsessive compulsive processor commands…
Checking misc settings…
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check
And then enable the Nagios services to start at boot.
sudo systemctl enable nagios
Start the services.
sudo systemctl start nagios
Step 9: Access Web Dashboard
Go to your browser and type http://ip-add/nagios/ to access the web interface. Provide the username and password we’ve created earlier and press Enter or click ok.
You’ll see the dashboard like this after successful login.
Here you can see the different options on the left side, click on hosts to see the monitoring hosts.
Just below the Hosts, click on the Services to see the services that are monitored by the Nagios.
So, this is how you can install Nagios on Ubuntu 20.04. In our next tutorial, we’ll learn how to add Remote Linux Machines/Hosts to Nagios Monitoring System. To see that click on the below link.