Multiple Nagios Instances on a Single Server

In this post I will cover how to run Multiple Nagios Instances on a Single Server. This will take a single installation of Nagios and allow you to run separate instances as you would to separate out different environments, such as production, development, certification, etc….

It allows for flexibility of configurations and allows Nagios to run faster for checks and execution. This installation scenario is based on RedHat 5.x installation with Nagios 3.2.0, Nagios Plugins 1.4.13, Nagiosgraph, rrdtool and LDAP integration.


Download and Install Boutell’s GD library

make install

Compile and install the Nagios and Plugins

tar -xzf nagios-3.2.0.tar.gz
tar -xzf nagios-plugins-1.4.13.tar.gz
export NAGIOSHOME=/usr/local/nagios
cd nagios-3.2.0
./configure --enable-embedded-perl --with-command-group=nagios --with-gd-lib=/usr/local/lib --with-gd-inc=/usr/local/include; make  all; make install install-init;make-install-config;make install-commandmode

Compile and install the Nagios plugins

cd nagios-plugins-1.4.13
./configure --prefix=$NAGIOSHOME/core/nagios-plugins --with-nagios-user=nagios --with-nagios-group=nagios; make ; make install

File Copy and Directory Creation
Create directories which hold your instances and their subdirectories


mkdir $NAGIOSHOME/instances
mkdir $NAGIOSHOME/instances/nagios_prod
mkdir $NAGIOSHOME/instances/nagios_prod/etc
mkdir $NAGIOSHOME/instances/nagios_prod/etc/monitors
mkdir $NAGIOSHOME/instances/nagios_prod/var
mkdir $NAGIOSHOME/instances/nagios_prod/var/rw
mkdir $NAGIOSHOME/instances/nagios_prod/var/spool
mkdir $NAGIOSHOME/instances/nagios_prod/var/spool/checkresults
mkdir $NAGIOSHOME/instances/nagios_prod/share
mkdir $NAGIOSHOME/instances/nagios_prod/sbin

Create Symbolic Links

ln -s $NAGIOSHOME/nagios/bin $NAGIOSHOME/instances/nagios_prod/bin
ln -s $NAGIOSHOME/nagios-plugins/libexec $NAGIOSHOME/instances/nagios_prod/libexec

Copy files

cp -r $NAGIOSHOME/sbin/*  $NAGIOSHOME/instances/nagios_prod/sbin/
cp –r $NAGIOSHOME/nagios/share/* $NAGIOSHOME/instances/nagios_prod/share/
cp $NAGIOSHOME/etc/cgi.cfg  $NAGIOSHOME/instances/nagios_prod/etc/
cp $NAGIOSHOME/etc/resource.cfg  $NAGIOSHOME/instances/nagios_prod/etc/
cp $NAGIOSHOME/etc/nagios.cfg  $NAGIOSHOME/instances/nagios_prod/etc/

Do the same with all the other instances you are going to deploy.

In the editing of the Nagios config files there will be instances that point to a central shared location and to individual settings. The configurations that are shared are checkcommands.cfg, misccommands.cfg, contacts.cfg, contactgroups.cfg, timeperiods.cfg, templates.cfg, dependencies.cfg & escalations.cfg.
The individual ones are the specific monitors and hosts, which in the nagios.cfg we will state a directory instead of the individual configuration files.

nagios.cfg modifications




# Definitions for monitoring


CGI.CFG File Edits

The cgi.cfg file must be edit for Apache to be able to run the correct CGI scripts for each instance you plan to run. To follow the examples in previous sections we use nagios_prod as our instance.


Resource.cfg file edits


Create nagios configuration for Apache
Create a nagios_prod.conf file in the /etc/httpd/conf.d directory with the following contents.
Note: this example uses ldap and the string will vary for your instance.

ScriptAlias /nagios_prod/cgi-bin/ "/usr/local/nagios/instances/nagios_prod/sbin/"

   SetEnv NAGIOS_CGI_CONFIG /usr/local/nagios/instances/nagios_prod/etc/cgi.cfg
   Options ExecCGI
   Options FollowSymLinks
   AllowOverride None
   Order allow,deny
   Allow from all
   AuthType Basic
   AuthName "Nagios Area51"
   AuthBasicProvider ldap
   AuthzLDAPAuthoritative off
   AuthLDAPURL ldaps://myldaprod:636/ou=IMEROOT,o=corp?uid

Alias /nagios_prod/ "/usr/local/nagios/instances/nagios_prod/share/"

   Options None
   AllowOverride None
   Order allow,deny
   Allow from all
   AuthType Basic
   AuthName "Nagios Area51"
   AuthBasicProvider ldap
   AuthzLDAPAuthoritative off
   AuthLDAPURL ldaps://myldaprod:636/ou=IMEROOT,o=corp?uid


The file is located in the /usr/local/nagios/instances/nagios_prod/share/ directory. Make the path changes for the instance.


Correct Directory and File PermissionsAt this point it is a good time to correct the file and directory permissions to the correct owner. Nagios is very particular on the correct settings. This is a painful process and is a good candidate to dump in a script and ran.

# chown –R nagios.nagios /usr/local/nagios/
# chown –R root.root /usr/local/nagios/instances/nagios_prod/share/locale
# chmod 775 /usr/local/nagios/instances
# chmod 775 /usr/local/nagios/instances/nagios_prod
# chmod 775 /usr/local/nagios/instances/ nagios_prod /etc
# chmod 775 /usr/local/nagios/instances/ nagios_prod /etc/monitors
# chmod 775 /usr/local/nagios/instances/ nagios_prod/sbin
# chmod 775 /usr/local/nagios/instances/ nagios_prod/share
# chmod 775 /usr/local/nagios/instances/ nagios_prod/share/docs
# chmod 775 /usr/local/nagios/instances/ nagios_prod/share/contexthelp
# chmod 775 /usr/local/nagios/instances/ nagios_prod/share/images
# chmod 775 /usr/local/nagios/instances/ nagios_prod/share/images/logos
# chmod 775 /usr/local/nagios/instances/ nagios_prod/share/includes
# chmod 775 /usr/local/nagios/instances/ nagios_prod/share/media
# chmod 775 /usr/local/nagios/instances/ nagios_prod/share/ssi
# chmod 775 /usr/local/nagios/instances/ nagios_prod/share/stylesheets
# chmod 775 /usr/local/nagios/instances/ nagios_prod/var
# chmod 775 /usr/local/nagios/instances/ nagios_prod/var/rw
# chmod 775 /usr/local/nagios/instances/ nagios_prod/var/spool
# chmod 775 /usr/local/nagios/instances/ nagios_prod/var/spool/checkresults

Now the files

# chmod 664 /usr/local/nagios/instances/nagios_prod/*
# chmod 664 /usr/local/nagios/instances/ nagios_prod /etc/*
# chmod 664 /usr/local/nagios/instances/ nagios_prod /etc/monitors/*
# chmod 664 /usr/local/nagios/instances/ nagios_prod/sbin/*
# chmod 664 /usr/local/nagios/instances/ nagios_prod/share/*
# chmod 664 /usr/local/nagios/instances/ nagios_prod/share/docs/*
# chmod 664 /usr/local/nagios/instances/ nagios_prod/share/contexthelp/*
# chmod 664 /usr/local/nagios/instances/ nagios_prod/share/images/*
# chmod 664 /usr/local/nagios/instances/ nagios_prod/share/images/logos/*
# chmod 664 /usr/local/nagios/instances/ nagios_prod/share/includes/*
# chmod 664 /usr/local/nagios/instances/ nagios_prod/share/media/*
# chmod 664 /usr/local/nagios/instances/ nagios_prod/share/ssi/*
# chmod 664 /usr/local/nagios/instances/ nagios_prod/share/stylesheets/*
# chmod 664 /usr/local/nagios/instances/ nagios_prod/var/*
# chmod 664 /usr/local/nagios/instances/ nagios_prod/var/rw/*
# chmod 664 /usr/local/nagios/instances/ nagios_prod/var/spool/*
# chmod 664 /usr/local/nagios/instances/ nagios_prod/var/spool/checkresults/*

Create Monitors
At this point you can start the creation of the monitors, hosts, hostgroups, contacts. Contactgroups and all the other dependent settings. Refer to Nagios site for syntax on each of the different objects. Foe the monitors you can use the default monitors created at install in /usr/local/nagios/etc/objects and copy the configs for localhost.cfg and windows.cfg as a starting basis.
Once you have your settings completed you need to run a check on the configs running the command

# /usr/local/nagios/instances/nagios_prod/bin/nagios -v /usr/local/nagios/instances/nagios_prod/etc/nagios.cfg

Fix any errors at this point and recheck.

Startup Scripts (init.d)
Add Nagios to the list of system services and have it automatically start when the system boots.
Create init.d scripts for each instance you want to create. Copy the Nagios installed script, and name it nagios_prod. Open in your favorite editor and find the line prefix= and change the path.



Save the changes and change the permissions to 755 on the script.

Use chkconfig to add it to the startup and enable it.

# chkconfig --add nagios_prod
# chkconfig nagios_prod on

At this point you can already start your instances:

# service nagios_prod start

Now restart your Apache and open your browser

# service httpd restart

NagiosGraph (Performance Monitoring)
This section explains how to configure Nagiosgraph for multiple instances to gathering and graphing performance data created by Nagios. Each of the steps will have to be done for each individual instance you want to collect and graph performance data with the exception of rrdtool and intltool installs, those are only required installed once.

intltool.x86_64 to 0.35 or higher

Update intltool.x86_64 to 0.35 or higher

# yum -y install  intltool.x86_64

Install rrdtool

# wget ''
# wget ''
# wget ''
# wget ''
# wget ''
# wget ''
# wget ''
# wget ''
# yum install -y libart_lgpl
# rpm -hiv *rrdtool*.rpm

Install NagiosGraph
Download NagiosGraph 1.3.1 from

# cd /usr/local/src
# tar xvf nagiosgraph-1.3.1.tar.gz
# cd nagiosgraph-1.3.1

Create the directory structure and copy files

# mkdir /usr/local/nagios/instances/nagios_prod/nagiosgraph
# mkdir /usr/local/nagios/instances/nagios_prod/nagiosgraph/rrd
# cp -r . /usr/local/nagios/instances/nagios_prod/nagiosgraph/
# chmod go+rX /usr/local/nagios/instances/nagios_prod/nagiosgraph
# chown nagios.apache /usr/local/nagios/instances/nagios_prod/nagiosgraph/rrd

# cd /usr/local/nagios/instances/nagios_prod/nagiosgraph/lib
# cp insert.* /usr/local/nagios/instances/nagios_prod/sbin/
# touch /usr/local/nagios/instances/nagios_prod/var/nagiosgraph.log /usr/local/nagios/instances/nagios_prod/var/spool/perfdata.log
# chown nagios.apache /usr/local/nagios/instances/nagios_prod/var/nagiosgraph.log /usr/local/nagios/instances/nagios_prod/var/spool/perfdata.log
# chmod 664 /usr/local/nagios/nagios_prod/var/nagiosgraph.log
# chmod 644 /usr/local/nagios/nagios_prod/var/spool/perfdata.log

# cd /usr/local/nagios/instances/nagios_prod/nagiosgraph/share
# cp nagiosgraph.js /usr/local/nagios/instances/nagios_prod/share/
# cp nagiosgraph.css /usr/local/nagios/instances/nagios_prod/share/stylesheets/
# chown nagios.nagios /usr/local/nagios/instances/nagios_prod/share/nagiosgraph.js
# chown nagios.nagios /usr/local/nagios/instances/nagios_prod/share/stylesheets/nagiosgraph.css

# cd /usr/local/nagios/instances/nagios_prod/nagiosgraph/cgi
# cp * /usr/local/nagios/instances/nagios_prod/sbin/
# cd /usr/local/nagios/instances/nagios_prod/nagiosgraph/etc/
# mv  /usr/local/nagios/instances/nagios_prod/sbin/
# mv nagiosgraph.conf  /usr/local/nagios/instances/nagios_prod/sbin/
# mv servdb.conf /usr/local/nagios/instances/nagios_prod/etc/
# mv hostdb.conf /usr/local/nagios/instances/nagios_prod/etc/
# mv map  /usr/local/nagios/instances/nagios_prod/etc/
# chown nagios.nagios  /usr/local/nagios/instances/nagios_prod/sbin/*

# cp /usr/local/nagios/instances/nagios_prod/nagiosgraph/etc/*  /usr/local/nagios/instances/nagios_prod/etc/
# mv /usr/local/nagios/instances/nagios_prod/etc/nagiosgraph.conf  /usr/local/nagios/instances/nagios_prod/sbin/
# mv /usr/local/nagios/instances/nagios_prod/etc/  /usr/local/nagios/instances/nagios_prod/sbin/

Configuration file edits & file
Edit & and modify the lib path.

# The configuration file and must be in this directory.

use lib '/usr/local/nagios/instances/nagios_prod/sbin';

Various CGI files
Edit the perl scripts in the cgi and lib directories, modifying the “use lib” for the following files in the /usr/local/nagios/instances/nagios_prod/sbin directory.


Change the following line.

use lib '/usr/local/nagios/instances/nagios_prod/sbin';

Nagiosgraph.conf file
Edit nagiosgraph.conf change the following lines.

rrddir = /usr/local/nagios/instances/nagios_prod/nagiosgraph/rrd
mapfile = /usr/local/nagios/instances/nagios_prod/etc/map

# Location of performance data log file. Comment out if not used.
perflog = /usr/local/nagios/instances/nagios_prod/var/spool/perfdata.log

# Location of hosts/database control file
hostdb = /usr/local/nagios/instances/nagios_prod/etc/hostdb.conf

# Location of services/database control file
servdb = /usr/local/nagios/instances/nagios_prod/etc/servdb.conf

# Nagios CGI URL
nagioscgiurl = https://cvglp9999/nagios_prod/cgi-bin

# JavaScript configuration
# The URL for the nagiosgraph.js file
javascript = /nagios_prod/nagiosgraph.js

# Stylesheet - added to head of show.cgi, etc. Comment out if not used
stylesheet = /nagios_prod/stylesheets/nagiosgraph.css

nagios.cfg file
Edit nagios.cfg and change /add.
Add the line

# NagiosGraph

Modify the following lines.


checkcommands.cfg file
Add to your checkcommands.cfg file in the shared Nagios libexec directory

define command {
       command_name  process-service-perfdata-prod
       command_line  /usr/bin/perl /usr/local/nagios/instances/nagios_prod/sbin/

serviceextinfo.cfg file
Create serviceextinfo.cfg in /usr/local/nagios/instances/nagios_prod/etc/ and add the entries in for the performance data to graph. Refer to Nagios documentation on the syntax for the serviceextinfo.cfg file. This file will tell which service monitors you would like to collect performance data on.
Example entry:

define serviceextinfo {
  service_description  Memory Usage
  hostgroup_name       windows-prod-servers
  notes_url       /nagios_prod/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&db=ntmem,memused,memwarn,memcrit,memmmax
  icon_image     extinfo.gif

define serviceextinfo {
  service_description  CPU_Load
  hostgroup_name    windows-prod-servers
  notes_url       /nagios_prod/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&db=ntload,avg05min,avg30min
  icon_image     extinfo.gif

Edit cgi.cfg and add line under main_config_file entry.


Map file
Edit the map file in usr/bin/perl /usr/local/nagios/instances/nagios_prod/etc directory. The default Nagiosgraph supplied one doesn’t have any Windows service map files. A good source for examples can be found at and has the basic map files needed for a good start.


# Service type: ntload
# check command: check_nt -H Address -v CPULOAD -l5,80,90,30,70,80
# output: CPU Load 9% (5 min average) 11% (10 min average) 3% (30 min average)
# perfdata: .5 min avg Load.=9%;80;90;0;100 .15 min avg Load.=11%;70;80;0;100 .30 min average Load.=3%;80;90;0;100
/output:.*?Load (\d+)% .*?(\d+)% /
and push @s, [ ntload,
[ avg05min, GAUGE, $1 ],
[ avg30min, GAUGE, $2 ] ];

# Service type: ntmem
#   check command: check_nt -H Address -v MEMUSE -w 50 -c 90
#   output: Memory usage: total:2467.75 Mb - used: 510.38 Mb (21%) - free: 1957.37 Mb (79%)
#   perfdata: Memory usage=510.38Mb;1233.88;2220.98;0.00;2467.75
and push @s, [ ntmem,
       [ memused, GAUGE, $1*1024**2 ],
       [ memwarn, GAUGE, $2*1024**2 ],
       [ memcrit, GAUGE, $3*1024**2 ],
       [ memmmax, GAUGE, $5*1024**2 ] ];

Complete Install
Now that NagiosGraph is installed all that remains is to restart your Nagios instance and Apache and check the results.

# service nagios_prod restart
# service httpd restart

I know this is a long and detailed article, but this can be done and has great benefit. If you would like a downloadable pdf of this post it is available Multiple_Nagios_instances_single_server.

One Response to “Multiple Nagios Instances on a Single Server”

  1. Eherr says:

    Following this to the T gets a lot of errors.

    Had to make my own mods and still cant get it to work.

    Any updates on this site?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.