How to Install Nagios on Ubuntu 16.04

Install Nagios on Ubuntu 16.04

In this tutorial we’ll learn how to install Nagios on Ubuntu 16.04. We will also install and configure its prerequisites. Nagios is the most widely used open source monitoring tools which help us to monitor the services and application that run’s on Windows, Linux, Routers and other network devices. The server administrator who uses Nagios gains access to a wide variety of features such as SSH-enabled remote monitoring, network and host traffic monitoring, and a versatile plugin ecosystem.

I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an Ubuntu 16.04 minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.

Install Nagios on Ubuntu 16.04

Step 1. First, ensure your system and apt package lists are fully up-to-date by running the following:

apt-get update -y && apt-get upgrade -y

Step 2. Installing Required Dependencies.

You’all need to install some basic prerequisite packages for Nagios:

apt-get install build-essential apache2 php7.0 openssl perl make php7.0-gd libgd2-xpm-dev libapache2-mod-php7.0 libperl-dev libssl-dev daemon wget apache2-utils unzip

Step 3. Creating Nagios User and Group.

Create a nagios user and nagcmd group for allowing the external commands to be executed through the web interface, add the nagios and apache user to be a part of nagcmd group:

useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd www-data

Step 4. Installing Nagios.

After installing required dependencies and adding user accounts. Let’s start with Nagios core installation:

cd /tmp

Extract nagios tarball archive you downloaded and use the script inside to install:

tar -zxvf nagios-4.3.2.tar.gz
cd /tmp/nagios-4.3.2/

Compile and Install Nagios:

./configure --with-nagios-group=nagios --with-command-group=nagcmd --with-httpd_conf=/etc/apache2/sites-enabled/
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf

Step 4. Configure Nagios.

Edit the contacts.cfg file and to do so open this file using any text editor:

nano /usr/local/nagios/etc/objects/contacts.cfg

Replace email with your own email then save the file and exit from the text editor:

# This contact definition inherits a lot of default values from the 'generic-contact'
# template which is defined elsewhere.
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 nagios@localhost ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ****** } [...]

We need to setup apache authentication for user nagiosadmin. Do not change this username. else you would required more changes in configuration:

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

Run the following command to enable Apache modules:

sudo a2enmod rewrite
sudo a2enmod cgi

Step 5. Installing Nagios Plugins.

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

tar -zxvf /tmp/nagios-plugins-2.2.1.tar.gz
cd /tmp/nagios-plugins-2.2.1/

Compile and install the plugins:

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

Verify the sample Nagios configuration files:

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

Ubuntu 16.04 use systemd for starting / stopping all the services, so, we need to create nagios.service file:

nano /etc/systemd/system/nagios.service

Add below content into above file:



ExecStart=/usr/local/nagios/bin/nagios /usr/local/nagios/etc/nagios.cfg

Now, start Nagios service and enable Nagios to start automatically at system startup:

systemctl enable /etc/systemd/system/nagios.service
systemctl start nagios

Step 6. Accessing Nagios Web Installation.

Now you can access the Nagios web install wizard in your browser by entering the domain name or http://your_ip/nagios/ to continue your  installation. You’ll be prompted for the username (nagiosadmin) and password you specified earlier.

Congratulation’s! You have successfully install and configured Nagios on your Ubuntu 16.04 LTS server.