Sie sind auf Seite 1von 8

Note:- 1.

Set basic configuration of nagios server as


hostname--> nagios.example.com
ip-address--> 192.168.0.154
2. Configure DNS (recomended)
DNS-address--> 192.168.0.154
Step1:- Add epel & rpmforge repository
Step2:- Install all required Packages as
* nagios
* nagios-common
* nagios-nrpe
* nagios-plugins
* nagios-plugins-all
* nagios-devel
* nagios-nsca
* nagios-plugins-nrpe
* nagios-nsca-client
Step3:- Configure Nagios, Its primary configuration file is /etc/nagios/cgi.cfg
# vim /etc/nagios/cgi.cfg
authorized_for_system_information=nagiosadmin
Changed it to
authorized_for_system_information=nagios
authorized_for_configuration_information=nagiosadmin
Changed it to
authorized_for_configuration_information=nagios
authorized_for_system_commands=nagiosadmin
Changed it to
authorized_for_system_commands=nagios
authorized_for_all_services=nagiosadmin
Changed it to
authorized_for_all_services=nagios
authorized_for_all_hosts=nagiosadmin
Changed it to
authorized_for_all_hosts=nagios
authorized_for_all_service_commands=nagiosadmin
Changed it to
authorized_for_all_service_commands=nagios
authorized_for_all_host_commands=nagiosadmin
Changed it to
authorized_for_all_host_commands=nagios

Step4:- Configure web server for nagios, Its configuration file /etc/httpd/conf.d/nagios.conf
ScriptAlias /nagios/cgi-bin "/usr/lib64/nagios/cgi"
<Directory "/usr/lib64/nagios/cgi">
# 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 /etc/nagios/htpasswd.users
Require valid-user
</Directory>
Alias /nagios "/usr/share/nagios"
<Directory "/usr/share/nagios">
# 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 /etc/nagios/htpasswd.users
Require valid-user
</Directory>
Step4:- Set password of user who is authorized for accessing the web portal
# htpasswd -cm /etc/nagios/htpasswd.users nagios
Step5:- Configure information of nagios web Portal, its configuration file /etc/nagios/nagios.conf
# nagios -v /etc/nagios/nagios.conf (To check parameter of configuration file)
# vim /etc/nagios/objects/localhost.cfg (In this file we will define host and services of localhost)
# a) Now first we will define host in this file
define host{
use
linux-server
; This is name of template which is define in /etc/nagios/object/template.cfg it will inherit all
variables which is defined in linux-server class

host_name
localhost
alias
localhost
address
127.0.0.1
}
# b) Now we will define service which will ping the host name 100 packets 20% loss
warning & 500 packets 60% packet loss critical
define service{
use
local-service
; Name of service template to use it is defined
in /etc/nagios/object/template.cfg
host_name
localhost
service_description
PING
check_command
check_ping!100.0,20%!500.0,60% ; This command is
defined in /usr/lib64/nagios/plugins or /usr/lib/nagios/plugins in 32-bit OS. Syntax is define in
/etc/nagios/object/command.cfg file.
}
# c) Now service which check load on disks 20% warning 10% critical
define service{
use
local-service
; Name of service template to use
host_name
localhost
service_description
Root Partition
check_command
check_local_disk!20%!10%!/
}
# d) Service which check login users 20 warning 50 critical
define service{
use
local-service
; Name of service template to use
host_name
localhost
service_description
Current Users
check_command
check_local_users!20!50
}
# e) Service check total running process 250 warning 400 critical
define service{
use
local-service
; Name of service template to use
host_name
localhost
service_description
Total Processes
check_command
check_local_procs!250!400!RSZDT
}
# f) Service check load its format as it shows average load in last 1 5 15 min (as in uptime)
"warning" if load 5.0 in last 1 min 4.0 in last 5 min & 3.0 in last 15 min. "critical" if load is 10.0 in
last 1 min 6.0 in last 5 min 4.0 in last 15 min.

define service{
use
local-service
; Name of service template to use
host_name
localhost
service_description
Current Load
check_command
check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
}
# g) Service check swap warning on 20% free & critical on 10% free
define service{
use
local-service
; Name of service template to use
host_name
localhost
service_description
Swap Usage
check_command
check_local_swap!20!10
}
# h) Service to check ssh, we can use timeout option by -t 20 (in sec)
define service{
use
local-service
; Name of service template to use
host_name
localhost
service_description
SSH
check_command
check_ssh
notifications_enabled
0
}
# i) Service check http
define service{
use
local-service
; Name of service template to use
host_name
localhost
service_description
HTTP
check_command
check_http
notifications_enabled
0
}
# nagios -v /etc/nagios/nagios.conf (To check configuration file)
# service httpd restart; chkconfig httpd on
# service nagios restart; chkconfig nagios on
# tail -f /var/log/nagios/nagios.log
Takes care of firewall
Now launch nagios
# firefox http://nagios.example.com/nagios
username--> nagios
password--> ******
************
************
Now we ready to monitor our localhost for services as ssh, http, swap, disk space, load, process &
ping. Now we will monitor our Linux Server, Windows Machines, Router, Apache Server, Msql

