Monday, 13 March 2017

Install and Configure Nagios On CentOS 6.8


Nagios now known as Nagios Core, is a free and open source computer-software application that monitors systems, networks and infrastructure. Nagios offers monitoring and alerting services for servers, switches, applications and services. 


Nagios was originally designed to run under Linux, but it also runs well on other Unix variants. It is free software licensed under the terms of the GNU General Public License version 2 as published by the Free Software Foundation.

NRPE Agent
Nagios Remote Plugin Executor (NRPE) is a Nagios agent that allows remote system monitoring using scripts that are hosted on the remote systems.[5] It allows for monitoring of resources such as disk usage, system load or the number of users currently logged in. Nagios periodically polls the agent on remote system using the check_nrpe plugin.

NCPA Agent 
The Nagios Cross Platform Agent is an open source project maintained by Nagios Enterprises.[7] NCPA installs on Windows, Linux, and Mac OS X. Created as a scale-able API that allows flexibility and simplicity in monitoring hosts. NCPA allows multiple checks such as memory usage, CPU usage, disk usage, processes, services, and network usage. Active checks are queried through the API of the "NCPA Listener" service while passive checks are sent via the "NCPA Passive" service.

To know more Visit 


This article is intended to guide you with easy instructions on how to install Nagios 4.1.1 from source on CentOS 6.8

 Step 1:  Host Setup 


[root@server10 ~]# vi  /etc/hosts 
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 server10
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.47.181 server10
Disable Firewall if Required :

For CentOS 6 :


# service iptables save
# service iptables stop
# chkconfig iptables off

# service ip6tables save
# service ip6tables stop
# chkconfig ip6tables off

Disable Selinux 

 Edit the /etc/sysconfig/selinux file as below :

[root@server22 ~]# cat /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - SELinux is fully disabled.
SELINUX=disabled
# SELINUXTYPE= type of policy in use. Possible values are:
#       targeted - Only targeted network daemons are protected.
#       strict - Full SELinux protection.
SELINUXTYPE=targeted

Restart the System and Check :


[root@server22 ~]# sestatus 
SELinux status:                 disabled

Step 2 : Install the Required Dependencies 


$ yum install php -y;

$ yum install php-mysql -y;
 
$ yum install wget;

$ yum -y install libev;

$ yum install -y  httpd php;

$ yum  -y install gcc glibc glibc-common;

$ yum -y install gd gd-devel;

$ yum install php-cli net-snmp wget -y;

$ yum -y install epel-release;

$ yum -y install xinetd openssl openssl-devel;

$ yum -y install telnet ;
 
$ yum -y install perl-DBD-MySQL-4.013-3.el6.x86_64.rpm ;
 
$ yum -y install perl-Time-HiRes.x86_64 ;

Step 3 : Create the user and group for Nagios installation.

Create a new nagios user and nagcmd group account and set a password.


useradd nagios
passwd nagios


Now create a group for nagios setup “nagcmd” and add nagios user to this group. Also add nagios user in apache group:

groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd apache

Step 4 : Download Nagios Core 4.1.1 

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


mkdir /opt/Downloads ; mkdir /opt/nagios ;

[root@server10 opt]# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.1.1.tar.gz  

Step 5: Extract Nagios Core Package 


cd /opt
tar -xvzf  nagios-4.1.1.tar.gz  

Step 6 : Configure Nagios Core 

Now, first we will configure Nagios Core and to do so we need to go to Nagios directory and run configure file and if everything goes fine, it will show the output in the end as sample output


cd nagios-4.1.1

./configure --with-command-group=nagcmd

Sample Output 


Creating sample config files in sample-config/ ...


*** Configuration summary for nagios 4.1.1 08-19-2015 ***:

 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):  /bin/traceroute


Review the options above for accuracy.  If they look okay,
type 'make all' to compile the main program and CGIs.

Now, after configuring we need to Compile and install all the binaries with make command and make install command will install all the needed libraries in your machine and we can proceed further.


make all

make install

Following command will install the init scripts for Nagios.


make install-init

To make nagios work from command line we need to install command-mode.


make install-commandmode

Next, install sample nagios files, please run following command.


make install-config

Now use below command to setup apache configuration for Nagios installation.


make install-webconf

Step 7 : Install Nagios Plugins 

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


