Download as odt, pdf, or txt
Download as odt, pdf, or txt
You are on page 1of 12

Nagios Server Configuration

1) wget http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
2) rpm ivh epel-release-5-4.noarch.rpm
3) yum install -y wget httpd php gcc glibc glibc-common gd gd-devel make net-snmp
4) Download NAGIOS CORE Server Software
5) wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.6.tar.gz
6) tar xvf nagios-4.0.6.tar.gz
7) cd nagios-4.0.6
8) useradd nagios
9) passwd nagios
10)
groupadd nagcmd
11)
usermod -a -G nagcmd nagios
12)
./configure --with-command-group=nagcmd
13)
make all
14)
make install
15)
make install-init
16)
make install-config
17)
make install-commandmode
18)
make install-webconf
19)
cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
20)
chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
21)
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
22)
/etc/init.d/nagios restart
23)
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Add bellow code in following file :vi /usr/local/nagios/etc/objects/commands.cfg


define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

Install Nagios Plugins


1) Download Nagios Plugin
2) wget http://nagios-plugins.org/download/nagios-plugins-2.0.2.tar.gz
3) tar xvf nagios-plugins-2.0.2.tar.gz
4) cd nagios-plugins-2.0.2
5) ./configure --with-nagios-user=nagios --with-nagios-group=nagios
6) Make
7) Make install
8) chkconfig --add nagios
9) chkconfig --level 35 nagios on
10)
chkconfig --add httpd
11)
chkconfig --level 35 httpd on
12)
/etc/init.d/nagios restart
13)
/etc/init.d/httpd restart

Install Nrpe on nagios server:1) yum install openssl.


2) wget http://osdn.dl.sourceforge.net/sourceforge/nagios/nrpe-2.8.tar.gz
tar xzf nrpe-2.8.tar.gz
cd nrpe-2.8

Compile the NRPE addon.


./configure
make all

Install the NRPE plugin (for testing), daemon, and sample daemon config file.
make install-plugin
make install-daemon
make install-daemon-config

Install the NRPE daemon as a service under xinetd.


make install-xinetd

Edit the /etc/xinetd.d/nrpe file and add the IP address of the monitoring server to the only_from directive.

only_from = 127.0.0.1, <nagios_ip_address>

Add the following entry for the NRPE daemon to the /etc/services file.
nrpe 5666/tcp # NRPE

Restart the xinetd service.


service xinetd restart

Make sure the nrpe daemon is running under xinetd.


netstat -at | grep nrpe

The output out above command should show something like this:
tcp 0 0 *:nrpe *:* LISTEN

If it does, great! If it doesn't, make sure of the following:


You added the nrpe entry to your /etc/services file
The only_from directive in the /etc/xinetd.d/nrpe file contains an entry for "127.0.0.1"
xinetd is installed and started
Check the system log files for references about xinetd or nrpe and fix any problems that are reported

Next, check to make sure the NRPE daemon is functioning properly. To do this, run the check_nrpe plugin that was
installed
for testing purposes.
/usr/local/nagios/libexec/check_nrpe -H localhost

You should get a string back that tells you what version of NRPE is installed, like this:
NRPE v2.8

On nagios server,after installtion of nrpe ,nrep service is not created default ,you need to create it with usign
below steps
cd /root/nrpe-2.12
cp init-script /etc/init.d/nrpe
chmod 777 /etc/init.d/nrpe
/etc/init.d/nrep restart

Login to Nagios webconsole with using below url


http://10.20.41.250/nagios/
username :-nagiosadmin
password :- which you have set to user nagiosadmin.for eg:-trimax

Configure nrpe and nagios-plugins on Client server


Install nrpe on Client Server
3) wget http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
4) rpm ivh epel-release-5-4.noarch.rpm

5) yum install -y nrpe openssl


6) cd /etc/nagios/
7) cp -p nrpe.cfg nrpe.cfg.orig (take backup of nrpe.cfg file)
8) Configure nrpe
9) Add the nagios server ip in allowed_hosts as edited in given below nrpe.cfg file.
10)
vi /etc/nagios/nrpe.cfg

