We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

Learn how to – Install and Configure Nagios 4 on Ubuntu 22.04|20.04|18.04

Learn how to – Install and Configure Nagios 4 on Ubuntu 22.04|20.04|18.04.

Welcome to our guide on how to install and configure Nagios 4 on Ubuntu 22.04|20.04|18.04. The edition of Nagios that will be installed on Ubuntu is Nagios Core. Nagios® Core™ is an Open Source system and network monitoring application. Nagios watches hosts and services that you specify, alerting you when things go bad and when they get better.

Nagios will enable your organization to identify and resolve IT infrastructure problems before they affect critical business processes. This is achieved through a pro-active IT infrastructure monitoring to ensure systems, applications, services, and business processes are functioning properly. Whenever a failure is recorded, Nagios will alert the technical staff of the problem.

Follow the steps in the next sections to have a running Nagios 4 monitoring server on Ubuntu 22.04|20.04|18.04 Linux machine.

Step 1: Update System

Run the update commands on your Ubuntu system to ensure you’re on the latest release.

sudo apt update && sudo apt upgrade -y

It is recommended to reboot if no service will be impacted.

[ -f /var/run/reboot-required ] && sudo reboot -f

Step 2: Install the required packages

Once the system is upgraded and rebooted. You’ll need to install the packages required to build Nagios Core on Ubuntu Linux.

sudo apt update
sudo apt install wget unzip vim curl openssl build-essential libgd-dev libssl-dev libapache2-mod-php php-gd php apache2

Step 3: Download Nagios Core

Check the releases page for latest Nagios available.

NAGIOS_VER=$(curl -s https://api.github.com/repos/NagiosEnterprises/nagioscore/releases/latest|grep tag_name|cut -d '"' -f 4)
curl -SL https://github.com/NagiosEnterprises/nagioscore/releases/download/$NAGIOS_VER/$NAGIOS_VER.tar.gz | tar -xzf -

The command will download and extract the Nagios core archive to your current working directory.

Change to created Nagios folder.

cd $NAGIOS_VER

Step 4: Install Nagios Core on Ubuntu

After extracting the archive, run the configure script:

 ./configure

Run the make command with all option to compile the main program and CGIs.

make all

Create User And Group:

sudo make install-groups-users
sudo usermod -a -G nagios www-data

Install Nagios Core 4.x on Ubuntu:

sudo make install

Install the init script in /lib/systemd/system,

sudo make install-daemoninit

Install and configures permissions on the directory for holding the external command file:

sudo make install-commandmode

Install sample config files in /usr/local/nagios/etc.

sudo make install-config

Install the Apache config file for the Nagios web interface:

sudo make install-webconf
sudo a2enmod rewrite cgi
sudo systemctl restart apache2

Install the Exfoliation theme for the Nagios web interface.

sudo make install-exfoliation

If you want to use classic Nagios theme, run:

<make install-classicui>

Step 5: Create Nagios Web user

A user is required for the access to Nagios web console.

$ sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password: 
Re-type new password: 
Adding password for user nagiosadmin

The htpasswd has been used to generate the password and write it to the /usr/local/nagios/etc/htpasswd.users file.

Step 6: Install Nagios Plugins

Nagios plugins are used to extend Nagios monitoring features. Let’s ensure they are installed. Check for the latest release of Nagios plugins from Github releases page.

cd ~/
VER=$( curl -s https://api.github.com/repos/nagios-plugins/nagios-plugins/releases/latest|grep tag_name|cut -d '"' -f 4|sed 's/release-//')
curl -SL https://github.com/nagios-plugins/nagios-plugins/releases/download/release-$VER/nagios-plugins-$VER.tar.gz | tar -xzf -

Change to the plugins source directory:

cd nagios-plugins-$VER

Compile and install Nagios plugins by running commands below.

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

Step 7: Verify installation and Start Nagios service

Confirm that your Nagios installation was successful on Ubuntu Linux machine.

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

You should get an output similar to below if installation of Nagios was successful.

Nagios Core 4.4.8
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 2022-10-04
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

Start and enable nagios service to start at boot.

sudo systemctl  enable --now nagios

Confirm that nagios service is running.

$ systemctl status nagios
 nagios.service - Nagios Core 4.4.8
     Loaded: loaded (/lib/systemd/system/nagios.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2022-10-14 16:50:19 EAT; 4s ago
       Docs: https://www.nagios.org/documentation
    Process: 33440 ExecStartPre=/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg (code=exited, status=0/SUCCESS)
    Process: 33445 ExecStart=/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg (code=exited, status=0/SUCCESS)
   Main PID: 33446 (nagios)
      Tasks: 8 (limit: 9460)
     Memory: 6.1M
        CPU: 150ms
     CGroup: /system.slice/nagios.service
             ├─33446 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
             ├─33447 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
             ├─33448 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
             ├─33449 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
             ├─33450 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
             ├─33451 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
             ├─33452 /usr/local/nagios/libexec/check_ping -H 127.0.0.1 -w 3000.0,80% -c 5000.0,100% -p 5
             └─33453 /usr/bin/ping -n -U -w 30 -c 5 127.0.0.1

Oct 14 16:50:19 jammy nagios[33446]: qh: Socket '/usr/local/nagios/var/rw/nagios.qh' successfully initialized
Oct 14 16:50:19 jammy nagios[33446]: qh: core query handler registered
Oct 14 16:50:19 jammy nagios[33446]: qh: echo service query handler registered
Oct 14 16:50:19 jammy nagios[33446]: qh: help for the query handler registered
Oct 14 16:50:19 jammy nagios[33446]: wproc: Successfully registered manager as @wproc with query handler
Oct 14 16:50:19 jammy nagios[33446]: wproc: Registry request: name=Core Worker 33449;pid=33449
Oct 14 16:50:19 jammy nagios[33446]: wproc: Registry request: name=Core Worker 33448;pid=33448
Oct 14 16:50:19 jammy nagios[33446]: wproc: Registry request: name=Core Worker 33450;pid=33450
Oct 14 16:50:19 jammy nagios[33446]: wproc: Registry request: name=Core Worker 33447;pid=33447
Oct 14 16:50:20 jammy nagios[33446]: Successfully launched command file worker with pid 3345

Step 8: Access Nagios Web Dashboard

if you have ufw firewall, allow http and https ports for inbound traffic.

for i in http https ssh; do sudo ufw allow $i; done

Now use your browser to access the Nagios dashboard on http:[IP/hostname]/nagios/

Input the credentials for the user created earlier.

You should get to Nagios Administration dashboard.

We hope this guide helped you to install Nagios 4 on Ubuntu 22.04|20.04|18.04. The next reading is monitoring for your IT environment.

Go through official Nagios 4 documentation for configuration guides.

Similar guides:

Install LibreNMS on Ubuntu

Install Grafana on Debian

Install Prometheus on Ubuntu

Cart

Your Cart is Empty

Back To Shop