Sie sind auf Seite 1von 13

NAGIOS-3.2.

EFFECTIVE DATE:11/07/2011

PREPARED BY : Karthikeyan.B

APPROVED BY:

Introduction:
Nagios is a opensource monitoring application used for monitoring systems,servers,routers
and switches in our network.It watches hosts and services, alerting users when thing go wrong and
again when they get better.

Hardware Requirements:
We can install nagios in a normal desktop.Nagios doesn't require higher end
configurations.

Software Requirements:
1) Redhat Linux el5
2) Apache-2.2.19
3) Php-5.3.6
4)gcc, glibc, glibc-common, gd, gd-devel

Dependencies Installation:
Step1:
gcc, glibc, glibc-common, gd, gd-devel is installed default during os installation.If it is
not installed download the rpm and install it using rpm -ivh command.

Step2:(Apache)
cd /usr/local/
Download the apache-2.2.19 source
tar -xvzf apache-2.2.19.tar.gz
cd apache-2.2.19
./configure –prefix=/usr/local/apache2
make
make install
/usr/local/apache2/bin/apachectl start -> starting the service

Step:3(Php)
cd /usr/local
Download the php-5.3.6 source
tar -xvzf php-5.3.6.tar.gz
cd php-5.3.6
./configure –prefix=/usr/local/php –with-apxs2=/usr/local/apache2/bin/apxs --with-gd-
dir=/usr/local/src/gd-2.0.35 --enable-track-vars --with-ttf --enable-gd-imgstrttf --with-png-dir=/usr/li
--with-freetype-dir=/usr/lib --with-fontconfig-dir=/usr/local/src/fontconfig-2.7.3 --with-jpeg-
dir=/usr/lib --with-xpm-dir=/usr/local/src/xpm-3.4k/lib/ --with-zlib-dir=/usr/local/lib/ --enable-ldap
--enable-ssl
make
make install
cp php.ini-production /usr/local/lib/php.ini
change the following lines in /usr/local/lib/php.ini
register_globals=On
short_open_tag=On
display_error=Off
Add the following lines in /usr/local/apache2/conf/httpd.conf
LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
DocumentRoot "/home/httpd"
save and quit the file.
/usr/local/apache2/bin/apachectl restart
To chk running status – Netstat –pan | grep 80
In URL: http://ip/ (should open up Apache home page)
Create user httpd in linux
useradd httpd
cd /home
chown -R httpd:httpd httpd
chmod 777 httpd

Nagios Installation:
Step:1
First we have to create nagios user and group.
useradd nagios
passwd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios -> adding nagios user to nagcmd group
usermod -a -G nagcmd httpd -> adding httpd user to nagcmd group

Step:2
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.3.tar.gz
wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-
1.4.11.tar.gz

tar -xvzf nagios-3.2.3.tar.gz


cd nagios-3.2.3
./configure --prefix=/home/httpd/nagios --with-command-group=nagcmd --with-
apache=/usr/local/apache2
Before making we should edit the Makefile and change apache path from /etc/httpd/conf.d to
/usr/local/apache2/conf
vim Makefile
the following lines should look like this
HTTPD_CONF=/usr/local/apache2/conf/
save &quit the file.
Make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf

Step:3
vim /home/httpd/nagios/etc/objects/contacts.cfg
in this file change the email address to your own email address.From this we can recieve alerts
through email.
/usr/local/apache2/bin/htpasswd -c /home/httpd/nagios/etc/htpasswd.users nagiosadmin
We have to restart the apache
/usr/loca/apache2/bin/apachectl restart

Step:4
tar -xvzf nagios-plugins-1.4.11.tar.gz
cd nagios-plugins-1.4.11
./configure -–prefix=/home/httpd/nagios --with-nagios-user=nagios --with-nagios-group=nagios
make
make install

Step:5
vim /usr/local/apache2/conf/httpd.conf
add the following lines
ScriptAlias /nagios/cgi-bin "/home/httpd/nagios/sbin"
<Directory "/home/httpd/nagios/sbin">
# SSLRequireSSL
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /home/httpd/nagios/etc/htpasswd.users
Require valid-user
</Directory>

Alias /nagios "/home/httpd/nagios/share"


<Directory "/home/httpd/nagios/share">
# SSLRequireSSL
Options None
AllowOverride None
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName “nagios Access"
AuthType Basic
AuthUserFile /home/httpd/nagios/etc/htpasswd.users
Require valid-user
</Directory>
save and quit the file
/usr/local/apache2/bin/apachectl restart
chkconfig nagios on
/home/httpd/nagios/bin/nagios -v /home/httpd/nagios/etc/nagios.cfg
service nagios start
now you can loginto the nagios web interface using http://localhost/nagios

Nrpe:
Nrpe is a plugin it is used to monitor remote linux host and the various services running on the
remotehost.

Installing Nrpe On Remote Host:


Download the Nrpe and Nagios from nagios.org.
Useradd nagios
passwd nagios
Step:1
tar -xvzf nagios-plugins-1.4.11.tar.gz
cd nagios -plugins-1.4.11
export LDFLAGS=-ld1
./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-redhat-pthread-
workaround
make
make install
chown nagios.nagios /usr/local/nagios
chown -R nagios.nagios /usr/local/nagios/libexec

Note:
In Redhat Linux ./configure command was hanging with “Checking for Redhat Spopen
Problem” so use --enable-redhat-pthread-workaround

In RHEL4 we need not to give the command export LDFLAGS=-ld1

Step:2
tar -xvzf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd

Step3:
vim /etc/xinetd.d/nrpe
only from 127.0.0.1 124.7.58.36 -> is a nagios server
save & auit the fle
Add the follwing in /etc/services
/etc/services
nrpe 5666/tcp #nrpe
service xinetd restart
netstat -at | grep nrpe
tcp 0 *:nrpe *:* LISTEN
/usr/local/nagios/etc/libexec/check_nrpe -H <serverip>
NRPE v2.12

Step:4
Installing Nrpe on Nagios server
tar -xvzf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure –prefix=/home/httpd/nagios
make all
make install-plugin
/home/httpd/nagios/libexec/check_nrpe -H 124.7.226.173
checks remote host connection

Creating Host & Service Definition for RemoteHost


There are two types of service monitoring in nagios
server.
1)Monitoring services from Nagios server
2)Monitoring services from remote hosts.
Services To Be Monitored From Nagios Server
1)Ping
2)Http
3) Url Monitoring
Services To Be Monitored From RemoteHost:
1)All Partitions
2)Apache Count
3)Ethernet
4)Server Load
5)Swap Usage
6)Server Memmory

Creating New Host On Nagios Server:


Step:1
First we have to edit the nagios configuration file /home/httpd/nagios/etc/nagios.cfg
uncomment the following line
cfg_dir=/home/httpd/nagios/etc/servers
save and quit the file.
mkdir /home/httpd/nagios/servers
chown nagios.nagios /home/httpd/nagios/etc/servers
chmod 755 /home/httpd/nagios/etc/servers
cp -av /home/httpd/nagios/etc/objects/localhost.cfg /home/httpd/nagios/etc/servers/alphacms.cfg
cp -av /home/httpd/nagios/etc/objects/contacts.cfg /home/httpd/nagios/etc/servers/
chown nagios.nagios /home/httpd/nagios/etc/servers/alphacms.cfg
chown nagios.nagios /home/httpd/nagios/etc/servers/alphacms.cfg
Note:
In this scenario host (124.7.58.41) is used for example.

Edit the file /home/httpd/nagios/etc/servers/alphacms.cfg


The following lines should look like this
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 124.7.58.41

alias 124.7.58.41

address 124.7.58.41

Adding Services To Be Monitored From Nagios Server:


Http:
Note:
Http is monitored by default in nagios.We dont need to add any configuration.Just we have to
check the configuration.
Edit the file /home/httpd/nagios/etc/objects/commands.cfg
The following lines should like this
# 'check_http' command definition

define command{

command_name check_http

command_line $USER1$/check_http -I $HOSTADDRESS$


}

save & quit the file.


Edit the file /home/httpd/nagios/etc/servers/alphacms.cfg
the following lines should look like this
define service{

use generic-service ; Name of service template to use


host_name 124.7.58.41

service_description HTTP

check_command check_http!124.7.58.41

notifications_enabled 0

save & quit the file.

/home/httpd/nagios/bin/nagios -v /home/httpd/nagios/etc/nagios.cfg
service nagios restart
Note:
The above command is used to test the nagios configuration,If there is any error in our
configuration it will displays the error.After adding each service we can check our configuration by
providing this command.

Url Monitoring:
Download the website monitoring scripts from http://exchange.nagios.org/directory/Plugins/
copy the script to /home/httpd/nagios/libexec
chown nagios.nagios /home/httpd/nagios/libexec/check_website_response.sh
Edit the file /home/httpd//nagios/etc/objets/commands.cfg
The following lines should look like this
# 'check_website' command definition

define command{

command_name check_website

command_line $USER1$/check_website_response.sh -w $ARG1$ -c


$ARG2$ -u $ARG3$

save & quit the file.


Edit the file /home/httpd/nagios/etc/objects/alphacms.cfg
The following lines should look like this
define service{
use generic-service ; Name of service template to use

host_name 124.7.58.41

service_description check_website

check_command check_website!1500!2000!alphacms.sify.com

save and quit the file.


service nagios restart
Adding Services To Be Monitored From Remote Host:
Monitoring All Partitions on Remote Host:
In this example host 124.7.58.41 has the following partitions.
/
/boot
/cmsdata
Login to 124.7.58.41
/usr/local/nagios/etc/nrpe.cfg -> This is the main configuration file we have to
specify our commands in this file.
/usr/local/nagios/libexec ->This is path for our all scripts.We have to place our scripts
in this directory.
Note:
Before that verify the partitions using df -h command,Becuase we have to create scripts according
to our partitions.
cd /usr/local/nagios/libexec
cp check_disk check_boot
cp check_boot check_cms
chown nagios.nagios check_boot
chown nagios.nagios check_cms
vim /usr/local/nagios/etc/nrpe.cfg
The Following lines should look like this:
command[check_boot]=/usr/local/nagios/libexec/check_boot -w 30% -c 25% -p
/boot

command[check_disk]=/usr/local/nagios/libexec/check_disk -w 25% -c 20% -p /

command[check_cms]=/usr/local/nagios/libexec/check_cms -w 20% -c 15% -p


/cmsdata

save & quit the file.


service xinetd restart

Nagios Server:
vim /home/httpd/nagios/etc/objects/commands.cfg
the following lines should look like this:
# 'check_nrpe' command definition
define command{

command_name check_nrpe

command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ -t


$ARG2$

save and quit the file.


Vim /home/httpd/nagios/etc/servers/alphacms.cfg
The folowing lines should look like this:
define service{

use local-service ; Name of service template to use

host_name 124.7.58.41

service_description Root Partition

check_command check_nrpe!check_disk!25%!20%!/

define service{

use generic-service ; Name of service template to use


/home/httpd/nagios/libexec/check_nrpe -H 202.144.65.152
host_name 124.7.58.41

service_description Boot Partition

check_command check_nrpe!check_boot!30%!25%!/boot

define service{

use generic-service ; Name of service template to use

host_name 124.7.58.41
service_description Cms Partition

check_command check_nrpe!check_cms!20%!15%!/cmsdata

save and quit the file.


Service nagios restart

Monitoring Swap Partition:


In Remote Host:
vim /usr/local/nagios/etc/nrpe.cfg
The Following lines should look like this:
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 25% -c 20%
save and quit the file.
service xinetd restart.

In Nagios Server:
vim /home/httpd/nagios/etc/servers/alphacms.cfg
The following lines should look like this:
define service{

use generic-service ; Name of service template to use

host_name 124.7.58.41

service_description Swap Usage

check_command check_nrpe!check_swap!20!10

service nagios restart

Monitoring Server Load:


In Remote Host:
vim /usr/local/nagios/etc/nrpe.cfg
The Following lines should look like this:
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20

save and quit the file.

In Nagios Server:
vim /home/httpd/nagios/etc/servers/alphacms.cfg
The following lines should look like this:
define service{
use generic-service ; Name of service template to use

host_name 124.7.58.41

service_description Current Load

check_command check_nrpe!check_load!15,10,5!30,25,20

service nagios restart

Monitoring Server Memmory:


In Remote Host:
vim /usr/local/nagios/etc/nrpe.cfg
The Following lines should look like this:
command[check_mem]=/usr/local/nagios/libexec/check_mem.sh -w 75 -c 80

service nagios restart


service xinetd restart.

In Nagios Server:
vim /home/httpd/nagios/etc/servers/alphacms.cfg
The following lines should look like this:
define service{

use generic-service ; Name of service template to use

host_name 124.7.58.41

service_description check_mem

check_command check_nrpe!check_mem!75!80

notifications_enabled 0

save and quit the file.


service nagios restart

Monitoring Apache Count:


copy the script alert.sh from any one of our server.
Script contents should look like this:
APC=`ps -ef | grep httpd | grep -v grep | wc -l`
if [ $APC -gt 300 ]; then

echo "apache count is $APC"

STATUS="Apache Count-MAX_THRESHOLD"

TV=300

VAL=1

else

echo "Apache Count is ok $APC"

fi

Copy it in to the remote host 124.7.58.41:/usr/local/nagios/libexec


chmod nagios.nagios alert.sh

In Remote Host:
vim /usr/local/nagios/etc/nrpe.cfg
The Following lines should look like this:
command[check_apache]=/usr/local/nagios/libexec/alert.sh

save & quit the file.


service xinetd restart
In Nagios Server:
vim /home/httpd/nagios/etc/servers/alphacms.cfg
The following lines should look like this:
define service{

use generic-service ; Name of service template to use

host_name 124.7.58.41

service_description check_apache

check_command check_nrpe!check_apache!10

notifications_enabled 0

service nagios restart

Monitoring Ethernet:
copy the script errorcheck.sh from any one of our server.
Copy it in to the remote host 124.7.58.41:/usr/local/nagios/libexec
chmod nagios.nagios errorcheck.sh
In Remote Host:
vim /usr/local/nagios/etc/nrpe.cfg
The Following lines should look like this:
command[check_ethernet]=/usr/local/nagios/libexec/errorcheck.sh

save & quit the file


service xinetd restart

In Nagios Server:
vim /home/httpd/nagios/etc/servers/alphacms.cfg
The following lines should look like this:
define service{

use generic-service ; Name of service template to use

host_name 124.7.58.41

service_description check_ethernet

check_command check_nrpe!check_ethernet!30

notifications_enabled 0

save & quit the file.


service nagios restart

Das könnte Ihnen auch gefallen