Nagios 3.x Install from Source on Ubuntu 12.04

This post is in the category: Guides

Posts here are mostly step-by-step guides on how to replicate something I have set up in the past. Read over my About page to see how I show commands/output and read the disclaimer.

When I deploy a new Nagios box, I always start with this. I do not use deb packages here because they are too many versions behind. Plus, I like to have full control over how this is configured.

I will refer to this server with the hostname s10-nagios. Change at will, but adjust the commands accordingly.

Base OS Installation

Install Ubuntu Server 12.04. If you are provisioning a VM, a 24GB drive will be plenty.

Set a root password. Yeah, it’s best to use sudo for the one-off commands. But sometimes being root is just easier.

[user]$ sudo passwd root

Be sure we are on the latest updates:

[root]$ apt-get update
[root]$ apt-get dist-upgrade

Some basic reminders: Set account passwords, bash prompts, etc.

Nagios & Plugins Install

This guide is for Nagios 3.5.1. You may choose to use a different version, just make sure you adjust the commands that deal with version numbers accordingly.

Prepare the Nagios User & Group

[root]$ useradd -m -s /bin/bash nagios
[root]$ passwd nagios

Create the group needed for submitting commands from the web.

[root]$ groupadd nagcmd
[root]$ usermod -a -G nagcmd nagios
[root]$ usermod -a -G nagcmd www-data

Download / Extract Archives

[root]$ cd ~
[root]$ wget 
[root]$ tar -xzvf nagios-3.5.1.tar.gz
[root]$ wget
[root]$ tar -xzvf nagios-plugins-1.5.tar.gz

By the way, both of those tar command were without referencing the docs.

Compile and Install Nagios

Install some required packages.

[root]$ apt-get install libgd2-xpm-dev apache2 php5
[root]$ cd ~/nagios
[root]$ ./configure --with-command-group=nagcmd
[root]$ make all

After the compiling is complete, the following options are presented:

make install – This installs the main program, CGIs, and HTML files – make install-init – This installs the init script in /etc/init.d – make install-commandmode – This installs and configures permissions on the directory for holding the external command file – make install-config – This installs SAMPLE config files in /usr/local/nagios/etc You’ll have to modify these sample files before you can use Nagios. Read the HTML documentation for more info on doing this. Pay particular attention to the docs on object configuration files, as they determine what/how things get monitored! – make install-webconf – This installs the Apache config file for the Nagios web interface – make install-exfoliation – This installs the Exfoliation theme for the Nagios web interface – make install-classicui – This installs the classic theme for the Nagios web interface

I ran the following installations:

[root]$ make install
[root]$ make install-init
[root]$ make install-commandmode
[root]$ make install-config
[root]$ make install-webconf

Don’t attempt to start Nagios yet.

Compile and Install Nagios Plugins

We first need to install some prerequisites.

[root]$ apt-get install libnet-snmp-perl libperl5.14 libpq5 libradius1 libsensors4 libsnmp-base libsnmp15 libtalloc2 libtdb1 libwbclient0 samba-common samba-common-bin smbclient snmp whois libmysqlclient15-dev libssl-dev

Now install it

[root]$ cd ~/nagios-plugins-1.5
[root]$ ./configure --with-nagios-user=nagios --with-nagios-group=nagios
[root]$ make
[root]$ make install

NRPE Plugin Make & Install

Note the steps below carefully. DO NOT run “make install”. All we want to do is copy out the check_nrpe plugin, which is apparently not included in the original plugin pack.

[root]$ cd ~
[root]$ wget
[root]$ tar -xzvf nrpe-2.14.tar.gz
[root]$ cd nrpe-2.14
[root]$ ./configure --with-ssl=/usr/bin/openssl --with-ssl-lib=/usr/lib/x86_64-linux-gnu
[root]$ make

Instead of installing this whole package, we just want the plugin exec.

[root]$ cp src/check_nrpe /usr/local/nagios/libexec/


Create the Apache login credentials.

[root]$ htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Configure your Nagios services / hosts. For now, I recommend that you only setup a couple service checks for localhost while we build out the rest of the configuration.

BONUS TIP: Bash Alias

Create this bash alias to make it easier to run checks. For the rest of this guide, I will use the command nverify to run a check assuming that you created this alias.

[root]$ vim ~/.bash_aliases
alias nverify="/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg"

Don’t forget to log out and then back in to this box to see the new alias.

Check the configuration.

[root]$ nverify

Hold your breath & start the services.

