Friday, March 24, 2017

How to Install and configure Nagios 4.x on Centos 7.x


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 Centos7.X)
2- HTTPd, PHP with gd and CGI.

Nagios Installation:-

Step 1- Install and setup prerequisites 
 Install Deployment tool 
[root@localhost ~]# yum groupinstall "Development Tools"

Install PHP, HTTPD, Pearl and wget
[root@localhost ~]# yum install wget perl httpd php gcc glibc glibc-common gd gd-devel make net-snmp libpng-devel libjpeg-turbo-devel

Create nagios User and group:
[root@localhost ~]# useradd nagios && passwd nagios      ##Command to add user and set password ##
[root@localhost ~]# groupadd nagcmd                      ## Command to add group ##
[root@localhost ~]# usermod -a -G nagcmd nagios          ## command to add nagios user in group nagcmd ##
[root@localhost ~]# usermod -a -G nagcmd apache          ## Command to add apache user in group nagcmd ##

Step 2- Install and configure Nagios
Download Nagios stable release 
[root@localhost ~]# wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.2.4.tar.gz
 Extract and Configure
[root@localhost ~]# tar zxfv nagios-4.2.4.tar.gz
Now go to extracted directory
[root@localhost ~]# cd nagios-4.2.4

Configure Nagios for installation
[root@localhost nagios-4.2.4]# ./configure -with-command-group=nagcmd

Make and install all the configuration files
[root@localhost nagios-4.2.4]# make all
[root@localhost nagios-4.2.4]# make install
[root@localhost nagios-4.2.4]# make install-init
[root@localhost nagios-4.2.4]# make install-commandmode
[root@localhost nagios-4.2.4]# make install-config
[root@localhost nagios-4.2.4]# make install-webconf
Copy eventhandlers and set permission
[root@localhost nagios-4.2.4]# cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/

[root@localhost nagios-4.2.4]# chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
Copy Check Nagios configuration and add Nagios login credentials 
[root@localhost nagios-4.2.4]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Nagios Core 4.2.4
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 12-07-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 26 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

Setup Nagios login credentials
[root@localhost nagios-4.2.4]#  htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:   *********
Re-type new password:   *********

Adding password for user nagiosadmin

Install Nagios Plugins and NRPE client
[root@localhost nagios-4.2.4]# yum install nagios-plugins-all nagios-plugins-nrpe

Update Firewall-cmd and allow http access
[root@localhost nagios-4.2.4]# firewall-cmd --permanent --add-service=http

[root@localhost nagios-4.2.4]# firewall-cmd --reload

Change plugins access user from this file "usr/local/nagios/etc/resource.cfg"
[root@localhost nagios-4.2.4]# vi /usr/local/nagios/etc/resource.cfg
Made changes as follow
# Sets $USER1$ to be the path to the plugins
#$USER1$=/usr/local/nagios/libexec
$USER1$=//usr/lib64/nagios/plugins
# Sets $USER2$ to be the path to event handlers
#$USER2$=/usr/local/nagios/libexec/eventhandlers
Enable Nagios and httpd service to start at boot time 
[root@localhost nagios-4.2.4]# systemctl enable httpd && systemctl enable nagios
Now reload httpd and nagios service
[root@localhost nagios-4.2.4]# systemctl restart httpd && systemctl restart nagios

Installation and configuration part completed successfully.
Let's check through URL: http://192.168.102.11/nagios/



















!!! Congrats Nagios 4.x installation and configuration part completed successfully !!!


In the next blog we will learn how to configure pnp4nagios to generate graph and view usage of resource whenever needed.



11 comments:

  1. thank you so much, excellent manual but i had a problem installing the plugins, i used yum install nagios-plugins-all and nagios-plugins-nrpe and the package source says: no package avaliable.
    But i used this:
    wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz
    tar xzf nagios-plugins-2.0.3.tar.gz
    cd nagios-plugins-2.0.3
    ./configure --with-nagios-user=nagios --with-nagios-group=nagios
    make
    make install
    ant then continue with your manual.
    hope you answer my comment.
    Thank You!

    ReplyDelete
    Replies
    1. Could you please let me know what CentOS version you have? or you can try run this command - yum groupinstall "Development Tools"

      Delete
  2. I have this version CentOS-7-x86_64-DVD-1611.iso ; and I already install Development Tools.

    ReplyDelete
  3. Loaded plugins: fastestmirror, langpacks
    Loading mirror speeds from cached hostfile
    * base: mirrors.ucr.ac.cr
    * extras: mirrors.ucr.ac.cr
    * updates: ftp.unicamp.br
    repo id repo name status
    base/7/x86_64 CentOS-7 - Base 9,363
    extras/7/x86_64 CentOS-7 - Extras 447
    updates/7/x86_64 CentOS-7 - Update 2100
    repolist: 11,910

    ReplyDelete
    Replies
    1. Please add epel repo by command below-
      "yum install epel-release"
      Then try to install NAGIOS plugin

      Delete
  4. Done! Thank you so much.
    So I have a Q, do you have information about Nagios4,Pnp4, and nagiosql working in CentOS7.x?
    I'm looking for information, how to configure those service in the same server.

    ReplyDelete
    Replies
    1. Try This-- First one you Already done, Go for Number 2 for PnP4 integration
      Install and configure Nagios4.x- https://linuxhowtoguide.blogspot.ca/2017/03/how-to-install-and-configure-nagios-4x.html

      Congigure PnP4 - https://linuxhowtoguide.blogspot.ca/2017/03/how-to-install-and-configure-pnp4nagios.html

      Delete
  5. Thank, i just need nagiosql.
    Thank you very much.

    ReplyDelete
    Replies
    1. I did not create my own NagiosQL document yet, but i will work on this section too. for now you can use this link -
      https://tecadmin.net/install-nagiosql-with-nagios-core-on-centos-rhel/

      I am not sure about it, but seems it should work as expected.

      Delete