[root@server10 opt]# wget https://nagios-plugins.org/download/nagios-plugins-2.1.4.tar.gz


cd /opt
tar -xvzf  nagios-plugins-2.1.4.tar.gz 

Configure Nagios Plugin 

Now compile and install nagios plugins


cd nagios-plugins-2.1.4/

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

make 

make install 

 Copy event handlers directory and change its ownership :
cp -r * /opt/nagios-4.1.1/contrib/eventhandlers /usr/local/nagios/libexec/

 We need to fix permission as well.
 chown nagios:nagios /usr/local/nagios
 chown -R nagios:nagios /usr/local/nagios/libexec 

Step 8 : Configure Apache Authentication 

We need to setup the password for the user nagiosadmin. This username will be used to access the web interface so it is important to remember the password that you will input here. Set the password running the following command and enter the password twice:


[root@server10 opt]# htpasswd -s -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin

Step 9 : Verify Nagios Configuration File 

Now we are all done with Nagios configuration and its time to verify it and to do so please insert following command. If everything goes smooth it will show up similar to below output.


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

Sample 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 30 services.
 Checked 3 hosts.
 Checked 1 host groups.
 Checked 0 service groups.
 Checked 2 contacts.
 Checked 2 contact groups.
 Checked 26 commands.
 Checked 5 time periods.
 Checked 0 host escalations.
 Checked 0 service escalations.
Checking for circular paths...
 Checked 3 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

Step 10 : Start Nagios and Apache Services 

/etc/init.d/nagios start

/etc/init.d/httpd start

Configure Nagios and Apache to start at system startup 


chkconfig httpd on && chkconfig nagios on

chkconfig --add nagios
chkconfig --add nagios
chkconfig --level 35 nagios on
chkconfig --add httpd
chkconfig --level 35 httpd on

Step 11 : Access Nagios in Web Browser 

Your nagios is ready to work, please open it in your browser with “http://Your-server-IP-address/nagios” or “http://FQDN/nagios” and Provide the username “nagiosadmin” and password.

Enter the username as nagiosadmin and its password which we created in the earlier steps.



Nagios Web Dashboard 



Host View 



Services  View 



Process Info 



If you want to access nagios administrative console from a particular IP series

If we want to allow nagios administrative access from 192.168.1.0/24 series only.

$ vi /etc/httpd/conf.d/nagios.conf

# SAMPLE CONFIG SNIPPETS FOR APACHE WEB SERVER
#
# This file contains examples of entries that need
# to be incorporated into your Apache web server
# configuration file.  Customize the paths, etc. as
# needed to fit your system.

ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"

<Directory "/usr/local/nagios/sbin">
#  SSLRequireSSL
   Options ExecCGI
   AllowOverride None
   <IfVersion >= 2.3>
      <RequireAll>
         Require all granted
#        Require host 127.0.0.1

         AuthName "Nagios Access"
         AuthType Basic
         AuthUserFile /usr/local/nagios/etc/htpasswd.users
         Require valid-user
      </RequireAll>
   </IfVersion>
   <IfVersion < 2.3>
      Order allow,deny
#     Allow from all
#     Order deny,allow
#     Deny from all
 Allow from 127.0.0.1 192.168.47.0/24

      AuthName "Nagios Access"
      AuthType Basic
      AuthUserFile /usr/local/nagios/etc/htpasswd.users
      Require valid-user
   </IfVersion>
</Directory>


Note : 

Here if you get Error:
“You don’t have permission to access /nagios/ on this server.”
Check /etc/httpd/conf/httpd.conf for Directory Index.


If it’s not having index.php add it as follows:


$ vi /etc/httpd/conf/httpd.conf

<IfModule dir_module>
    DirectoryIndex index.html index.php index.html.var
</IfModule>

#
# If your host doesn't have a registered DNS name, enter its IP address here.
# You will have to access it by its address anyway, and this will make
# redirections work in a sensible way.
#
ServerName server10:80


For HTTP Warning Error follow the below Steps  :


WARNING  01-26-2017 21:49:06  0d 0h 42m 40s  4/4  HTTP WARNING: HTTP/1.1 403 Forbidden - 5159 bytes in 0.002 second response time 


cd /var/www/html/

touch index.html

Verify the Configuration file again and Restart the Nagios and Apache Service 


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

service nagios restart
service apache restart 


3 comments: