26.1 C
Texas

How To Install Nagios on Ubuntu 20.04

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.

- Advertisement -
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).

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

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.

cd /tmp/nagios-4.4.5/

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
New password:
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.

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

Then extract the downloaded package.

tar -zxvf /tmp/nagios-plugins-2.3.3.tar.gz

And switch to the resultant directory.

cd /tmp/nagios-plugins-2.3.3/

After it compile the plugin with following command.

sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios
sudo make
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

Output:

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
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

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.

How To Install Nagios on Ubuntu 20.04

You’ll see the dashboard like this after successful login.

How To Install Nagios on Ubuntu 20.04

Here you can see the different options on the left side, click on hosts to see the monitoring hosts.

How To Install Nagios on Ubuntu 20.04

Just below the Hosts, click on the Services to see the services that are monitored by the Nagios.

How To Install Nagios on Ubuntu 20.04

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.

How To Monitor Remote Hosts with Nagios on Ubuntu 20.04

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

1 COMMENT

  1. Hello Sabi,
    nice tutorial.

    I tried it on a fresh ubuntu 20.10 installation.
    When I run “sudo make all”, I get the following error:
    collect2: error: ld returned 1 exit status

    Do you have a solution? Thanks.

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article