Install and Setup Nagios Core on Ubuntu 20.04

|
Last Updated:
|
|

In this guide, we will provide a step-by-step tutorial on how to install and setup Nagios Core on Ubuntu 20.04. Nagios, now known as, Nagios Core, is an enterprise-class Open Source IT monitoring, network monitoring, server and applications monitoring solution.

Installing Nagios Core on Ubuntu 20.04

There are two ways in which you can install Nagios on Ubuntu 20.04.

  • Install Nagios from default Ubuntu 20.04 repositories
  • Build Nagios from Source Code on Ubuntu 20.04 (for latest and stable release versions)

In this guide, we will cover the installation of Nagios Core on Ubuntu 20.04 from the source code. We choose this method because it is the surest method to installing latest and stable release version of Nagios.

As much it is easier to install Nagios from Ubuntu repos, sometimes the repos do not provide the latest stable release versions of Nagios. Take for example, Nagios 4.x is the current versions of Nagios with Nagios 4.4.7 release being the latest stable version as per the releases page.

If you check the available versions on Ubuntu 20.04 repos, Nagios 4.3.4 is the latest stable release.

apt show nagios4

Package: nagios4
Version: 4.3.4-3
Priority: optional
Section: universe/net
Origin: Ubuntu
Maintainer: Ubuntu Developers [email protected]
Original-Maintainer: Russell Stuart [email protected]
Bugs: https://bugs.launchpad.net/ubuntu/+filebug

Hence, why we choose installation from the source code.

Run System Update

Ensure that your system packages are up-to-date.

apt update

Install Required Nagios build tools and Development Libraries

Run the command below to install the required built tools and development libraries.

apt install autoconf gcc libc6 make wget unzip apache2 php libapache2-mod-php libgd-dev libssl-dev -y

Download Nagios Core Source Code

Navigate to Nagios Core download’s page and grab the latest and stable release Nagios source tarball. Simply grab the link and optionally pull it using wget command;

wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.7.tar.gz

Extract Nagios Core Source Code

Once the download completes, extract the source archive;

tar xzf nagios-4.4.7.tar.gz

Compile and install Nagios Core

Navigate to Nagios core source directory and run the configure script to adapt Nagios Core to your system while checking for any missing required dependency before the installation;

cd nagios-4.4.7

Configure Nagios Core to use Apache as the web server. Use the --with-httpd-conf to specify where to install Nagios Core Apache site configs. Be sure to use ./configure --help for more options.

./configure --with-httpd-conf=/etc/apache2/sites-enabled

Pay attention to the output of this command just in case there is any error that needs to be fixed before you can proceed.

If all is well, you should an output similar to;


*** Configuration summary for nagios 4.4.7 2022-04-14 ***:

 General Options:
 -------------------------
        Nagios executable:  nagios
        Nagios user/group:  nagios,nagios
       Command user/group:  nagios,nagios
             Event Broker:  yes
        Install ${prefix}:  /usr/local/nagios
    Install ${includedir}:  /usr/local/nagios/include/nagios
                Lock file:  /run/nagios.lock
   Check result directory:  /usr/local/nagios/var/spool/checkresults
           Init directory:  /lib/systemd/system
  Apache conf.d directory:  /etc/apache2/sites-enabled
             Mail program:  /bin/mail
                  Host OS:  linux-gnu
          IOBroker Method:  epoll

 Web Interface Options:
 ------------------------
                 HTML URL:  http://localhost/nagios/
                  CGI URL:  http://localhost/nagios/cgi-bin/
 Traceroute (used by WAP):  


Review the options above for accuracy.  If they look okay,
type 'make all' to compile the main program and CGIs.

Next, compile the main Nagios program and CGIs.

make all

Create Nagios Core user and group. Add the user to the Apache web server group.

make install-groups-users
usermod -aG nagios www-data

Install Nagios Core main program, CGIs, and HTML files.

make install

Install Nagios Core startup scripts;

make install-init

Initialize the init scripts;

make install-daemoninit

Install and configure permissions on the directory for holding the Nagios Core external command file.

make install-commandmode

Install Nagios Core sample configuration files in /usr/local/nagios/etc.

make install-config

Install Apache configuration file for the Nagios web interface

make install-webconf

Enable Apache rewrite and CGI modules;

a2enmod rewrite cgi

