NOTE: You will need to have root privileges for executing some of these commands

Install few pre-requisite packages first:

# yum install gd gd-devel gcc glibc glibc-common

Next, we install wget package as well. # yum install wget

Once done, the next step is to install and setup the EPEL Repo. We will use this repo to download the required Nagios packages for our system.

# wget http://epel.mirror.net.in/epel/6/<YOURARCH>/epel-release-6-8.noarch.rpmNOTE: Remember to change the <YOURARCH> depending on your system's architecture, i.e. x86_64 or i386Once the RPM is downloaded, simply install it using the following command:# rpm -ivh epel-release-6-8.noarch.rpm

Run a quick repolist command to make sure the EPEL Repo can list its packages:# yum repolist

All done, we can now install the Nagios packages using a simple command:# yum install nagios*

Once the installation completes, feel free to walk through the Nagios folder (/etc/nagios) and have a quick look around. The important things to know here are:

nagios.cfg

This is the configuration file which defines the various directives that Nagios uses. These directives include the path to various folders where Nagios needs to check in for the required files, the object config files, the command files etc and various other parameters which decide how Nagios operates.

nrpe.cfg

'nrpe' is a commonly used client application or agent that runs on the hosts to be monitored to gather local data which cannot (or is less logical to) be retrieved directly from the Nagios host. The nrpe.cfg file contains several command definitions that you'll likely use to monitor such hosts. READ MORE

objects Directory

This directory contains few configuration files described below:

contacts.cfgThis config file is used to send notifications of alerts and recoveries to particular users/ sysadmins.

Sample definition:

define contact {

contact_name bob

alias Bob The builder-sysadmin

use generic-contact

email john@exmaple.com

}

hosts.cfg

This config file defines various servers, routers, switches and other devices which Nagios has to monitor.

Sample definition:

define host {

use generic-host

host_name testserver.cloud.com

address 192.168.50.xxx

max_check_attempts 10

}

services.cfg

Nagios service objects call nagios commands (from the commands.cfg) which are a defined set of objects that run commands which return either of four flags: OK, WARNING, CRITICAL or UNKNOWN.

The following service simply checks the connectivity to the testserver by pinging it.

Sample definition:

define service {

use generic-service

host_name testserver.cloud.com

service_description PING TEST

check_command check_icmp!500.0,80%!1000.0,100%

}

commands.cfg

Here, the individual commands are defined. the following example describes the check_icmp command parameters.

To do a quick start with Nagios, we will first add a EMAIL ADDRESS for our Nagios admin account. This can be done in the objects/contacts.cfg file as shown below:

# Add the following in objects/contacts.cfg fileemail admin@cloud.com

Set the password for your nagiosadmin user:# htpasswd /etc/nagios/passwd nagiosadmin

You are almost there! Simply start up the Nagios service:# service nagios start# chkconfig nagios on

Open up a browser and type in the following:http://<NAGIOS_SERVER_IP>/nagios
The Web-based UI is fairly simple to understand and use. The menus o the left of the page help in quick navigation to view status of various hosts, their services, host groups and service groups.

If you click on the Hosts tab, it displays all the hosts that are being monitored by Nagios. Since we haven't added any host explicitly yet, all you will see is the localhost, i.e. the Nagios Server itself. You can view its status and status information here. To know more details about the individual host, simply select the host as shown below:

As shown here, you can monitor the individual host for its performance, uptime, etc. You can also set various commands for your host such as disable active checks, schedule downtime for a host etc from the Host Commands section provided to the right of the page.

Configuring Nagios monitoring on Clients

Nagios can virtually monitor any infrastructure thats basically on a network. In this case, I'm going to show you a quick way to setup Nagios monitoring on a Client host.

Nagios Client Setup:

In this section of the tutorial, I'll be using a CentOS 6.5 as my Client however, similar steps can be followed for a Ubuntu-based Client as well... just remember to change yum install.. to a sudo apt-get install..

OS: CentOS 6.5 Minimal Server

Name: lamp.cloud.com

IP: 192.168.50.152

NOTE: You will need to have root privileges for executing some of these commands

Save the nrpe.cfg file.Now moving over to the Nagios Server, edit the nagios.cfg and remove the comment on the following line:cfg_dir=/etc/nagios/servers

Next, create a new directory inside the nagios called as servers and create a new config file in it as shown:We are going to use this newly created config file to add our Client for remote monitoring.# mkdir servers# cd servers/# vi clients.cfg

Add the following content in the clients.cfg file. Make sure to change the host_name and address parameters as per your client's needs.

NOTE: Use of '#' as in comments does not work in Nagios, instead, you need to use a semi-colon ';' for it.