Nagios Installation and Configuration on Centos 6.2

Nagios Installation and Configuration on Centos 6.2

by -
0 1388

What is Nagios ?

Nagios is an Open Source monitoring tool, its provides you monitoring environment to keep an eye on your different machines wheather its window machine or linux machine.

With Nagios, we can monitor remote hosts and their services on a single window. It will show you warnings and indicates if something goes wrong on your servers which eventually helps you to detect problems before they occur. It helps you to reduce downtime and business losses.

Configure RPMForge and EPEL repository:

Download and install rpmforge repository 32 bit:
# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
# rpm -Uvh rpmforge-release-0.5.2-2.el6.rf.i686.rpm

Download and install epel repository 32 bit:
# wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
# rpm -ivh epel-release-6-8.noarch.rpm

If you get below error for epel repository:
“Cannot retrieve metalink for repository: epel. Please verify its path and try again”
then run this command:
# sudo yum upgrade ca-certificates –disablerepo=epel

Different Configuration files used in Nagios:

nagios.cfg: The primary nagios configuration file where lots of global parameters are there. In this file we add path of the newly added linux, windows machine as well as switch or routers. Whatever we like to monitor on nagios we have to add that device file path here.

cgi.cfg: configuration information for nagios web interface.This include path of the primary configuration file called nagios.cfg.This file also contains user information who is authorized to nagios.

timeperiods.cfg: Define the timeperiods. for e.g. if you want a service to be monitored only during the business hours, define a time period called business hours and specify the hours that you would like to monitor. define the timeperiods with time templates. This config file provides you with some example time period definitions that you can reference in host, service, contact, and dependency definitions.

commands.cfg: All the commands to check services are defined here. You can use $HOSTNAME$ and $HOSTADDRESS$ macro on the command execution that will substitute the corresponding hostname or host ip-address automatically. This config file provides you with some example command definitions that you can reference in host, service, and contact definitions.

templates.cfg: Multiple host or service definition that has similar characteristics can use a template, where all the common characteristics can be defined. Use template is a time saver.

localhost.cfg: define the monitoring for local host as sample configuration file.

Printer.cfg: sample configuration file for printer.

Switch.cfg: sample configuration file for switch.

Windows.cfg: sample configuration file for windows machine.

what is NRPE and what nagios-plugins do?

NRPE stands for Nagios Remote Plugin Executor. NRPE allows you to remotely execute Nagios plugins on other Linux/Unix & windows machines. This allows you to monitor remote machine metrics (disk usage, CPU load, webserver usage, database server usage, etc…,).

Nagios Plugins monitor hosts, devices, services, protocols, and applications with Nagios and give the report to NRPE. NRPE send those reports to Nagios server based on Nagios server request. So, Nagios & NRPE can perform all the process only with Nagios-plugins.

Installation on Nagios Server: (192.168.0.160)

These are Required packages to install nagios:

#yum install nagios
#yum install nagios-plugins-all
#yum install nagios–common
#yum install nagios-nrpe
#yum install nagios-plugins
#yum install nagios-devel
#yum install openssl-devel
#yum install nagios-nsca
#yum install nagios-plugins-nrpe
#yum install nagios-nsca-client
Check above packages that they are available on nagios server.

We need to add nrpe service under /etc/services with exact port number and protocol:
# vi /etc/services
nrpe 5666/tcp #nrpe

Edit nrpe configuration file and add entry of nagios server ip:
# vim /etc/nagios/nrpe.cfg
## the nagios monitoring server is permitted ##
## NOTE: There is no space after the comma ##
allowed_hosts=127.0.0.1,192.168.0.160
#service nrpe restart

Check whether the service is listening or not.
# netstat –ntulp | grep nrpe

Now, add user “nagios” on server if not available.
# useradd nagios
# passwd nagios

Nagios configuration: Open cgi.cfg file and replace default nagiosadmin user to nagios user.
# vi /etc/nagios/cgi.cfg
use_authentication=1
authorized_for_system_information=nagios
authorized_for_configuration_information=nagios
authorized_for_system_commands=nagios
authorized_for_all_services=nagios
authorized_for_all_hosts=nagios
authorized_for_all_service_commands=nagios
authorized_for_all_host_commands=nagios
: wq!

Nagios password file: Add user nagios to the htpasswd.users file as follow:
# cd /etc/nagios
# htpasswd –c htpasswd.users nagios
# htpasswd htpasswd.users nagios

Now, copy “localhost.cfg” template as “server.cfg” for monitoring nagios server:
# cd /etc/nagios/objects/
# cp localhost.cfg server.cfg

Open server.cfg file and make entry for hostname, alias and ip of linux pc.This to be done for host, hostgroup and services.
# vim server.cfg
define host{
use                       linux-server
host_name        server
alias                    server
address              192.168.0.160
}

define hostgroup{
hostgroup_name            linux
alias                                   Servers
members                           server
}

define service{
use                                       local-service
host_name                         server
service_description           PING
check_command       check_ping!100.0,20%!500.0,60%
}

(NOTE:change hostname as “server” for rest of services as well)

Verify configuration nagios configuration file for errors:
# nagios –v /etc/nagios/nagios.cfg

If there is no DNS configured then open httpd.conf file and make entry of server as:
# vim /etc/httpd/conf/httpd.conf
ServerName 192.168.0.160:80
: wq!

Open /etc/httpd/conf.d/nagios.conf file and check the “AuthUserFile” location for nagios access:
# vim /etc/httpd/conf.d/nagios.conf
AuthUserFile /etc/nagios/htpasswd.users

Start the following services:
# service httpd start
# chkconfig httpd on
# service nagios start
# chkconfig nagios on
# service nrpe start
# chkconfig nrpe on

Run below command to check whether the nrpe service is working and its listening or not:
#/usr/lib/nagios/pulgins/check_nrpe –H 192.168.0.160

Check the nagios console from web as with user nagios:
http://192.168.0.160/nagios

Check nagios log under:
# tail –f /var/log/nagios/nagios.log

Add Linux machine to nagios server for monitoring:(192.168.0.163)

Install the following packages on client machine:
#yum install nagios-plugins-nrpe
#yum install nagios-nrpe
#yum install openssl-devel

Edit nrpe configuration file and add entry of nagios server ip:
# vim /etc/nagios/nrpe.cfg
## the nagios monitoring server is permitted ##
## NOTE: There is no space after the comma ##
allowed_hosts=127.0.0.1,192.168.0.160

We need t0 add nrpe service under /etc/services with exact port number and protocol:
# vi /etc/services
nrpe 5666/tcp #nrpe
#service nrpe restart

Check whether the service is listening or not.
# netstat –ntulp | grep nrpe

Now, come to nagios server (192.168.0.160) machine:
# cd /etc/nagios/objects/
# cp localhost.cfg linux.cfg
Open linux.cfg file and make entry for hostname, alias and ip of linux pc.This to be done for host, hostgroup and services.
# vim linux.cfg
define host{
use                  linux-server
host_name    labclient1
alias                 labclient1
address            192.168.0.163
}

define hostgroup{
hostgroup_name      labclient
alias                            Linux Servers
members                   labclient1
}

define service{
use                              local-service
host_name                  labclient1
service_description     PING
check_command     check_ping!100.0,20%!500.0,60%
}

(NOTE:change hostname as “labclient1” for rest of services as well)

Now, edit ngios.cfg file and add entry for linux pc.
# vi /etc/nagios/nagios.cfg
cfg_file=/etc/nagios/objects/linux.cfg
:wq!

Verify configuration nagios configuration file for errors:
# nagios –v /etc/nagios/nagios.cfg

Run below command to check whether the nrpe service is working and its listening to client linux pc or not:
#/usr/lib/nagios/pulgins/check_nrpe –H 192.168.0.163

Start the following services on nagios server:
# service httpd start
# service nagios start
# service nrpe start
Now, check the newly added linux pc on nagios monitoring tool.

Add window machine to nagios server for monitoring 🙁 192.168.0.100)

Install NSClient++ package on windows machine. Chose form 32bit or 64bit package.
http://nsclient.org/nscp/downloads

Once downloaded the package run the exe file and enter the allow host ip i.e. nagios server ip (192.168.0.150), NSClient password as “password “and also load the following modules as well:
Enable common check plugins
Enable NSClient server (check_nt)
Enable nrpe server (check_nrpe)
Enable WMI checks

Now start the NSClient++ service by:
Control Panel > Administrative Tools > services > NSClient++ > stop > start

If you want to do changes for NSClient then can edit “nsclient.ini” file to modify the settings whether its for ip address or for password etc.
C:\Program Files\NSClient++\nsclient.ini
After make changes don’t forget to restart the NSClient service.

Now come to the nagios server and do the followings:
Come to nagios server (192.168.0.160) machine:
# cd /etc/nagios/objects/
# vim windows.cfg
Open windows.cfg file and make entry for hostname, alias and ip of window pc.This to be done for host, hostgroup and services.
define host{
use windows-server ; Inherit default values from a template
host_name admin1
alias My Windows Server
address 192.168.0.100 ; IP address of the host
}

Now, check ngios.cfg file and make sure there should be entry for windows pc.
# vi /etc/nagios/nagios.cfg
cfg_file=/etc/nagios/objects/windows.cfg
: wq!

Verify configuration nagios configuration file for errors:
# nagios –v /etc/nagios/nagios.cfg

Run below command to check whether the nrpe service is working and its listening to client windows pc or not:
#/usr/lib/nagios/pulgins/check_nrpe –H 192.168.0.100

Start the following services on nagios server:
# service httpd start
# service nagios start
# service nrpe start
Now, check the newly added windows pc on nagios monitoring tool.

Download PDF

NO COMMENTS

Leave a Reply

Required Captcha *