[root]$ service apache2 restart
[root]$ service nagios start

Configure service to run at startup:

[root]$ ln -s /etc/init.d/nagios /etc/rc2.d/S20nagios

Checkpoint One

Let’s pause a moment to verify we have not made any mistakes.
  1. Reboot s10-nagios
  2. Verify that the service automatically started. Correct any startup config issues.
  3. Attempt to navigate to http://s10-nagios/nagios from a computer on the same LAN.
  4. Login using credentials previously specified.
Everything pass? Great – onward!


Install some more prerequisites.

[root]$ apt-get install libcgi-pm-perl librrds-perl libgd-gd2-perl

Download and extract the files.

[root]$ cd ~
[root]$ wget
[root]$ tar -xzvf nagiosgraph-1.4.4.tar.gz
[root]$ cd nagiosgraph-1.4.4

Verify that we have a working environment.

[root]$ ./ --check-prereq

If everything looks good, continue with the install. I think it’s best to keep everything separate from the Nagios install to make upgrades easier.

[root]$ ./ --layout standalone --prefix /usr/local/nagiosgraph

Most of the questions should be left at the default, except the last few. Questions that are not default are emphasized.

Destination directory (prefix)? [/usr/local/nagiosgraph]
Location of configuration files (etc-dir)? [/usr/local/nagiosgraph/etc]
Location of executables? [/usr/local/nagiosgraph/bin]
Location of CGI scripts? [/usr/local/nagiosgraph/cgi]
Location of documentation (doc-dir)? [/usr/local/nagiosgraph/doc]
Location of examples? [/usr/local/nagiosgraph/examples]
Location of CSS and JavaScript files? [/usr/local/nagiosgraph/share]
Location of utilities? [/usr/local/nagiosgraph/util]
Location of state files (var-dir)? [/usr/local/nagiosgraph/var]
Location of RRD files? [/usr/local/nagiosgraph/var/rrd]
Location of log files (log-dir)? [/usr/local/nagiosgraph/var]
Path of log file? [/usr/local/nagiosgraph/var/nagiosgraph.log]
Path of CGI log file? [/usr/local/nagiosgraph/var/nagiosgraph-cgi.log]
URL of CGI scripts? [/nagiosgraph/cgi-bin]
URL of CSS file? [/nagiosgraph/nagiosgraph.css]
URL of JavaScript file? [/nagiosgraph/nagiosgraph.js]
Path of Nagios performance data file? [/tmp/perfdata.log]
URL of Nagios CGI scripts? [/nagios/cgi-bin]
username or userid of Nagios user? [nagios]
username or userid of web server user? [www-data]
Modify the Nagios configuration? [n] y
Path of Nagios configuration file? [/usr/local/nagios/etc/nagios.cfg]
Path of Nagios commands file? /usr/local/nagios/etc/objects/commands.cfg
Modify the Apache configuration? [n] y

Restart some services.

[root]$ service apache2 restart
[root]$ service nagios restart

Graphs can now be access here: http://s10-nagios/nagiosgraph/cgi-bin/show.cgi

Template Hacks…err…Integration

The graphs can be integrated into the templates with a couple hacks. They are a bit cringeworthy, but they work.

To activate the pop-up graphs that we will include later, create this file.

[root]$ vim /usr/local/nagios/share/ssi/common-header.ssi
<script type="text/javascript" src="/nagiosgraph/nagiosgraph.js"></script>

To include icons for a specific service, you will need this line in your service definition:

action_url      /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&geom=1000x200' onMouseOver='showGraphPopup(this)' onMouseOut='hideGraphPopup()' rel='/nagiosgraph/cgi-bin/showgraph.cgi?host=$HOSTNAME$&service=$SERVICEDESC$

I also have a special graph saved for ping tests. I use this to show RTA and packet loss. We are going to utilize both actionurl and notesurl for this.

action_url              /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&db=pl,data&db=pl,warn&db=pl,crit&geom=1000x200' onMouseOver='showGraphPopup(this)' onMouseOut='hideGraphPopup()' rel='/nagiosgraph/cgi-bin/showgraph.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&db=pl,data&db=pl,warn&db=pl,crit
notes_url               /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&db=rta,data&db=rta,warn&db=rta,crit&geom=1000x200' onMouseOver='showGraphPopup(this)' onMouseOut='hideGraphPopup()' rel='/nagiosgraph/cgi-bin/showgraph.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&db=rta,data&db=rta,warn&db=rta,crit

Since we make use of the notes icon, lets give it the graph icon as well.

[root]$ mv /usr/local/nagios/share/images/notes.gif /usr/local/nagios/share/images/notes.bak.gif
[root]$ cp /usr/local/nagios/share/images/action.gif /usr/local/nagios/share/images/notes.gif

Go into your host configuration files and add the graph templates to your service definitions. Only add them to services that are returning performance data.

Check and restart Nagios.

[root]$ nverify
[root]$ service nagios restart

Checkpoint Two

Let’s pause a moment to verify we have not made any mistakes.

You may have to let Nagios run for about 30 minutes to give the graphs a chance to collect some data.

  1. Navigate to http://s10-nagios/nagios from a computer on the same LAN.
  2. Login using credentials previously specified.
  3. View the services page, and note that ping and other services should have graph icons next to them.
  4. Mouseover the icons, confirm that graphs are popping up.
  5. Click on the icons, verify that you are being led to the page that shows graphs.
Everything pass? Great – onward!

Monitoring Nagios / MRTG

So you now have Nagios running to ensure all your servers and gadgets are running as expected. But…how do you know that Nagios is healthy? We should monitor that too! We are going to use MRTG to graph stats about how Nagios is running.

[root]$ apt-get install mrtg

Copy the default config file for Nagios stats.

[root]$ cp ~/nagios/sample-config/mrtg.cfg /usr/local/nagios/etc/
[root]$ mkdir /usr/local/nagios/share/stats

Configure the working directory.

[root]$ vim /usr/local/nagios/etc/mrtg.cfg

Add this to the top.

WorkDir: /usr/local/nagios/share/stats

Make the initial run.

[root]$ env LANG=C mrtg /usr/local/nagios/etc/mrtg.cfg

Configure the HTML page.

[root]$ indexmaker /usr/local/nagios/etc/mrtg.cfg --output=/usr/local/nagios/share/stats/index.html

Create a scheduled cron job to keep the status up to date.

[root]$ vim /etc/cron.d/nagiostats
*/5 * * * *  root  env LANG=C /usr/bin/mrtg /usr/local/nagios/etc/mrtg.cfg

Checkpoint Three

Let’s pause a moment to verify we have not made any mistakes.

You may have to let Nagios run for about 30 minutes to give the graphs a chance to collect some data.

  1. Navigate to http://s10-nag-01/nagios/stats/ from a computer on the same LAN.
  2. Verify that you see a bunch of pretty graphs.
Everything pass? Great – onward!

Nagios Template Tweaks

There are several additions / tweaks that are recommended for a more efficient experience.

Set the default page to the services detail page (may want to limit results or show a different page on a large installation)

[root]$ vim /usr/local/nagios/share/index.php

Find where $corewindow is defined, and change it to something more useful.


Also lets add some links to the sidebar – specifically the graphs.

[root]$ vim /usr/local/nagios/share/side.php

Add this section wherever you see fit.

<div class="navsection">
<div class="navsectiontitle">External Tools</div>
<div class="navsectionlinks">
<ul class="navsectionlinks">
<li><a href="/nagios/stats" target="<?php echo $link_target;?>">Nagiostats</a></li>
<li><a href="/nagiosgraph/cgi-bin/show.cgi" target="<?php echo $link_target;?>">Nagiosgraph</a></li>


You now have a working base Nagios install. Now you are off to build your service checks, find more plugins, and tweak your alerts. I can almost feel your anticipation!

This entry was posted in Guides and tagged , on by .

About Andrew Wells

I have been developing on the LAMP stack since about 2006. I run Ubuntu XFCE on my desktop and have a history of managing Ubuntu and CentOS servers. I code web applications mostly in PHP but have experience with other languages as well. When I'm not working, I can be found working in my home lab or out snowboarding, hiking, camping, or biking depending on the season.

4 thoughts on “Nagios 3.x Install from Source on Ubuntu 12.04

  1. Sergio Lewin

    when running this command

    [root]$ apt-get install libnet-snmp-perl libperl5.14 libpq5 libradius1 libsensors4 libsnmp-base libsnmp15 libtalloc2 libtdb1 libwbclient0 samba-common samba-common-bin smbclient snmp whois libmysqlclient15-dev libssl-dev

    its replys that libperl5.14 could not be located

    and about libmysqlclient15-dev it tells me “note, selecting `libmysqlclient-de` instead of `libmysqlclient15-dev`


Leave a Reply

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