Professional Documents
Culture Documents
of Nagios
2
Table of Contents
1. Objectives/ Description 1
2. System Requirements 2
2.1 Prerequisites 2
3. Installation Procedure 3
3.1 Create Account Information 3
3.2 Download Nagios and the Plugins 3
3.3 Compile and Install Nagios 3
3.4 Customize Configuration 4
3.5 Configure the Web Interface 4
3.6 Compile and Install the Nagios Plugins 4
3.7 Start Nagios 5
3.8 Login to the Web Interface 5
4. Configuration 6
4.1 Monitoring Routers & Switches: 6
4.1.1 Configuring Nagios 6
4.1.2 Monitoring Packet Loss and RTA 6
4.1.3 Monitoring SNMP Status Information 7
5. List of Commands 9
6. References 10
3
1) Objectives/Description
To setup a system & network monitoring application for monitoring our entire
network smoothly and dynamically. Our chosen application is Nagios.
Nagios is a system and network monitoring application. It watches hosts and services
that we specify, alerting when things go bad and when they get better. Nagios have
many features through which we can easily & smoothly monitor our entire network.
Monitoring of network services (e.g. SMTP, POP3, HTTP, NNTP, PING, etc.)
Monitoring of host resources (e.g. processor load, disk usage, current user
etc.)
Ability to define network host hierarchy using "parent" hosts, allowing
detection of and distinction between hosts that are down and those that are
unreachable
Contact notifications when service or host problems occur and get resolved
(via email, pager, or user-defined method)
Ability to define event handlers to be run during service or host events for
proactive problem resolution
Automatic log file rotation
Support for implementing redundant monitoring hosts
Optional web interface for viewing current network status, notification and
problem history, log file, etc.
4
2) System Requirements
The only requirement of running Nagios is a machine running Linux (or UNIX variant)
and a C compiler. Should have TCP/IP configured, as most service checks will be
performed over the network.
2.1 Prerequisites:
Make sure that we have the following packages installed in our system
Apache
GCC Compiler
GD Development libraries
5
3) Installation Procedure
During portions of the installation we'll need to have root access to the machine.
Then we have to check all the prerequisites packages are installed or not. To check
the packages:
If the packages are not installed then we have to install the packages.
#/usr/sbin/useradd nagios
#passwd nagios
Create a new nagcmd group for allowing external commands to be submitted through
the web interface. Add both the nagios user and the apache user to the group.
#/usr/sbin/groupadd nagcmd
#/usr/sbin/usermod -G nagcmd nagios
#/usr/sbin/usermod -G nagcmd apache
Download the source code tarballs of both Nagios and the Nagios plugins (visit
http://www.nagios.org/download/ for links to the latest versions).
#mkdir ~/downloads
#cd ~/downloads
#cd ~/downloads
#tar xzf nagios-3.0.2.tar.gz
#cd nagios-3.0.2
Run the Nagios configure script, passing the name of the group we have created
earlier like so:
6
3
#./configure --with-command-group=nagcmd
#make
#make all
Install binaries, init scripts, sample config files and set permissions on the external
command directory.
#make install
#make install-init
#make install-commandmode
#make install-config
#vi /usr/local/nagios/etc/objects/contacts.cfg
Install the Nagios web config file in the Apache conf.d directory.
#make install-webconf
Create a nagiosadmin account for logging into the Nagios web interface and assign a
password to it.
#cd /usr/local/nagios
#cd sbin/
#vi .htaccess
#cd ..
7
# cd share/
#vi .htaccess
#cd ~/downloads
#tar xzf nagios-plugins-1.4.11.tar.gz
#cd nagios-plugins-1.4.11
Add Nagios to the list of system services and have it automatically start when the
system boots.
8
#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
We should now be able to access the Nagios web interface at the URL below. We'll be
prompted for the username (nagiosadmin) and password we specified earlier.
http://localhost/nagios/
Make sure the machine's firewall rules are configured to allow access to the web
server if we want to access the Nagios interface remotely.
4) Configuration
Once we get Nagios installed and running properly, we’ll no doubt want to start
monitoring more than just our local machine. So we need to configure some
configuration files for monitoring Windows/Linux machines, Routers/Switches,
Network Printers & publicly available service (HTTP, FTP, SSH etc).
/usr/local/nagios/etc/cgi.cfg
/usr/local/nagios/etc/nagios.cfg
/usr/local/nagios/etc/resource.cfg
To monitor a network switch/ router we need to edit the main nagios config file
#vi /usr/share/nagios/etc/nagios.cfg
Remove the leading pound (#) sign from the following line in the main configuration
file:
#cfg_file=/usr/local/nagios/etc/objects/switch.cfg
#vi /usr/local/nagios/etc/objects/switch.cfg
Add a new host definition for the switch that we're going to monitor. A sample host
definition is already in switch.cfg. Change the host_name, alias, and address fields to
appropriate values for the switch.
9
define host {
use generic-switch ; Inherit default values from
template
host_name DHK31_EDGE_SW ; The name we're giving to the switch
Alias DHK31_EDGE_SW ; A longer name associated with switch
address 172.30.0.9 ; IP address of the switch
hostgroups EDGE_SW ; Host groups this switch is
associated with
}
Now we can add some service definitions (to the same configuration file) to monitor
different aspects of the switch.
Add the following service definition in order to monitor packet loss and round trip
average between the Nagios host and the switch every 5 minutes under normal
conditions.
define service{
use generic-service ; Inherit values from a
template
host_name DHK31_EDGE_SW ; The name of the host the
service is associated with
service_description PING ; The service description
check_command check_ping!200.0,20%!600.0,60% ; The
command used to monitor the service
normal_check_interval 5 ; Check the service every 5
minutes under normal conditions
retry_check_interval 1 ; Re-check the service every
minute until its final/hard state is determined
}
CRITICAL if the round trip average (RTA) is greater than 600 milliseconds or
the packet loss is 60% or more.
WARNING if the RTA is greater than 200 ms or the packet loss is 20% or
more.
OK if the RTA is less than 200 ms and the packet loss is less than 20%.
If the switch or router supports SNMP, we can monitor a lot of information by using
the check_snmp plugin. Add the following service definition to monitor the uptime of
the switch.
define service{
use generic-service ;Inherit values from
template
host_name DHK31_EDGE_SW
service_description Uptime
check_command check_snmp!-C public -o sysUpTime.0
}
10
In the check_command directive of the service definition above, the "-C public" tells
the plugin that the SNMP community name to be used is "public" and the "-o
sysUpTime.0" indicates which OID should be checked.
define service{
use generic-service ; Inherit values from a
template
host_name DHK31_EDGE_SW
service_description Port 1 Link Status
check_command check_snmp!-C public -o ifOperStatus.1 -r
1 -m RFC1213-MIB
}
In the example above, the "-o ifOperStatus.1" refers to the OID for the operational
status of port 1 on the switch. The "-r 1" option tells the check_snmp plugin to return
an OK state if "1" is found in the SNMP result (1 indicates an "up" state on the port)
and CRITICAL if it isn't found. The "-m RFC1213-MIB" is optional and tells the
check_snmp plugin to only load the "RFC1213-MIB" instead of every single MIB that's
installed on your system, which can help speed things up.
Once we've added the new host and service definitions to the switch.cfg file, we're
ready to start monitoring the router/switch. To do this, we'll need to verify our
configuration and restart nagios.
In order to verify your configuration, run Nagios with the -v command line option like
so:
#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
#/etc/rc.d/init.d/nagios reload
Or
#service nagios restart
11
8
5) List of Commands
#rpm –qa | grep httpd
#rpm –qa | grep gcc
#rpm –qa | grep gd
#rpm –qa | grep glibc
#rpm –Uvh httpd-*
#rpm –Uvh gcc-*
#rpm –Uvh gd-*
#rpm –Uvh glibc-*
#/usr/sbin/useradd nagios
#passwd nagios
#/usr/sbin/groupadd nagcmd
#/usr/sbin/usermod -G nagcmd nagios
#/usr/sbin/usermod -G nagcmd apache
Download the source code tarballs of both Nagios and the Nagios plugins (visit
http://www.nagios.org/download/ for links to the latest versions) and put them in a
directory named downloads.
#mkdir ~/downloads
#cd ~/downloads
#tar xzf nagios-3.0.2.tar.gz
#cd nagios-3.0.2
#./configure --with-command-group=nagcmd
#make
#make all
#make install
#make install-init
#make install-config
#make install-commandmode
#vi /usr/local/nagios/etc/objects/contacts.cfg
#make install-webconf
#htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
#service httpd restart
#cd ~/downloads
#tar xzf nagios-plugins-1.4.11.tar.gz
#cd nagios-plugins-1.4.11
#./configure --with-nagios-user=nagios --with-nagios-group=nagios
12
#make
#make install
#chkconfig --add nagios
#chkconfig nagios on
#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
#service nagios start
9
6) References
http://www.nagios.org/
http://www.nagios.org/docs/
http://www.nagios.org/download/
http://www.nagiosbook.org/
http://oss.isg.inf.ethz.ch/nagiosplug/
http://en.wikipedia.org/wiki/Nagios
13
10
14