by Wayne E Goodrich (Outlaw)
(Transferred from the wiki by Peter)

Introduction

If you manage a network of any size, you want to be notified of problems before your customers or your bosses find out, but you don't want to be tied to a console checking for the availability of hosts and services. This is where Nagios shines. If you put in the time it takes to install and customize Nagios for your environment, you'll be rewarded with a superb monitoring and notification solution that happens to be free. In this PET, I will guide you through the installation and configuration of Nagios, and I will provide examples of customizations you can add using plugins you can write yourself.
Gather up our packages

I will use Redhat Enterprise Linux AS 4.0 in these examples, but they can be adapted for any Linux distribution. The following are required packages for HTTPD services that will drive Nagios's web interface:



Apache


Code:
httpd 
httpd-suexec 
apr-util
Optional (for secure sockets layer, HTTPS interface)
Code:
mod_ssl
If you selected the default package set during installation, these are already installed. If you opted not to make Apache available during Redhat install, you can grab the packages from RHN using up2date or by manually downloading them.
The following are needed for Nagios basic functionality, really it's the Nagios framework we get. Nagios's checks are accomplished entirely through the use of plugins, which are available in a separate package. From here on out, I will suggest getting prebuilt packages from Dag Wieers's collection, and occasionally from CPAN. To make it easier on yourself, add Dag's repositories if you use YUM.



Nagios

nagios-2.2-1.el4.rf.i386.rpm http://dag.wieers.com/packages/nagios/
The following are needed for Nagios to actually perform checks



Nagios Plugins

nagios-plugins-1.4.1-1.2.el4.rf.i386.rpm http://dag.wieers.com/packages/nagios-plugins/
fping-2.4-1.b2.2.el4.rf.i386.rpm http://dag.wieers.com/packages/fping/
perl-Crypt-DES-2.03-3.2.el4.rf.i386.rpm http://dag.wieers.com/packages/perl-Crypt-DES/
perl-Net-SNMP-5.0.1-1.2.el4.rf.noarch.rpm http://dag.wieers.com/packages/perl-Net-SNMP/
perl-IO-Socket-INET6-2.51-1.2.el4.rf.noarch.rpm http://dag.wieers.com/packages/perl-IO-Socket-INET6/
Digest-HMAC-1.01.tar.gz http://search.cpan.org/~gaas/Digest-HMAC-1.01/lib/Digest/HMAC.pm
Digest-SHA1-2.11.tar.gz http://search.cpan.org/~gaas/Digest-SHA1-2.11/SHA1.pm
Install Necessary Packages

We can begin installation of the packages by first installing Nagios:
Code:
rpm -ivh nagios-2.2-1.el4.rf.i386.rpm
Now we begin satisfying nagios-plugins dependencies:
Code:
rpm -ivh fping-2.4-1.b2.2.el4.rf.i386.rpm
rpm -ivh perl-Crypt-DES-2.03-3.2.el4.rf.i386.rpm
mkdir /tmp/perltmp
cp *gz /tmp/perltmp
cd /tmp/perltmp
find . -name "*gz" -exec tar xvzf {} \;
cd Digest-SHA1-2.11
perl Makefile.pl
make test
make install
cd ../Digest-HMAC-1.01
 perl Makefile.pl
make test
make install
cd ../Socket6-0.19
perl Makefile.pl
make test
make install
These next two Dag perl packages expect SHA1, HMAC and Socket6 to be available as rpms, but since they were not, we have to tell rpm not to check dependencies.
Code:
rpm -ivh --nodeps perl-Net-SNMP-5.0.1-1.2.el4.rf.noarch.rpm
rpm -ivh --nodeps perl-IO-Socket-INET6-2.51-1.2.el4.rf.noarch.rpm
rpm -ivh nagios-plugins-1.4.1-1.2.el4.rf.i386.rpm
Begin Configuration

Nagios has two methods for arranging its configuration files. One way relies on a single file where you specify hosts, groups, services etc. The other allows you to split these files up by purpose for ease of administration. The single file method can become unwieldy as you add machines and services to monitor. Here, we'll assume the multiple definition file method.
Configure The Nagios Service

Let's become familiar with the file locations that the Dag provided packages use as defaults:



Main Nagios Configs
Code:
/etc/nagios
Plugins and CGIs
Code:
/usr/lib/nagios
Nagios Web Files
Code:
/usr/share/nagios
Here, we see the example config files in /etc/nagios:
Code:
[radar@test2 ~]$ ls -lh /etc/nagios
total 160K
-rw-rw-r--  1 root root  30K Apr  8 08:28 bigger.cfg
-rw-rw-r--  1 root root 9.4K Apr  8 08:28 cgi.cfg
-rw-rw-r--  1 root root 4.8K Apr  8 08:28 checkcommands.cfg
-rw-r--r--  1 root root  16K Aug  5  2005 command-plugins.cfg
-rw-rw-r--  1 root root  14K Apr  8 08:28 minimal.cfg
-rw-rw-r--  1 root root 4.2K Apr  8 08:28 misccommands.cfg
-rw-rw-r--  1 root root  30K Apr  8 08:28 nagios.cfg
-rw-rw----  1 root root 1.3K Apr  8 08:28 resource.cfg
The first file we're interested in is nagios.cfg, the main config file. This file specifies, among other things, the object config (definition) files. Those are what we are most interested in at this point. We want to open /etc/nagios/nagios.cfg in an editor and comment out the line that contains minimal.cfg. Then we'll uncomment the lines containing the object config files that we'll need to create, and populate with our definitions. Let's go ahead and do that, then.

Code:
# You can split other types of object definitions across several
# config files if you wish (as done here), or keep them all in a
# single config file.

#cfg_file=/etc/nagios/minimal.cfg
Here, I have commented out minimal.cfg
Code:
cfg_file=/etc/nagios/contactgroups.cfg
cfg_file=/etc/nagios/contacts.cfg
#cfg_file=/etc/nagios/dependencies.cfg
#cfg_file=/etc/nagios/escalations.cfg
cfg_file=/etc/nagios/hostgroups.cfg
cfg_file=/etc/nagios/hosts.cfg
cfg_file=/etc/nagios/services.cfg
cfg_file=/etc/nagios/timeperiods.cfg
And here I have uncommented the object config files we will work with first, to get basic functionality. We will now create these and populate them with some hosts, services, groups, etc.


While we're at it we want to enable service commands in the CGIs, and enable flap detection: