Nagios 3.0 Jumpstart Guide For Linux – Overview, Installation and Configuration

by Ramesh Natarajan on May 29, 2008

Nagios

Let us discuss the overview, installation and configuration of Nagios, a powerful open source monitoring solution for host and services.
 
I. Overview of nagios

II. 8 steps for installing nagios on Linux:

  1. Download the nagios and plugins
  2. Take care of the prerequisites
  3. Create user and group for nagios
  4. Install nagios
  5. Configure the web interface
  6. Compile and install nagios plugins
  7. Start Nagios
  8. Login to web interface

III. Configuration files overview


I. Overview of Nagios

.
Nagios is a host and service monitor tool. Following are some of the features of nagios.
 

  • Monitor equipments such as servers, switches, routers, firewalls, power supply etc.
  • Monitor services such as disk space, cpu usage, memory usage, temperature of the equipment, HTTP, Mail, SSH etc.
  • Nagios can monitor pretty much anything. for e.g. host, services, databases, applications etc.
  • Nagios has an extensible plugin interface for monitoring user defined services. There are lot of plugins available for Nagios. Visit NagiosPlugins and NagiosExchange for review the available user developed plugins.
  • It can send out various notifications ( email, pager etc.) when the problem occurs and get resolved.
  • Web interface to view current status, notifications, problem history, log files etc.

Following is a partial screenshot of the nagios web dashboard:
 

Nagios Web UI
Fig: Nagios Web UI (click on the image to enlarge)

II. 8 steps for installing nagios on Linux:

1. Download the nagios and plugins

Download following files from Nagios.org and move to /home/downloads

  • nagios-3.0.1.tar.gz
  • nagios-plugins-1.4.11.tar.gz

2. Take care of the prerequisites

  • Make sure apache is working on the server by verifying from browser: http://localhost
  • Verify whether gcc is installed
      [root@localhost]#rpm -qa | grep gcc
      gcc-3.4.6-8
      compat-gcc-32-3.2.3-47.3
      libgcc-3.4.6-8
      compat-libgcc-296-2.96-132.7.2
      compat-gcc-32-c++-3.2.3-47.3
      gcc-c++-3.4.6-8
  • Verify whether GD is installed
      [root@localhost]# rpm -qa gd
      gd-2.0.28-5.4E

3. Create user and group for nagios

[root@localhost]# useradd nagios
[root@localhost]# passwd nagios
[root@localhost]# groupadd nagcmd
[root@localhost]# usermod -G nagcmd nagios
[root@localhost]# usermod -G nagcmd apache

4. Install nagios

[root@localhost]# tar xvf nagios-3.0.1.tar.gz
[root@localhost]# cd nagios-3.0.1
[root@localhost]# ./configure --with-command-group=nagcmd
[root@localhost]# make all
[root@localhost]# make install
[root@localhost]# make install-config
[root@localhost]# make install-commandmode

Following are some additional parameters that you can pass to ./configure to customize your installation. I used only --with-command-group as shown above.

	--prefix		/opt/nagios	Where to put the Nagios files
	--with-cgiurl		/nagios/cgi-bin	Web server url where the cgi's will be available
	--with-htmurl		/nagios		Web server url where nagios will be available
	--with-nagios-user	nagios		user account under which Nagios will run
	--with-nagios-group	nagios		group account under which Nagios will run
	--with-command-group	nagcmd		group account which will allow the apache user to submit
						commands to Nagios

At the end of the configure output, it will display a summary as shown below:

*** Configuration summary for nagios 3.0.1 05-28-2008 ***:

General Options:
-------------------------
Nagios executable:  nagios
Nagios user/group:  nagios,nagios
Command user/group:  nagios,nagcmd
Embedded Perl:  no
Event Broker:  yes
Install ${prefix}:  /usr/local/nagios
Lock file:  ${prefix}/var/nagios.lock
Check result directory:  ${prefix}/var/spool/checkresults
Init directory:  /etc/rc.d/init.d
Apache conf.d directory:  /etc/httpd/conf.d
Mail program:  /bin/mail
Host OS:  linux-gnu

Web Interface Options:
------------------------
HTML URL:  http://localhost/nagios/
CGI URL:  http://localhost/nagios/cgi-bin/
Traceroute (used by WAP):  /bin/traceroute

5. Configure the web interface.

[root@localhost]# make install-webconf
[root@localhost# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin

6. Compile and install nagios plugins

[root@localhost]# tar xvf nagios-plugins-1.4.11.tar.gz
[root@localhost]# cd nagios-plugins-1.4.11
[root@localhost]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
[root@localhost]# make
[root@localhost]# make install

Note: On Red Hat, the ./configure command mentioned above did not work and was hanging at the when it was displaying the message: checking for redhat spopen problem… Add –enable-redhat-pthread-workaround to the ./configure command as a work-around for the above problem as shown below.

[root@localhost]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-redhat-pthread-workaround

7. Start Nagios

  • Add the nagios to the startup routine:
      [root@localhost]# chkconfig --add nagios
      [root@localhost]# chkconfig nagios on
  • Verify to make sure there are no errors in the nagios configuration file:
      [root@localhost]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

      Total Warnings: 0
      Total Errors:   0
      Things look okay - No serious problems were detected during the pre-flight check
  • Start the nagios
      [root@localhost]# service nagios start
      Starting nagios: done.

8. Login to web interface

Nagios Web URL: http://localhost/nagios/
Use the userid, password that was created from step#5 above.


III. Configuration files overview

.
The first configuration to modify is to change the default value of email address in /usr/local/nagios/etc/objects/contacts.cfg file to your email address.

Following are the three major configuration files located under /usr/local/nagios/etc
 

  1. nagios.cfg – This is the primary Nagios configuration file where lot of global parameters that controls the nagios can be defined.
  2. cgi.cfg - This files has configuration information for nagios web interface.
  3. resource.cfg – If you have to pass some sensitive information (username, password etc.) to a plugin to monitor a specific service, you can define them here. This file is readable only by nagios user and group.

Following are the other configuration files under /usr/local/nagios/etc/objects directory:
 

  • contacts.cfg: All the contacts who needs to be notified should be defined here. You can specify name, email address, what type of notifications they need to receive and what is the time period this particular contact should be receiving notifications etc.
  • commands.cfg – All the commands to check services are defined here. You can use $HOSTNAME$ and $HOSTADDRESS$ macro on the command execution that will substitute the corresponding hostname or host ip-address automatically.
  • timeperiods.cfg – Define the timeperiods. for e.g. if you want a service to be monitored only during the business hours, define a time period called businesshours and specify the hours that you would like to monitor.
  • templates.cfg – Multiple host or service definition that has similar characteristics can use a template, where all the common characteristics can be defined. Use template is a time saver.
  • localhost.cfg – Defines the monitoring for the local host. This is a sample configuration file that comes with nagios installation that you can use as a baseline to define other hosts that you would like to monitor.
  • printer.cfg – Sample config file for printer
  • switch.cfg – Sample config file for switch
  • windows.cfg – Sample config file for a windows machine

I will discuss about the steps to configure a remote Linux Host and Windows Host for monitoring through nagios in upcoming posts.
 

Two Best Nagios Books

These are the two best nagios books that covers the latest Nagios 3. I strongly recommend that you read both of these books to gain a detailed understanding on Nagios. Since Nagios is free software, spending few dollars on the books can be the best investment you can make.

Nagios 3.1 (2nd edition)    Learning Nagios 3.1
Nagios Book 1
  
Nagios Book 2

Awesome Nagios Articles

Following are few awesome Nagios articles that you might find helpful.

Download Free eBook - Linux 101 Hacks

Get free Unix tutorials, tips and tricks straight to your email in-box.

If you enjoyed this article, you might also like..

  1. How To Monitor Remote Linux Host using Nagios 3.0
  2. Nagios XI Review (Free Nagios core Vs Nagios XI)
  3. Linux NBD Tutorial: Network Block Device Jumpstart Guide
  4. How To Monitor Remote Windows Machine Using Nagios on Linux
  5. How To Monitor Network Switch and Ports Using Nagios
  

Vim 101 Hacks Book

{ 8 trackbacks }

The Geek Stuff » How to monitor remote Linux host using Nagios 3.0
June 1, 2008 at 10:58 pm
The Geek Stuff » How to monitor remote Windows machine using Nagios on Linux
July 9, 2008 at 11:17 pm
The Geek Stuff » How To Monitor VPN Active Sessions and Temperature Using Nagios
September 11, 2008 at 12:01 am
The Geek Stuff » How To Monitor Network Switch and Ports Using Nagios
November 3, 2008 at 8:31 am
How to monitor remote Windows machine using Nagios on Linux « Junji’s Blog Site
November 19, 2008 at 2:15 am
4 Steps to Define Nagios Contacts With Email and Pager Notification
June 15, 2009 at 9:02 am
The Beginner’s Guide to The Geek Stuff – A Guided Tour
December 29, 2009 at 9:11 am
Nagios XI Review (Free Nagios core Vs Nagios XI)
February 8, 2010 at 12:03 am

{ 11 comments… read them below or add one }

1 jackie July 23, 2008 at 9:10 am

I cant find any documentation about how to add further hosts. i have nagios running, monitoring the local host and another pc, using the localhost.cfg and windows.cfg file. How to add more hosts? I tried to create another file and declared it in the nagios.cfg file but doesnt work. any ideas?

2 Neal September 24, 2008 at 9:07 am

I think you missed a command. Step 4 should also include “make install-init” otherwise step 7 will fail. Otherwise perfect post, thank you! Saved me a bit of hair pulling. :)

3 Ian October 23, 2008 at 2:47 am

There are also very useful quick start guides for Fedora, openSUSE and Ubuntu in the Nagios documentation :)

4 Siva December 4, 2008 at 6:43 pm

Hi, I had configured the windows.cfg file for one server. How do I configure for multiple servers?

5 Balakumar December 25, 2008 at 10:43 am

Thank u so much for nice article.It is very understandable.

6 kailas kadam June 29, 2009 at 10:55 pm

i configured nagios . when i was starting the NAGIOS service it is showing the error like unrecgnised service can u help me what is the service for nagios

waiting for reply

7 Ian June 29, 2009 at 11:29 pm

What does chkconfig –list | grep nagios show? If it shows nothing you need to go through the install guide again and check all the steps.

8 gopi August 25, 2009 at 8:35 am

Thanks I have successfully configured nagios by reading the above. but before trying this i installed through rpm which failed.

9 Arunkeerthan October 7, 2009 at 2:18 am

I configured Nagios no errors and warnings.But when i tried to start the Nagios service its saying “unrecognized service Nagios” .Please help me out in this issue..

10 Arunkeerthan October 7, 2009 at 11:13 am

“make install-init” chould be added to step 4 in RHEL.Otherwise its not working step 7 fails.I dont know about the other distros.
Thanks for the wonderful post.

11 Ezudin December 18, 2009 at 4:21 am

For installation on Ubuntu server see: https://help.ubuntu.com/9.10/serverguide/C/nagios.html

Leave a Comment

Previous post:

Next post: