Install Nagios core 4.1.1 on Ubuntu 16.04 (Xenial Xerus) Server

Sponsored Link
Nagios® Core™ is an Open Source system and network monitoring application. It watches hosts and services that you specify, alerting you when things go bad and when they get better.Nagios Core was originally designed to run under Linux, although it should work under most other unices as well.

Nagios Features

Some of the many features of Nagios Core include:

Monitoring of network services (SMTP, POP3, HTTP, NNTP, PING, etc.)
Monitoring of host resources (processor load, disk usage, etc.)
Simple plugin design that allows users to easily develop their own service checks
Parallelized service checks
Ability to define network host hierarchy using "parent" hosts, allowing detection of and distinction between hosts that are down and those that are unreachable
Contact notifications when service or host problems occur and get resolved (via email, pager, or user-defined method)
Ability to define event handlers to be run during service or host events for proactive problem resolution
Automatic log file rotation
Support for implementing redundant monitoring hosts
Optional web interface for viewing current network status, notification and problem history, log file, etc.

Preparing your system

First You need to make sure you have install Ubuntu 16.04 LAMP Server and once you have that follow the next steps.

Switch to root user and run the all the commands

sudo su --

Install the following packages

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

You need to create nagios user,nagcmd group and add the nagios,apache user to the part of nagcmd group

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

Download Nagios core DIY Source from here

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

Compile and install Nagios Using the following commands

./configure –with-nagios-group=nagios –with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf

You may get the following error

root@ubuntu:/tmp/nagios-4.1.1# make install-webconf
/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf
/usr/bin/install: cannot create regular file ‘/etc/httpd/conf.d/nagios.conf': No such file or directory
Makefile:296: recipe for target ‘install-webconf' failed
make: *** [install-webconf] Error 1

The above error message is due to that nagios is trying to create the nagios.conf file inside the /etc/httpd.conf/directory. But, in Ubuntu systems the nagios.conf file should be placed in /etc/apache2/sites-enabled/directory

Run the following command instead of make install-webconf

sudo /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/sites-enabled/nagios.conf

make install-exfoliation

Configure Nagios web Interface

Create nagiosadmin account using the following command

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

Enable CGI module and restart the apache2 server

a2enmod cgi

service apache2 restart

Install Nagios Plugins

Download and install nagios plugins using the following commands

cd /tmp

wget http://www.nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz

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

cd /tmp/nagios-plugins-2.1.1/

Compile and install nagios plugins using the following commands

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

Start Nagios

Verify the sample nagios configuration files using the following command

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

Output

Nagios Core 4.1.1
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 08-19-2015
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

If you are not seeing any errors the start nagios using the following

/etc/init.d/nagios start

When i try to start the nagios i got the following error and found out there is an issue with nagios init script

[....] Starting nagios (via systemctl): nagios.serviceFailed to start nagios.service: Unit nagios.service failed to load: No such file or directory. failed!

Solution to nagios init script

Copy /etc/init.d/skeleton to /etc/init.d/nagios using the following command

cp /etc/init.d/skeleton /etc/init.d/nagios

Now edit the nagios file

vi nagios

add the following lines

DESC="Nagios"
NAME=nagios
DAEMON=/usr/local/nagios/bin/$NAME
DAEMON_ARGS="-d /usr/local/nagios/etc/nagios.cfg"
PIDFILE=/usr/local/nagios/var/$NAME.lock

Save and exit the file

Finally you need to change the permissions of the file

chmod +x /etc/init.d/nagios

You can start the nagios using the following command

/etc/init.d/nagios start

Ouput

* Starting Nagios [ OK ]

Screenshots

1

2

Sponsored Link

You may also like...

4 Responses

  1. Christophe says:

    Why are people still writting tutorials for Nagios? They don’t care about their users, community and their architecture isn’t scalable.

    Do yourself a favour and take a look at Icinga. https://www.icinga.org/products/icinga-2/

  2. martin prezelj says:

    Hello!

    i have a little problem , when executing ./configure –with-nagios-group=nagios –with-command-group=nagcmd
    it doesn’t work , so i compiled it without nagios group and command group , but now when i try to search left pane of nagios web interface nothing works . it displays problems with cgi like :
    /tac.cgi” target=””>Tactical Overview

    any else have such problem ?
    thanks for reply

  3. mark simmons says:

    I followed this guid and got this working on a fresh zorin desktop test vm (ubuntu 16.04.2). Could we please have a 2nd part on how to add remote machine monitoring ? NRPE, NSCA…

  4. Stuart Hill says:

    Many thanks for this most excellent tutorial

    I have little knowledge of linux and was able to follow this easily.

    I did have to delete the first VM I made as I missed the early instruction that I needed LAMP setup ! After this hiccup I installed a fresh Ubuntu 16.04.1 server and then followed the guide to the letter. It took about an hour or so to get to the nagios website login.

    My only deviation was following the failed “make install-webconf” command, I found that the following command would also give an error :

    sudo /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/sites-enabled/nagios.conf

    What I needed to do first was to create the folder /etc/apache2/site-enabled with :
    “mkdir /etc/apache2/site-enabled”

    .. then it all worked fine

Leave a Reply

Your email address will not be published. Required fields are marked *