Configure Nagios Core Web Interface basic authentication.

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Where nagiosadmin – this user is the default admin user for accessing Nagios Core web interface (as specified in the nagios.cfg). You can create or use any other user name and be sure to specify it in the /usr/local/nagios/etc/nagios.cfg configuration file.

If you need to add more users, omit option -c in the command above.

We are almost done setting up Nagios Core on Ubuntu 20.04.

Running Nagios Core Service

The make install-init command, install systemd service units for Nagios Core. You can start and enable Nagios Core to run on system boot by running the command;

systemctl enable --now nagios

To check the status;

systemctl status nagios

● nagios.service - Nagios Core 4.4.7
     Loaded: loaded (/lib/systemd/system/nagios.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2022-05-04 17:17:27 UTC; 6s ago
       Docs: https://www.nagios.org/documentation
    Process: 22698 ExecStartPre=/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg (code=exited, status=0/SUCCESS)
    Process: 22708 ExecStart=/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg (code=exited, status=0/SUCCESS)
   Main PID: 22709 (nagios)
      Tasks: 6 (limit: 2281)
     Memory: 3.9M
     CGroup: /system.slice/nagios.service
             ├─22709 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
             ├─22710 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
             ├─22711 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
             ├─22712 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
             ├─22713 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
             └─22720 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

May 04 17:17:27 ubuntu20 nagios[22709]: qh: core query handler registered
May 04 17:17:27 ubuntu20 nagios[22709]: qh: echo service query handler registered
May 04 17:17:27 ubuntu20 nagios[22709]: qh: help for the query handler registered
May 04 17:17:27 ubuntu20 nagios[22709]: wproc: Successfully registered manager as @wproc with query handler
May 04 17:17:27 ubuntu20 nagios[22709]: wproc: Registry request: name=Core Worker 22712;pid=22712
May 04 17:17:27 ubuntu20 nagios[22709]: wproc: Registry request: name=Core Worker 22713;pid=22713
May 04 17:17:27 ubuntu20 nagios[22709]: wproc: Registry request: name=Core Worker 22711;pid=22711
May 04 17:17:27 ubuntu20 nagios[22709]: wproc: Registry request: name=Core Worker 22710;pid=22710
May 04 17:17:28 ubuntu20 nagios[22709]: Successfully launched command file worker with pid 22720
...

Accessing Nagios Core Web Interface

Restart and enable Apache to run on system reboot;

systemctl restart apache2
systemctl enable --now apache2

If firewall is running, allow Apache through.

ufw allow Apache

You can access Nagios Core from web interface via, http://Nagios-Server-IP-OR-Hostname/nagios.

Enter your basic authentication credentials;

nagios htaccess login

Nagios Core default web interface

nagios core ui ubuntu

Install Nagios Plugins on Ubuntu 20.04

In order for Nagios to start monitoring hosts, you need to install Nagios plugins and NRPE agents. You can simply install plugins as follows;

apt install nagios-plugins

This will install a number of plugins under the directory, /usr/lib/nagios/plugins/. By default, Nagios installed from the source expects the plugins to reside under, /usr/local/nagios/libexec directory.

So for Nagios use the current plugins directory, simply edit the Nagios resource config file and update as follows;

vim /usr/local/nagios/etc/resource.cfg
...
#$USER1$=/usr/local/nagios/libexec
$USER1$=/usr/lib/nagios/plugins
...

You can as well create a symbolic link instead of making the above changes as follows;

ln -s /usr/lib/nagios/plugins/* /usr/local/nagios/libexec

By this, you should have the plugins under the /usr/local/nagios/libexec directory.

Follow the links below to learn how to add hosts for monitoring as well as installing plugins and NRPE agents on other systems.

Related Tutorials

Monitor Linux Hosts using Nagios check_by_ssh Plugin

Add Hosts to Nagios Server For Monitoring

How to Install Nagios Plugins From Source RHEL/CentOS/Oracle Linux

Monitor SSL/TLS Certificates Expiry with Nagios

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
koromicha
I am the Co-founder of Kifarunix.com, Linux and the whole FOSS enthusiast, Linux System Admin and a Blue Teamer who loves to share technological tips and hacks with others as a way of sharing knowledge as: "In vain have you acquired knowledge if you have not imparted it to others".

1 thought on “Install and Setup Nagios Core on Ubuntu 20.04”

Leave a Comment