Raymii.org IEC Resistor logo

Quis custodiet ipsos custodes?
RSS Feed

Nagios Core 4.0.4 installation on Ubuntu 12.04

17-03-2014 | Remy van Elst

nagios 4

This is a guide on installing the latest Nagios Core (4.0.4) on Ubuntu 12.04. Nagios is an open source computer system monitoring, network monitoring and infrastructure monitoring software application. Nagios offers monitoring and alerting services for servers, switches, applications, and services. It alerts the users when things go wrong and alerts them a second time when the problem has been resolved. The version in the Ubuntu repositories is quite old, it is still the in the 3 branch. This guide helps to fix that by using the latest Nagios version.

This tutorial was written and tested on a DigitalOcean VPS. If you use this you sponsor me (referral link)

You can find more information about Nagios on the official website: http://www.nagios.org/projects/nagioscore.

The description of Nagios Core from their website:

Nagios Core is the monitoring and alerting engine that serves as the primary application around which hundreds of Nagios projects are built. It serves as the basic event scheduler, event processor, and alert manager for elements that are monitored. It features several APIs that are used to extend its capabilities to perform additional tasks, is implemented as a daemon written in C for performance reasons, and is designed to run native on Linux/*nix systems.


We are going to do the following:

  • Install required packages
  • Create the Nagios user
  • Download and Compile Nagios Core
  • Download and Compile the Nagios Plugins
  • Download and Compile NRPE
  • Setup the upstart script
  • Set up Apache

At the end of this tutorial you will have a fully up to date Nagios Core installation, with the latest plugins, the latest NRPE and the webinterface set up with authentication and ssl.

This was written and tested on Ubuntu 12.04, both 32 and 64 bit.

Whats new in Nagios Core 4?

Major performance increases:

  • Core Workers - Core workers are lightweight processes whose only job is to perform checks. Because they are smaller they spawn much more quickly than the the old process which forked the full Nagios Core. In addition, they communicate with the main Nagios Core process using in-memory techniques, eliminating the disk I/O latencies that could previously slow things down, especially in large installations.
  • Configuration Verification - Configuration verification has been improved so that each configuration item is verified only once. Previously configuration verification was an O(n2) operation.
  • Event Queue - The event queue now uses a data structure that has O(log n) insertion times versus the O(n) insertion time previously. This means that inserting events into the queue uses much less CPU than in Nagios Core 3.

Other nice changes:
- The host address attribute is now optional. The address attribute is set to the host name when it is absent. Most configurations set the host name attribute to the DNS host name making the address attribute redundant. - Both hosts and services now support an hourly value attribute. The hourly value attribute is intended to represent the value of a host or service to an organization and is used by the new minimum value contact attribute.- Services now support a parents attribute. A service parent performs a function similar to host parents and can be used in place of service dependencies in simple circumstances.

No more embedded perl:
- Embedded Perl - Embedded Perl has historically been the least tested and the most problem prone part of Nagios Core. A significant part of the issue is that there are so many versions of Perl available. The performance enhancements provided by the new worker process architecture make up for any performance loss due to the removal of embeddd Perl. In addition, the worker process architecture makes possible the implementation of a special purpose worker to persistently load and run Perl plugins. The following configuration variables that were related to embedded Perl have been obsoleted: useembeddedperlimplicitly, enableembeddedperl, p1file.

See this page for the full listing of new stuff in Nagios 4: http://nagios.sourceforge.net/docs/nagioscore/4/en/whatsnew.html

Note about currently installed Nagios versions

Make sure you remove all currently installed Nagios versions and packages. Better yet, start on a new empty server/vm.

Note about the plugins and NRPE

We are compiling the latest version of the plugins and NRPE on the Nagios Server. On the Nagios clients, you do not have to do this. The version of NRPE in the Ubuntu repositories works with this newer Nagios version. The same goes for the plugins.

Note about packages and checkinstall

We are using checkinstall here to create a debian package of the source we compile. I do this because it gives more flexibility in managing the software afterwards. Upgrading or uninstalling the packages is easier than removing all the things make install placed. Furthermore, it makes it more clear for other administrators which software is installed.

If you for example want to upgrade Nagios when it was installed via this tutorial with checkinstall, repeat the tutorial with only the version number changed.

Install required packages

Install the packages required for compilation, apache and mail functionality:

apt-get install apache2 libapache2-mod-php5 build-essential libgd2-xpm-dev libssl-dev sendmail-bin sendmail heirloom-mailx wget curl daemon apt-file libnet-snmp-perl libperl5.14 libpq5 libradius1 libsensors4 libsnmp-base libsnmp15 libtalloc2 libtdb1 libwbclient0 samba-common samba-common-bin smbclient snmp whois libmysqlclient15-dev

Create the Nagios user

Nagios runs as its own user and has its own groups. We need to create this user and groups. We also make sure the user Apache runs as can access the Nagios files by adding the www-data user to the nagios groups.

groupadd -g 3000 nagios
groupadd -g 3001 nagcmd
useradd -u 3000 -g nagios -G nagcmd -d /usr/local/nagios -c 'Nagios Admin' nagios
adduser www-data nagcmd

Download and Compile Nagios Core

If necessary, create /usr/local/src/nagios4:

mkdir -p /usr/local/src/nagios4

cd into /usr/local/src/nagios4:

cd /usr/local/src/nagios4

(I like to keep my source code and compilation files in one place).

Use wget to download the latest Nagios Core from sourceforge:

wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.4.tar.gz

Extract it:

tar xf nagios-4.0.4.tar.gz
cd nagios-4.0.4

Create a few folders:

mkdir -p /usr/local/nagios/share/{stylesheets,images}

Now start the compilation process. First configure:

./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-command-user=nagios --with-command-group=nagcmd

Output should look like this:

 General Options:
        Nagios executable:  nagios
        Nagios user/group:  nagios,nagios
       Command user/group:  nagios,nagcmd
             Event Broker:  yes
        Install ${prefix}:  /usr/local/nagios
    Install ${includedir}:  /usr/local/nagios/include/nagios
                Lock file:  ${prefix}/var/nagios.lock
   Check result directory:  ${prefix}/var/spool/checkresults
           Init directory:  /etc/init.d
  Apache conf.d directory:  /etc/apache2/conf.d
             Mail program:  /usr/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):  /usr/sbin/traceroute

Review the options above for accuracy.  If they look okay,
type 'make all' to compile the main program and CGIs.

Then the make process:

make all

Then the use checkinstall, for all the parts:

# This installs the main program, CGIs, and HTML files

In the depends section of the package, make sure to add libc6, perl. Name the package nagios4 and give it the correct version, namely 4.0.4. Repeat for all following packages created.

# This installs the init script in /etc/init.d
checkinstall --pkgname=nagios-init make install-init

# This installs *SAMPLE* config files in /usr/local/nagios/etc
checkinstall --pkgname=nagios-config make install-config

#This installs and configures permissions on the directory for holding the external command file
checkinstall --pkgname=nagios-commandmode make install-commandmode

# This installs the Apache config file for the Nagios web interface
checkinstall --pkgname=nagios-webconf make install-webconf

# This installs the Exfoliation theme for the Nagios web interface
checkinstall --install=no --pkgname=nagios-exfoliation make install-exfoliation
dpkg --force-overwrite -i nagios-exfoliation_4.0.3-1_amd64.deb

If this all goes well, we can continue to the next part.

Download and Compile the Nagios Plugins

Same as above. First create the right folders:

mkdir -p /usr/local/src/nagios-plugins
cd /usr/local/src/nagios-plugins

Download the files and untar them:

wget https://www.nagios-plugins.org/download/nagios-plugins-2.0.tar.gz
tar -xf nagios-plugins-2.0.tar.gz
cd nagios-plugins-2.0

Start the compile process:

./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl=/usr/bin/openssl --enable-perl-modules --enable-libtap

Then the make and make install:


Here again, make sure to set libc6, perl as dependencies, name it nagios-plugins and give it the correct version (2.0).

This should also go fine. Continue on to NRPE.

Download and Compile NRPE

NRPE allows you to remotely execute Nagios plugins on other Linux/Unix machines. This allows you to monitor remote machine metrics (disk usage, CPU load, etc.). NRPE can also communicate with some of the Windows agent addons, so you can execute scripts and check metrics on remote Windows machines as well.

Same steps as above. First create the right folders:

mkdir -p /usr/local/src/nrpe
cd /usr/local/src/nrpe

Download the files and extract:

wget http://kent.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz
tar -xf nrpe-2.15.tar.gz
cd nrpe-2.15

Because of an issue with the openssl library folder we need to use another path than /usr/lib:

./configure --with-ssl=/usr/bin/openssl --with-ssl-lib=/usr/lib/x86_64-linux-gnu

(If you run a 32 bit installation of Ubuntu you can find the right path using this command: apt-file search libssl | grep libssl-dev. You might need to install apt-file.)

Now make and make install:

make all

Same thing as above, require libc6, perl in the dependencies, name it correctly (nrpe) and give it the right version in checkinstall (2.15).

That part also finished. Continue on.

Setup the upstart script

The current init script which comes with Nagios Core 4.0.4 does not work with Ubuntu 12.04. See this stackoverflow topic: http://stackoverflow.com/questions/19606049/nagios-4-cant-open-etc-rc-d-init-d-functions.

The fixes in that topic and on the Nagios forum did not work for me, so I wrote a very simple upstart script.

Place it in /etc/init/nagios.conf:

# nagios - monitoriong system
# by https://raymii.org

description     "nagios monitoring system"

start on virtual-filesystems
stop on runlevel [06]

respawn limit 5 30
limit nofile 65550 65550

chdir /usr/local/nagios/
setuid nagios
setgid nagios
console log

        exec bin/nagios etc/nagios.cfg
end script

Don't forget to remove the init script:

mv /etc/init.d/nagios /var/backups/nagios.init

Set up Apache

First we set up a user account for the new nagios user:

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
chown nagios:nagcmd /usr/local/nagios/etc/htpasswd.users

Then we create a certificate. This is a self signed one, you can also request a certificate at a provider such as Digicert or Verisign.

mkdir /etc/apache2/ssl
cd /etc/apache2/ssl
a2enmod ssl
openssl req -x509 -nodes -days 365 -newkey rsa:4096 -out nagios.pem -keyout nagios.key

We also create a folder for nagios under /var/www:

mkdir -p /var/www/nagios4/
chown www-data:www-data /var/www/nagios4

Create some symlinks:

ln -s /usr/local/src/nagios4/nagios-4.0.4/contrib/exfoliation/images/favicon.ico /var/www/favicon.ico

Set up a vhost for Nagios. The below file can be used. Place it in /etc/apache2/sites-available/nagios:

    ServerAdmin webmaster@example.org
    ServerName nagios.example.org
    DocumentRoot /var/www/nagios

        Options FollowSymLinks
        AllowOverride None

        Options -Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all

     SSLEngine On
     SSLCertificateFile /etc/apache2/ssl/nagios.pem
     SSLCertificateKeyFile /etc/apache2/ssl/nagios.key

Remember to replace example.org with your domain.

Disable the default vhost:

a2dissite default

Enable the vhost:

a2ensite nagios

Restart apache:

/etc/init.d/apache2 restart

Now we are finished with the installation. Read on for some tweaks I like to make.


I like to have my config files in /etc/nagios4/conf.d. To do that, we create a symlink first:

ln -s /usr/local/nagios/etc/ /etc/nagios4

Then the conf.d folder:

mkdir /etc/nagios4/conf.d

Then add this to /etc/nagios4/nagios.cfg


I also like to separate my config in directories like so:



Create it like this:

mkdir -p /etc/nagios4/conf.d/{hosts,services,timeperiods,templates,hostgroups,servicegroups,contacts}

Remember to restart Nagios when you are finished:

service nagios restart

And the nagios is accessible at https://example.org/nagios, with username nagiosadmin and your chosen password.

Tags: apache, monitoring, nagios, nagios-core, nrpe, ubuntu,