Tuesday, November 29, 2016

Step by step installation of Nagios4.x Core Ubuntu 16.04

Part 1 of Setting up and configuring Nagios4.x and PNP4Nagios.
Part 2 of Setting up and configuring Nagios4.x and PNP4Nagios. 
Part 3 of enable E-mail notification Nagios4.x and PNP4Nagios

What Is Nagios Core :-

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.


System Requirments :- 

1-  Linux machine (In my case I am using Ubuntu 16.04)

2-  Apache, PHP with gd and cgi.

Prerequisites :-
Use below command to install prerequisites

root@WPT:~# apt-get install wget build-essential apache2 php apache2-mod-php7.0 php7.0-xml php-gd libgd-dev unzip
Nagios Installation :-

Step 1 :- Create Nagios user and group:
root@WPT:~# useradd nagios
root@WPT:~# groupadd nagcmd
root@WPT:~# usermod -a -G nagcmd nagios
root@WPT:~# usermod -a -G nagios,nagcmd www-data

Step 2- Use below command to download Nagios server and Plugins

root@WPT:~# wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.2.3.tar.gz
root@WPT:~# wget http://nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz

Step 3 :- Nagios Core Extract and Installation :

Use below command to extract Nagios core :
root@WPT:~# tar -xvf nagios-4.2.3.tar.gz
Use below command to extract Nagios Plugins
root@WPT:~# tar -xvf nagios-plugins-2.1.2.tar.gz

Now Change dir to extract Nagios using below command.
root@WPT:~# cd nagios-4.2.3/

Now use below command to configure Nagios core:
root@WPT:~/nagios-4.2.3#./configure --with-command-group=nagcmd --with-httpd-conf=/etc/apache2/

Use below command to make and install 
root@WPT:~/nagios-4.2.3#make all

root@WPT:~/nagios-4.2.3#make install
root@WPT:~/nagios-4.2.3#make install-init
root@WPT:~/nagios-4.2.3#make install-config
root@WPT:~/nagios-4.2.3#make install-commandmode
root@WPT:~/nagios-4.2.3#make install-webconf

Use below command to copy eventhandlers to /usr/local/nagios/libexec/

root@WPT:~/nagios-4.2.3#cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/

Change Ownership to nagios user
root@WPT:~/nagios-4.2.3# chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
Check Nagios configuration using below command.
root@WPT:~/nagios-4.2.3# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Nagios Core 4.2.3
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 11-21-2016
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

Now copy Nagios Apache config file to /etc/apache2/site-available path
root@WPT:~/nagios-4.2.3# cp /etc/apache2/nagios.conf /etc/apache2/sites-available/
Let's enable site using below command
root@WPT:~/nagios-4.2.3# a2ensite nagios.conf

Enable apache module using below command
root@WPT:~/nagios-4.2.3#  a2enmod rewrite cgi

Now Create nagiosadmin user and password to login using web access
root@WPT:~/nagios-4.2.3# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password: *********
Re-type new password: ********
Adding password for user nagiosadmin
root@WPT:~/nagios-4.2.3#



Step 4 :- Install Nagios Plugins :
root@WPT:~# tar -xvf nagios-plugins-2.1.2.tar.gz
Change Nagios Plugins dir using below command
root@WPT:~# cd nagios-plugins-2.1.2/
Use below command to configure and install plugins:
root@WPT:~# ./configure --with-nagios-user=nagios --with-nagios-group=nagios 
root@WPT:~# make
root@WPT:~# make install

Step 5:- Install NRPE Agent
root@WPT:~/nagios-plugins-2.1.2#  apt install nagios-nrpe-server
Finally, Now Start Nagios Server service 


root@WPT:~/nagios-4.2.3# systemctl start nagios
Step 6:-  Start NRPE Agent and Nagios Core service

root@WPT:~# /etc/init.d/nagios restart
[ ok ] Restarting nagios (via systemctl): nagios.service.
root@WPT:~# /etc/init.d/nagios-nrpe-server restart
[ ok ] Restarting nagios-nrpe-server (via systemctl): nagios-nrpe-server.service.

Open browser and hit Nagios_URL


Congratulations Nagios Core has been setup successfully.

No comments:

Post a Comment