How to Install Nagios on Ubuntu 20

In this tutorial, we’ll show you how to install Nagios on Ubuntu 20. Nagios is the Open source tool and it is widely used for monitoring services and applications.

Prerequisite to install Nagios on Ubuntu 20:

  • You should have Installed Ubuntu 20 Operating System on Server/VM.
  • Required Sudo or root access for installing locate command
  • SSH port open on the server and SSH package pre-installed and enable it (or) Login to server with GUI and follow below steps

Steps to install Nagios on Ubuntu 20

Step 1: Update Ubuntu package

$ sudo apt-get update

Step 2: Install dependency package:

$ 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

Nagios doesn’t have a .deb package format.  You need to install the above package on your ubuntu server. So in this article, we will see how to install Nagios from the source code.

Step 3: Create account information, user and group for Nagios

sudo useradd nagios
sudo groupadd nagcmd

Step 4: Add the Nagios and apache user to the nagcmd group

sudo usermod -a -G nagcmd nagios

sudo usermod -a -G nagcmd www-data

Step 5: Download Nagios core for Ubuntu 20

Download Nagios core tar file by using wget command as mentioned in the below steps or you can also download the latest version from the official Nagios download page.

cd /tmp
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.5.tar.gz
tar -zxvf /tmp/nagios-4.4.5.tar.gz
cd /tmp/nagios-4.4.5/

Step 6: Install Nagios core on Ubuntu 20

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 7: Configure Nagios on Ubuntu 20

Default Nagios configuration files found in /usr/local/nagios/etc directory.

To receive alert notification you need to update your email id in “/usr/local/nagios/etc/objects/contacts.cfg” file.

sudo nano /usr/local/nagios/etc/objects/contacts.cfg
define contact{
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of user

email your-email@domain.com ;

}

Step 8: Install  and configure Nagios Web Interface

sudo make install-webconf

Create a nagiosadmin account for logging into the Nagios web interface.

Note: The password you need while login to Nagios web console.

sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
sudo a2enmod cgi
sudo systemctl restart apache2

Step 9: Download and Extract Nagios Plugins

cd /tmp
wget https://nagios-plugins.org/download/nagios-plugins-2.3.3.tar.gz
tar -zxvf /tmp/nagios-plugins-2.3.3.tar.gz
cd /tmp/nagios-plugins-2.3.3/

Compile and install the Nagios plugins.

sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios
sudo make
sudo make install

Step 10: Verify the sample Nagios configuration files.

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

Demo Output:

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
License: GPL

Website: https://www.nagios.org
Reading configuration data...
Read main config file okay...
Read object config files okay...

Running pre-flight check on configuration data...

Checking objects...
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

Step 11: Enable Nagios service to start automatically at system boot/startup.

sudo systemctl enable nagios

Step 12: Start Nagios Service

sudo systemctl start nagios

Step 13: Log in to the Nagios Web Interface

http://your-server-ip-address/nagios/

(Or)

http://localhost/nagios/

How to install Nagios on Ubuntu 20

Once you successful login you will get Nagios Homepage

How to install Nagios on Ubuntu 20

 

On Nagios Homepage click on the Hosts tab to see/list the servers which are monitored by Nagios.

How to install Nagios on Ubuntu 20

On the left pane click on services to view which all services are monitored in Nagios.

How to install Nagios on Ubuntu 20

End of the tutorial – How to install Nagios on Ubuntu 20. You have Nagios server up and running on Ubuntu 20.

If you want to add/monitor the remote server in Nagios then you need to install the NRPE plugin on that server and configure it.

We have already written a blog on how to add remote Linux host to Nagios monitoring server.

Thanks for reading this article, If you have any queries, comment below.