Nagios Installation and Configuration (Part 1)

What is Nagios ?

Nagios is a host and service monitor designed to inform you of network problems before your clients, end-users or managers do. It has been designed to run under the Linux operating system, but works fine under most *NIX variants as well. The monitoring daemon runs intermittent checks on hosts and services you specify using external "plugins" which return status information to Nagios. When problems are encountered, the daemon can send notifications out to administrative contacts in a variety of different ways (email, instant message, SMS, etc.). Current status information, historical logs, and reports can all be accessed via a web browser.


Nagios Features


Nagios has a lot of features, making it a very powerful monitoring tool. Some of the major features are listed below:
  • Monitoring of network services (SMTP, POP3, HTTP, NNTP, PING, etc.)
  • Monitoring of host resources (processor load, disk and memory usage, running processes, log files, etc.)
  • Monitoring of environmental factors such as temperature
  • Simple plugin design that allows users to easily develop their own host and service checks
  • Ability to define network host hierarchy, 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 other user-defined method)
  • Optional escalation of host and service notifications to different contact groups
  • Ability to define event handlers to be run during service or host events for proactive problem resolution
  • Support for implementing redundant and distributed monitoring servers
  • External command interface that allows on-the-fly modifications to be made to the monitoring and notification
  • behavior through the use of event handlers, the web interface, and third-party applications
  • Retention of host and service status across program restarts
  • Scheduled downtime for suppressing host and service notifications during periods of planned outages
  • Ability to acknowledge problems via the web interface.
  • Web interface for viewing current network status, notification and problem history, log file, etc.
  • Simple authorization scheme that allows you restrict what users can see and do from the web interface

Nagios Requirements

The only requirement of running Nagios is a machine running Linux (or UNIX variant) and a C compiler. You will probably also want to have TCP/IP configured, as most service checks will be performed over the network.

You are not required to use the CGIs included with Nagios. However, if you do decide to use them, you will need to have the following software installed.

A web server (preferrably Apache)

Thomas Boutell's gd library version 1.6.3 or higher (required by the statusmap and trends CGIs)


Download Nagios

http://www.nagios.org/download/

Nagios Documentation

http://www.nagios.org/docs/

Nagios Screenshots

http://www.nagios.org/about/screenshots.php

Nagios FAQ

http://www.nagios.org/faqs/



Installing Nagios
 


Prerequisites


The below packages are very important to install on your system to complete the nagios installation without any problem


#yum install make gcc g++  (Online Installation)


or Download the Packages and use rpm command to install on Redhat, Suse and apt-get command on Debian.

Create Nagios User/Group

You're probably going to want to run Nagios under a normal user account, so add a new user (and group) to your system with the following command (this will vary depending on what OS you're running):

#useradd nagios

This should create the user account and a default group with the same name (nagios). This can be checked by

# grep nagios /etc/passwd

This should show the group (if created) with the members.

If the group is missing then create the group by,

# groupadd nagios

This group can be used as the group that  Nagios uses as a Command group.
Now download Nagios and Nagios-Plugins

[root@p-root]# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.1.tar.gz
[root@p-root]# wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.11.tar.gz
[root@p-root]# tar –zxvf nagios-3.2.1.tar.gz

Identify Web Server User

You're probably going to want to issue external commands (like acknowledgments and scheduled downtime) from the web interface. To do so, you need to identify the user your web server runs as (typically apache, although this may differ on your system). This setting is found in your web server configuration file. The following command can be used to quickly determine what user Apache is running as (paths may differ on your system):

# grep "^User" /etc/httpd/http.conf

Add Webserver user (www-data/apache) and Nagios user (nagios)

# usermod -G nagios nagios

#usermod -G www-data,nagios www-data

Check if the users are the members of the group by

# grep nagios /etc/group

Create Installation Directory

Create the base directory where you would like to install Nagios as follows

#mkdir /usr/local/nagios

Change the owner of the base installtion directory to be the Nagios user and group you added earlier as follows:

#chown -R nagios:nagios /usr/local/nagios

Prior to that, it is imporant to install the GD-Utils for the Status Maps to work properly.

In Redhat, the following should install the required libraries:

# yum install libgd2-xpm libgd2-xpm-dev libgd2 libgd2-dev libpng12-dev libjpeg62-dev libgd-tools libpng3-dev
[root@p-root]# cd /usr/local/nagios
[root@p-root]# ./configure – -with-command-group=nagios
[root@p-root]# make all
[root@p-root]# make install
[root@p-root]# make install-init
[root@p-root]# make install-config
[root@p-root]# make install-commandmode
[root@p-root]# make install-webconf
(it will create nagios web config file in apache conf.d direcotry)

This will complete the installation Now we need to know the Directory Structure and File locations

#cd /usr/local/nagios

You should see five different subdirectories. A brief description of what each directory contains is given below.

Sub-Directory Contents

bin/ Nagios core program
etc/ Main, resource, object, and CGI configuration files should be put here
sbin/ CGIs
share/ HTML files (for web interface and online documentation)
var/ Empty directory for the log file, status file, retention file, etc.
var/archives Empty directory for the archived logs
var/rw Empty directory for the external command file

Now one thing you need to concentrate is /usr/local/nagios/etc directory where all the sample configuration files stores.

