Flipkart

Wednesday, January 11, 2017

Installing Nagios 4.2.0 and Nagios Plugin 2.1.2

Install Required Dependencies

yum install -y httpd php gcc glibc glibc-common gd gd-devel make net-snmp


yum install -y httpd php gcc glibc glibc-common gd gd-devel make net-snmp


Create Nagios User and Group

useradd nagios

groupadd nagcmd


Next, add both the nagios user and the apache user to the nagcmd group. 

 usermod -G nagcmd nagios
 usermod -G nagcmd apache

Download Nagios Core 4.2.0 and Nagios Plugin 2.1.2


Create a directory for your Nagios installation and all its future downloads. 

  mkdir /root/nagios
  cd /root/nagios

  wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.2.0.tar.gz
  wget https://www.nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz

Extract Nagios Core and its Plugins

#  tar -xvf nagios-4.2.0.tar.gz
#  tar -xvf nagios-plugins-2.1.2.tar.gz


# ls -l


total 13528

drwxrwxr-x. 18 root root 4096 Aug 20 2015 nagios-4.2.0
-rw-r--r--. 1 root root 11142182 Aug 20 2015 nagios-4.2.0.tar.gz
drwxr-xr-x. 15 root root 4096 Aug 1 21:58 nagios-plugins-2.1.2
-rw-r--r--. 1 root root 2695301 Aug 1 21:58 nagios-plugins-2.1.2.tar.gz

Configure Nagios Core
 # cd nagios-4.2.0
 # ./configure --with-command-group=nagcmd


Sample output:
Creating sample config files in sample-config/ ...
*** Configuration summary for nagios 4.2.0 08-01-2016 ***:
General Options:
-------------------------


Nagios executable: nagios
Nagios user/group: nagios,nagios
Command user/group: nagios,nagcmd
Event Broker: yes
Install ${prefix}: /usr/local/nagios
Install ${includedir}: /usr/local/nagios/include/nagios
Lock file: ${prefix}/var/nagios.lock
Check result directory: ${prefix}/var/spool/checkresults
Init directory: /etc/rc.d/init.d
Apache conf.d directory: /etc/httpd/conf.d
Mail program: /bin/mail
Host OS: linux-gnu
IOBroker Method: epoll
Web Interface Options:
------------------------
HTML URL: http://localhost/nagios/
CGI URL: http://localhost/nagios/cgi-bin/
Traceroute (used by WAP): /usr/bin/traceroute
Review the options above for accuracy. If they look okay,
type 'make all' to compile the main program and CGIs.


# make all

# make install

Sample output:
*** Exfoliation theme installed ***
NOTE: Use 'make install-classicui' to revert to classic Nagios theme
make[1]: Leaving directory '/root/nagios/nagios-4.2.0'
make install-basic
make[1]: Entering directory '/root/nagios/nagios-4.2.0'
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/libexec
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/archives
/usr/bin/install -c -m 775 -o nagios -g nagcmd -d /usr/local/nagios/var/spool/checkresults
chmod g+s /usr/local/nagios/var/spool/checkresults
*** Main program, CGIs and HTML files installed ***
You can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):
make install-init
- This installs the init script in /etc/rc.d/init.d
make install-commandmode
- This installs and configures permissions on the
directory for holding the external command file
make install-config
- This installs sample config files in /usr/local/nagios/etc
make[1]: Leaving directory '/root/nagios/nagios-4.2.0'


 # make install-init

# make install-commandmode

# make install-config

Sample output:
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/cgi.cfg /usr/local/nagios/etc/cgi.cfg
/usr/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg /usr/local/nagios/etc/objects/templates.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/commands.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg
*** Config files installed ***
Remember, these are *SAMPLE* config files. You'll need to read
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.


Customizing Nagios Configuration

Open the “contacts.cfg” file with your choice of editor and set the email address associated with the nagiosadmin contact definition to receiving email alerts.

# vi /usr/local/nagios/etc/objects/contacts.cfg


Sample Output 

###############################################################################
###############################################################################
#
# CONTACTS
#
###############################################################################
###############################################################################
# Just one contact defined by default - the Nagios admin (that's you)
# 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

}


Install and Configure Web Interface for Nagios

make install-webconf

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

New password:
Re-type new password:
Adding password for user nagiosadmin

Restart Apache to make the new settings take effect.

Restart Apache to make the new settings take effect.
# service httpd restart

Compile and Install Nagios Plugin

/root/nagios, Go there and configure and install it as directed below.

# cd /root/nagios

 # cd nagios-plugins-2.1.2/

 # ./configure --with-nagios-user=nagios --with-nagios-group=nagios

 # make
 # make install


Verify Nagios Configuration Files

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


Sample Output

Nagios Core 4.2.0
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 08-01-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
Things look okay - No serious problems were detected during the pre-flight check


Add Nagios Services to System Startup 

To make Nagios work across reboots, we need to add nagios and httpd with chkconfig and systemctlcommand.

On RHEL/CentOS 6/5 and Fedora
# chkconfig --add nagios
# chkconfig --level 35 nagios on
# chkconfig --add httpd
# chkconfig --level 35 httpd on

Restart Nagios to make the new settings take effect. 

# service nagios start [On RHEL/CentOS 6/5 and Fedora]

 Login to the Nagios Web Interface

Your nagios is ready to work, please open it in your browser with “http://Your-server-IP-address/nagios” 


Nagios Web Dashboard

No comments:

Post a Comment