server etc.
But before this we will discuss about configuration files of nagios
1) /etc/nagios/cgi.cfg:- This is main configuration file for nagios which we have already configured
2) /etc/nagios/nagios.conf:- This is configuration for content on web page of nagios. Here details
about some entries
a) log_file=/var/log/nagios/nagios.log
It contain log files of nagios
b) cfg_file=/etc/nagios/objects/commands.cfg
It has all commands which used with nagios with there syntax
c) cfg_file=/etc/nagios/objects/contacts.cfg
It has information of user who can access nagios information
d) cfg_file=/etc/nagios/objects/timeperiods.cfg
It has a timeperiods of monitoring
e) cfg_file=/etc/nagios/objects/templates.cfg
It is default template in which lots of templates are define which we can use for future
purpose according to this template "generic-host" is main class as define then "linux-server" which
inherit "generic-host" properties by "use" command in this templete, we can also define templates
here and can use future
f) cfg_file=/etc/nagios/objects/localhost.cfg
It has information of host & service which will be monitor by nagios as defined above
g) #cfg_file=/etc/nagios/objects/windows.cfg
It is default or sample template to monitor window machine
h) #cfg_file=/etc/nagios/objects/switch.cfg
It is for monitoring switch
i) #cfg_file=/etc/nagios/objects/printer.cfg
It is for monitoring printer
j) object_cache_file=/var/nagios/objects.cache
k) resource_file=/etc/nagios/resource.cfg
This has a path from where all commands is execute which is in /usr/lib64/nagios/plugins
l) status_update_interval=10
m) nagios_user=nagios
n) nagios_group=nagios
***************************
***************************

Now we are going to add other hosts & their services which we want to monitor. We can add
1) Linux hosts
2) Windows host
3) Router
4) Switches
5) Web-server
6) My-Sql server as a hosts.
1) First we will going to add "Linux host & their services" eg. hostname is linuxserver.example.com & address 192.168.0.157
Step1:- On linux-server.example.com Here we need a nagios-nrpe which work as protocol to
interact with nagios server
# yum install nagios-nrpe nagios-plugins-nrpe xinetd
# vim /etc/xinetd.d/nrpe
disable = no
only from = 127.0.0.1 192.168.0.154 <nagios-server-ip>
# service xinetd restart
# chkconfig xinetd on
# vim /etc/services
nrpe 5666/tcp
# NRPE
# netstat -at | grep nrpe
# /usr/lib64/nagios/plugins/check_nrpe -H localhost (to check either nrpe is properly
configured on localhost or not)
Step2:- On nagios.example.com
# rpmquery nagios-nrpe
# /usr/lib64/nagios/plugins/check_nrpe -H 192.168.0.157 <IP-Address-of linuxserver.example.com>
Now create configuration file to monitor linux-server
# cp /etc/nagios/objects/localhost.cfg /etc/nagios/objects/linux-server.cfg
# vim /etc/nagios/object/linux-server.cfg
define host{
use linux-server
(Name of template as defined in
/etc/nagios/objects/template.cfg)
host_name linux-server.example.com (Resolve by DNS, name of linuxserver)
alias linux
(optional)
address
192.168.0.157
}

define service{
use local-service
(Name of service template)
host_name linux-server.example.com
service_description Check ssh on machine
check_command
check_ssh (as command define in
/usr/lib64/nagios/plugins by nagios-plugins-all)
}
# vim /etc/nagios/nagios.cfg
cfg_file=/etc/nagios/objects/linux-server.cfg
# nagios -v /etc/nagios/nagios.cfg
# service nagios restart
# service httpd restart
# firefox http://nagios.example.com/nagios
Same we can add multiple services...
2) Now going to add window server in nagios
Step1:- Install NSClient++ in machine,--> Put nagios server ip while installation
Step2:-Change configuration if required which is in c:\"Program File"\NSClient++\nsclient
port 12489
allow hosts = 192.168.0.154 <Nagios IP>
password = redhat <Which we put during installation & which need during query
from window machine>
Step3:- Now restart the services by administrative tool
Step4:- On nagios server
a) # vim /etc/nagios/objects/command.cfg
search /check_nt (Command to check window then put password as
mentioned on window side as)
command_line $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -s
redhat -v $ARG1$ $ARG2$
b) # vim /etc/nagios/objects/window.cfg
change hostname & ipaddress
c) # vim /etc/nagios/nagios.cfg
config_file=/etc/nagios/objects/window.cfg (either make entry or
uncomment)
d) # nagios -v /etc/nagios/nagios.cfg (To check entry)
f) # /usr/lib64/nagios/plugins/check_nrpe -H 192.168.0.156 <window ip>
f) # service httpd restart; service nagios restart