Monitoring with Nagios: Installation and Configuration

In this series of tutorials, I’ll be walking you through simple steps to setup and get started with Nagios, a really cool open source monitoring tool.

Why Nagios?

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.. and much more..
Post’s I’ll be covering:
1) Installing and configuring Nagios Core (THIS TUTORIAL)
2) Monitoring Basic Services with Nagios
So without further adieu, LETs GET STARTED!!

Nagios Server Setup:

OS: CentOS 6.5 Minimal Server
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<YOURARCH>/epel-release-6-8.noarch.rpm

NOTE: Remember to change the <YOURARCH> depending on your system’s architecture, i.e. x86_64 or i386

Once 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:
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’ 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:
This 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

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

Sample definition:
    define host {
        use generic-host
        max_check_attempts 10

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
        service_description PING TEST
        check_command check_icmp!500.0,80%!1000.0,100%
Here, the individual commands are defined. the following example describes the check_icmp command parameters.
Sample definition:    
define command {
command_name check_icmp
command_line $USER1$/check_icmp -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$


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 file

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:

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
NOTE: You will need to have root privileges for executing some of these commands

Next, we install the Nagios Plugins and NRPE in our Client system
# yum install nrpe nagios-plugins-all openssl

Once installed, we need to add the Nagios Server IP address ( in our Client NRPE’s configuration file as shown below:
# vi /etc/nagios/nrpe.cfg

# Append the Nagios Server IP to the allowed_hosts parameter

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

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.
    define host {
        use                                 linux-server
        host_name                      lamp
        alias                                lampserver
        max_check_attempts       5
        check_period                   24×7
        notification_interval          30
        notification_period            24×7

Restart the Nagios service for the changes to take effect.

NOTE: Nagios service will not startup if they are any errors in the config files

To view the Client in the Nagios UI, click on the Hosts tab. You should see the newly added Client (in this case, lamp) as shown below:

Clicking on the Client name shows you further details regarding its status, performance, uptime etc

You can add services to be monitored for your client by defining services as shown below:

define service {
        use                               generic-service
        host_name                    lamp
        service_description       SSH
        check_command          check_ssh
        notifications_enabled     0

Restart Nagios service once again and check the newly added service in the Services Tab in the Nagios UI. You should see the newly added SSH service under your Client name (here, its lamp)!!

You can add additional services and monitor additional clients as required.

Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: