How to Install Nagios 4.3 on Ubuntu 16.04 & 14.04 LTS

How to Install Nagios 4.3 on Ubuntu 16.04 & 14.04 LTS

Nagios is the most popular, open source, powerful monitoring system for any kind of infrastructure. It enables organizations to identify and resolve IT infrastructure problems before they affect critical business processes. Nagios has the capability of monitoring application, services, entire IT infrastructure.

This article will help you to setup Nagios Monitoring Server on Ubuntu 16.04 LTS, 14.04 LTS and 12.04 LTS and Debian systems. After completing this article, you will like to follow below tutorials.

How to Monitor remote Linux host using Nagios
How to Monitor remote Windows host using Nagios

#1. Prerequisite

We assume that you have fresh installed Ubuntu/Debian systems, So our first requirement is to install Apache and PHP first. Use the following commands to complete it.

Let’s use following commands to install required packages for Nagios.

For Ubuntu 16.04 or Above:

$ sudo apt update
$ sudo apt install wget build-essential unzip
$ sudo apt install apache2 php7.0 apache2-mod-php7.0 php7.0-gd libgd-dev 

For Ubuntu 15.10 or Below

$ sudo apt update
$ sudo apt-get install wget build-essential apache2 php5 php5-gd libgd-dev unzip

#2. Create Nagios User

First of all, create a new user account for Nagios in your system and assign a password.

$ sudo adduser nagios

Now create a group for Nagios setup “nagcmd” and add nagios user to this group. Also, add nagios user in Apache group.

$ sudo groupadd nagcmd
$ sudo usermod -a -G nagcmd nagios
$ sudo usermod -a -G nagcmd www-data

#3. Install Nagios Core Service

After installing required dependencies and adding user accounts. Let’s start with Nagios core installation. Download latest Nagios core service from the official site.

$ cd /opt/
$ wget
$ tar xzf nagios-4.3.2.tar.gz
$ cd nagios-4.3.2
$ sudo ./configure --with-command-group=nagcmd
$ sudo make all
$ sudo make install
$ sudo make install-init
$ sudo make install-config
$ sudo make install-commandmode

Now copy event handlers scripts under libexec directory. These binaries provides multiple events triggers for your Nagios web interface.

$ cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
$ chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers

Now create nagios apache2 configuration file.

$ sudo vi /etc/apache2/conf-available/nagios.conf
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"

<Directory "/usr/local/nagios/sbin">
   Options ExecCGI
   AllowOverride None
   Order allow,deny
   Allow from all
   AuthName "Restricted Area"
   AuthType Basic
   AuthUserFile /usr/local/nagios/etc/htpasswd.users
   Require valid-user

Alias /nagios "/usr/local/nagios/share"

<Directory "/usr/local/nagios/share">
   Options None
   AllowOverride None
   Order allow,deny
   Allow from all
   AuthName "Restricted Area"
   AuthType Basic
   AuthUserFile /usr/local/nagios/etc/htpasswd.users
   Require valid-user

For Ubuntu users using systemd:
For Users running with Ubuntu 16.04 or later versions and using systemd for managing process can enable nagios with systemd using following commands.

$ sudo cp /etc/init.d/skeleton /etc/init.d/nagios
$ sudo vi /etc/init.d/nagios

and add the following lines

DAEMON_ARGS="-d /usr/local/nagios/etc/nagios.cfg"

#4. Enable Apache Authentication

We need to setup apache authentication for user nagiosadmin. Untill more specific reason use this user name as “nagiosadmin” else you would required more changes in configuration.

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

Now enable Apache configuration and restart Apache service to make the new settings take effect.

$ sudo a2enconf nagios
$ sudo a2enmod cgi rewrite
$ sudo service apache2 restart

#5. Installing Nagios Plugins

After installing and configuring Nagios core service, Download latest nagios-plugins source and install using following commands.

$ cd /opt
$ wget
$ tar xzf nagios-plugins-2.2.1.tar.gz
$ cd nagios-plugins-2.2.1

Now compile and install Nagios plugins

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

#6. Verify Configuration and Start Nagios

Use the following commands to verify Nagios install and start Nagios core service.

$ /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
$ service nagios start

Also configure Nagios to auto start on system boot.

$ sudo systemctl enable nagios

#7. Access Nagios Web Interface

Access your nagios setup by access nagios server using hostname or ip address followed by /nagios.
[change domain name with your domain or ip]

Prompting for Apache Authentication Password –

Nagios After login screen –

Now you have successfully installed and configured Nagios Monitoring Server core service in your system. Now visit net article to monitor Linux host and Windows host using Nagios server.


Enjoyed this video?
How to Install Nagios 4.3 on Ubuntu 16.04 & 14.04 LTS
"No Thanks. Please Close This Box!"