cgi.cfg-sample    nagios.cfg-sample bigger.cfg-sample   misccommands.cfg-sample  checkcommands.cfg-sample  minimal.cfg-sample  resource.cfg-sample

The above are the sample configuration files you need to rename those files to .cfg files i am showing here one example you need to do for the other files

# mv bigger.cfg-sample bigger.cfg

Important Note :- In nagios 2.x(For nagios 1.x versions it creats at the time of installation) hosts.cfg,services.cfg,commands.cfg and other configuration files are not crteated by default we need to create these files using the existing sample files like bigger.cfg and minimal.cfg and other files

We will see more about these file in Configuration section

Now, you have a completely installed nagios to work on. The next steps would be to install the plugins and start configuring Nagios.

Now create nagiosadmin account for nagios web interface.

[root@p-root]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Password:
[root@p-root]# /etc/init.d/httpd restart

Now install nagios-plugin.

[root@p-root]# tar –zxvf nagios-plugins-1.4.11.tar.gz
[root@p-root]# cd nagios-plugins-1.4.11
[root@p-root]# ./configure –with-nagios-user=nagios –with-nagio-group=nagios
[root@p-root]# make
[root@p-root]# make install

Now the complete Nagios Directory structure

bin/ Nagios core program
etc/ Main, resource, object, and CGI configuration files should be put here
sbin/ CGIs
share/ HTML files (for web interface and online documentation)
var/ Empty directory for the log file, status file, retention file, etc.
var/archives Empty directory for the archived logs
var/rw Empty directory for the external command file
libexec/ nagios plugins available in this
Now Basic installation of nagios completed.Now you need to configure the web interface for nagios.

Configure the Web interface For Nagios in Debian

Find how to setup the web-interface and configure the user authentication for nagios. This article also describes how to force teh CGIs to use Authentication.

Once Nagios and the plugins are installed. It's time to create the front end web interface for nagios. For this, you need to configure the Alias for the web interface and the script alias for the CGIs on your webserver.

In Debian with Apache2 you can do this by the following:

Create the config file for nagios in Apache

Creating the config file nagios (or in any name that you want the alias to called as) in the /etc/apache2/sites-available/ with the following contents (copy & paste using VI):

ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin

<Directory "/usr/local/nagios/sbin">
   Options ExecCGI
   AllowOverride None
   Order allow,deny
   Allow from all
   AuthName "Nagios Access"
   AuthType Basic
   AuthUserFile /usr/local/nagios/etc/htpasswd.users
   Require valid-user
</Directory>

Alias /nagios /usr/local/nagios/share

<Directory "/usr/local/nagios/share">
   Options None
   AllowOverride None
   Order allow,deny
   Allow from all
   AuthName "Nagios Access"
   AuthType Basic
   AuthUserFile /usr/local/nagios/etc/htpasswd.users
   Require valid-user
</Directory>
Now you have installed all the required packages and services.

Now start nagios.

[root@p-root]# chkconfig –add nagios
[root@p-root]# chkconfig nagios on

Verify your nagios config file.

[root@p-root]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

If there is no error it means your nagios configuration is correct and you can start nagios service.

[root@p-root]# /etc/init.d/nagios start

Now access your nagios web interface :-

http://localhost/nagios



NRPE Installation and Configuration.
Download and Install NRPE
Extract the Files:
[root@p-root~]# tar -xzf nrpe-2.12.tar.gz
[root@p-root~]# cd nrpe-2.12
Compile and Configure NRPE
You need the openssl-devel package installed to compile NRPE with ssl support. So make sure that open ssl is already installed on the server.
Install NRPE:
[root@p-root~]# ./configure
General Options:
————————-
NRPE port: 5666
NRPE user: nagios
NRPE group: nagios
Nagios user: nagios
Nagios group: nagios
[root@p-root~]# make all
[root@p-root~]# make install-plugin
[root@p-root~]# make install-daemon
[root@p-root~]# make install-daemon-config
[root@p-root~]# make install-xinetd
Post NRPE Configuration
Edit Xinetd NRPE entry:
Add Nagios Monitoring server to the “only_from” directive
[root@p-root~]# vi /etc/xinetd.d/nrpe
Entry will be like this:-
service nrpe
{
flags = REUSE
socket_type = stream
port = 5666
wait = no
user = nagios
group = nagios
server = /usr/local/nagios/bin/nrpe
server_args = -c /etc/nrpe.conf –inetd
log_on_failure += USERID
disable = no
# only_from = 127.0.0.1
}
only_from = 127.0.0.1
Edit services file entry:
Add entry for nrpe daemon
[root@p-root~]# vi /etc/services
nrpe 5666/tcp # NRPE
Restart Xinetd and Set to start at boot:
[root@p-root~]# chkconfig xinetd on
[root@p-root~]# service xinetd restart
Test NRPE Daemon Install
Check NRPE daemon is running and listening on port 5666:
[root@p-root~]# netstat -at |grep nrpe
Output should be:-
tcp 0 0 *:nrpe *.* LISTEN
or
[root@p-root]# netstat -plan | grep 5666
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 15721/xinetd
Check NRPE daemon is functioning:
[root@p-root]# /usr/local/nagios/libexec/check_nrpe -H localhost
Output should be NRPE version:
NRPE v2.12