log_facility=daemon
pid_file=/var/run/nrpe/nrpe.pid
server_port=5666
nrpe_user=nrpe
nrpe_group=nrpe
allowed_hosts=192.168.10.50 (Nagios server ip address)
dont_blame_nrpe=0
debug=0

command_timeout=60
connection_timeout=300
include_dir=/etc/nrpe.d/
Defult :command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1 (Enter here / partition device name for eg:
/dev/had1)
command[check_zombie_procs]=/usr/lib/nagios/plugins/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/lib/nagios/plugins/check_procs -w 150 -c 200
change to :-

command[check_users]=/usr/lib/nagios/plugins/check_users -w 80 -c 90
command[check_http]=/usr/lib/nagios/plugins/check_http -H 127.0.0.1 -w 2 -c 1
command[check_ssh]=/usr/lib/nagios/plugins/check_ssh -t 30 -H 10.20.41.250
command[check_swap]=/usr/lib/nagios/plugins/check_swap -w 20% -c 10%
command[check_load]=/usr/lib/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_disk]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda2
command[check_procs]=/usr/lib/nagios/plugins/check_procs -w 190 -c 220
command[check_ping]=/usr/lib/nagios/plugins/check_ping -H 10.20.41.250 -w 100.0,25% -c 300.0,75% -p 1
NOTE:-1).when you install Nagios plugines through YUM command then nagios plugines install at path
/usr/lib/nagios/plugins/ on 32 bit os ,on 64 bit os /usr/lib64/nagios/plugins/
2). when you install Nagios pluginess through source means download nagios plugine and install ,then that
time Nagios plugines install at path /usr/local/nagios/libexec
11)

/etc/init.d/nrpe restart

2) Install Nagios Plugins on Client Server


12)

useradd nagios

13)
14)
15)
16)
17)
18)
19)
20)
21)
22)
23)
24)

passwd nagios
Download Nagios Plugin
wget http://nagios-plugins.org/download/nagios-plugins-2.0.2.tar.gz
tar xvf nagios-plugins-2.0.2.tar.gz
cd nagios-plugins-2.0.2
./configure --with-nagios-user=nagios --with-nagios-group=nagios
Make
Make install

chown nagios.nagios /usr/local/nagios


chown -R nagios.nagios /usr/local/nagios/libexec
yum install xinetd
service xinetd restart

Do below thing on Nagios server


1)
2)
3)
4)

Create server configure file on Nagios Server


cd /usr/local/nagios/etc/objects/
cp localhost.cfg GLPI_Server.cfg
vi GLPI_Server.cfg

Note:1.you need to replace localhost by server name in below file.


2.At point define host.you need to replace localhost ip address 127.0.0.1 by server ip address for eg:192.168.10.21 where nagios client is installed.
3.You need to replace hostgroup_name linux-servers, when you go to install the other server you need to change
hostgroup name linux-servers1,linux-server2 etc.
4.you need to replace members

localhost change to members

5. you need to replace use local-service change to use

kaushik_server(hostname of client server).

generic-service.

6.You need to replace check_command check_local_disk!20%!10% / change to check_command check_nrpe!


check_disk
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------##########################################################################
#####
# LOCALHOST.CFG - SAMPLE OBJECT CONFIG FILE FOR MONITORING THIS MACHINE

#
#
# NOTE: This config file is intended to serve as an *extremely* simple
#
example of how you can create configuration entries to monitor
#
the local (Linux) machine.
#
############################################################################
###
############################################################################
###
# HOST DEFINITION
############################################################################
###
############################################################################
###
# Define a host for the local machine
define host{
use

linux-server

; Name of host template to use


; This host definition will inherit all variables that are defined
; in (or inherited by) the linux-server host template definition.

host_name
GLPI_Server
alias
GLPI_Server
address
192.168.10.21
}
############################################################################
##
############################################################################
##
# HOST GROUP DEFINITION
############################################################################
##
############################################################################
##
# Define an optional hostgroup for Linux machines
define hostgroup{
hostgroup_name
linux-servers
The name of the hostgroup
alias
Linux Servers
; Long name of the group
members
kaushik_server Comma separated list of hosts that belong to this group
}
##########################################################################

############################################################################
#
# SERVICE DEFINITIONS
############################################################################
##
############################################################################
##
# Define a service to "ping" the local machine
define service{
use
generic-service
; Name of service template to use
host_name
GLPI_Server
service_description
PING
check_command
check_nrpe!check_ping
}

2) Configure nagios.cfg file on Nagios Server.


1) Add this server configure file (cfg_file=/usr/local/nagios/etc/objects/GLPI_Server.cfg)
2) vi /usr/local/nagios/etc/nagios.cfg
--------------------------------------------------------------------------------------# You can also tell Nagios to process all config files (with a .cfg
# extension) in a particular directory by using the cfg_dir
# directive as shown below:
#cfg_dir=/usr/local/nagios/etc/servers
#cfg_dir=/usr/local/nagios/etc/printers
#cfg_dir=/usr/local/nagios/etc/switches
#cfg_dir=/usr/local/nagios/etc/routers
cfg_file=/usr/local/nagios/etc/objects/GLPI_Server.cfg

To work email.need to start the SMTP service on Nagios server.


---------------------------------------------------------------------------------------1).install sendmail as below
#yum install sendmail
2).After successful installation of sendmail.restart the sendmail server as below
#/etc/init.d/sendmail start
3).After starting Sendmail check SMTP port 25 is opened on nagios server or not with below command.
#namp localhost
output :-----------------------------PORT
STATE SERVICE
22/tcp
open
ssh
25/tcp open
smtp
80/tcp
open
http
111/tcp open
rpcbind
--------------------------------

Mail Configure for sending Critical and warning Alert.


/etc/init.d/sendmail restart
Add Email id in bellow .cfg file
vi /usr/local/nagios/etc/objects/contacts.cfg
##############################################################################
#
##############################################################################
#
#
# 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
use
alias

nagiosadmin
generic-contact
Nagios Admin

email
}

; Short name of user


; Inherit default values from generic-contact template (defined above)
; Full name of user

amit.zepale@gmail.com ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******

##############################################################################
#

/etc/init.d/nagios restart

you will get mail in the below format


---------------------------------------------------------------------------------------------From: nagios@unique.dhanaji.com [nagios@unique.dhanaji.com]
Sent: Friday, June 06, 2014 8:44 PM
To: Dhanaji Katkar
Subject: ** PROBLEM Service Alert: localhost/Root Partition is CRITICAL **
***** Nagios *****
Notification Type: PROBLEM
Service: Root Partition

Host: localhost
Address: 127.0.0.1
State: CRITICAL
Date/Time: Fri Jun 6 11:14:17 EDT 2014
Additional Info:
DISK CRITICAL - free space: / 23295 MB (5% inode=94%):
-------------------------------------------------------------------------------------------While Reseduling/Refteshing any service if you get the Below error
----------------------------------------------------------------------------------------Error: Could not open command file '/usr/local/nagios/var/rw/nagios.cmd' for update!
The permissions on the external command file and/or directory may be incorrect. Read the FAQs on how to setup proper
permissions.
An error occurred while attempting to commit your command for processing.
Return from whence you came

Soution is Below
Go to the below path on Nagios server
#/usr/local/nagios/var/rw/
Change the permission of nagios.cmd file as below
#chmod 777 nagios.cmd

If you get Below error while monitoring the HTTP service.


When you newly setup the nagios server I mostly get this warning error HTTP WARNING: HTTP/1.1 403 Forbidden.
Solution:-------------i).To solve this alert, create a index.html file inside /var/www/html in server
touch /var/www/html/index.html
ii).Then Restart the httpd and nagios service. Even without doing this it will clear the alert after a few minutes
On Nagios server :/etc/init.d/nagios restart
/etc/init.d/httpd restart
On Remote Agent server :/etc/init.d/nrpe restart
/etc/init.d/httpd restart

You might also like