Installing Nagios

by Oktay Altunergil

What is Nagios?

"Nagios is a system and network monitoring application. It watches hosts and services that you specify, alerting you when things go bad and when they get better" (from This is the same tool that used to be called NetSaint until recently. Although the NetSaint site is still up, all future development will be done on Nagios.

Nagios has an impressive list of features that include:

Nagios runs on Unix and its variants and optionally requires a Web server to be installed (for the Web interface).

Installing and Configuring Nagios

Download the latest Nagios package and the latest Nagios plugins to a temporary location. For this article we will be using ~/tmp/nagios.

root@ducati:~/tmp/nagios# ls  
nagios-1.0b5.tar.gz  nagiosplug-1.3-beta1.tar.gz

First we will install the main Nagios application. Start by decompressing the tar.gz archive.

root@ducati:~/tmp/nagios# tar xfvz nagios-1.0b5.tar.gz

This will decompress the archive and we will end up with a nagios-1.0b5 directory. (The filename and the name of the directory created will differ, depending on when and which version you download.) Go into this new directory:

root@ducati:~/tmp/nagios# cd nagios-1.0b5 

At this point, we need to decide where on our system we want to install Nagios. You can install Nagios anywhere, but the best approach to selecting the location is to stick with the default installation directory (/usr/local/nagios), because the documentation always refers to this directory. This will make it easier to solve problems that we might have.

Create the directory where you would like to install Nagios.

root@ducati:~/tmp/nagios/nagios-1.0b5# mkdir /usr/local/nagios

At this point, we need to create a user and a group that our Nagios application will run as. You can use "root" for this purpose, but since it's not required, we might as well not use it, for better security. In order to make maintaining Nagios easier, we will dedicate a new username and group to it. The user and the group that we will create are both called "nagios."

root@ducati:~/tmp/nagios/nagios-1.0b5# useradd nagios

If you don't have the useradd command on your system, try the adduser command. On some systems, adduser is an interactive command that expects you to answer a few questions before creating the account. Please refer to the man page for the command you're using for more information.

root@ducati:~/tmp/nagios/nagios-1.0b5# groupadd nagios

On some systems, adduser will create the matching group; on other systems you will need to edit the /etc/group file to add the group by hand. Please refer to the documentation on your system for more information.

Once we have created the user and the group, we can now start the actual installation process. First we need to specify some parameters and create the Makefile that will be used to compile and install the software.

Type the following script on a single line without line breaks:

root@ducati:~/tmp/nagios/nagios-1.0b5# ./configure --prefix=/usr/local/nagios 
--with-cgiurl=/nagios/cgi-bin --with-htmurl=/nagios/ --with-nagios-user=nagios 

Related Reading

The Networking CD Bookshelf
By O'Reilly Media, Inc.

If you have opted to install Nagios in /usr/local/nagios and the user and group you have created are both "nagios," you might as well just run ./configure with no parameters, since the above values are the default values configure will assume. You can also run configure --help to see a lot more options you can use.

Once configure completes, it will display a summary of all parameters that were used during the configuration. Make sure everything is OK, and run configure again with the correct options, if necessary.

There's also a very high chance of getting a warning about the lack of GD libraries from Boutell. You can go back and install GD if it's not installed. If you already have it on your system and configure can't find it, you can use the --with-gd-lib and --with-gd-inc options to specify the exact directories where your gd include and library files are located. If, after trying all of these, you're still getting the warning about GD, the configuration script suggests just giving up on using the components that require GD and living with it. I believe this is a good approach if you're installing Nagios for the first time. The GD library is only used in a few CGIs that create dynamic images from the service statistics. The application is still very useful without these graphics. You can always go back and reinstall the application when you're more comfortable with GD and Nagios.

Now it's time to actually compile the software. This is done as follows (if you're not logged in as "root," you need to switch to the "root" user at this point):

root@ducati:~/tmp/nagios/nagios-1.0b5# make all

This step will take a while to complete, especially on a slower machine. If there were no problems during the compilation, you will receive a "Compile finished" notification. Right now, all of our software is compiled and ready to be installed to the directories that we have specified in configure.

We will run three install commands to install various components in place. First we need to install the main program files and directories in /usr/local/nagios. This step is required.

root@ducati:~/tmp/nagios/nagios-1.0b5# make install

Now, optionally, we can install the startup script so that Nagios starts automatically at boot time. This script will also allow us to start, stop, restart, and reload Nagios conveniently. This is accomplished as follows:

root@ducati:~/tmp/nagios/nagios-1.0b5# make install-init

On my system (which is running Slackware 8.0), this installs a nagios script in /etc/rc.d. Depending on your distribution, this file might also be installed in /etc/rc.d/init.d/. The configurator should take care of this. On my system, I have renamed this file to rc.nagios, which conforms better to the naming structure for Slackware. On FreeBSD, the file would need to live in /usr/local/etc/rc.d and be renamed for it to work properly.

If you take a look into the /usr/local/nagios directory right now, you will see that there are four directories.

root@ducati:~/tmp/nagios/nagios-1.0b5# ls /usr/local/nagios/          
bin  sbin  share  var

The bin directory contains a single file, nagios, that is the core of the package. This application does the actual monitoring. The sbin directory contains the CGI scripts that will be used in the Web-based interface. Inside of the share directory, you can find the HTML files and documentation. Finally, the var directory is where Nagios will be storing its information, once it starts running.

In order to be able to use Nagios, we need a couple of configuration files. These files go into the etc directory, which will be created when you run the following:

root@ducati:~/tmp/nagios/nagios-1.0b5# make install-config

This command also creates a sample copy of each required configuration file and puts them into the etc directory.

Plugins Installation

At this point the Nagios installation is complete. However, it is not very useful at its current state, because it lacks the actual monitoring applications. These applications, the duty of which is to check whether a particular monotired service is functioning properly, are called plugins. Nagios comes with a default set of such plugins, but they have to be downloaded and installed seperately. (Please visit the Nagios Web site for the latest download URL.)

Download the latest Nagios Plugins package and decompress it. You will need to run the configure script that is provided in order to prepare the package for compilation on your system. You will find that that the plugins are installed in a fashion similar to the actual Nagios program. Once again, you can just run configure if you are OK with the default settings for the username, group, and directory where Nagios is installed.

Type the following script on a single line:

root@ducati:~/tmp/nagios/nagiosplug-1.3-beta1# ./configure 
--prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios

You might get notifications about missing programs or Perl modules while configure is running. These are mostly OK, unless you specifically need the mentioned application to monitor a service.

Once configure is complete, compile all of the plugins.

root@ducati:~/tmp/nagios/nagiosplug-1.3-beta1# make all

If no errors were reported, you are ready to install the plugins.

root@ducati:~/tmp/nagios/nagiosplug-1.3-beta1# make install

The plugins will be installed in the libexec directory of your Nagios base directory (/usr/local/nagios/libexec, in my case).

root@ducati:~/tmp/nagios/nagiosplug-1.3-beta1# cd /usr/local/nagios/libexec/

There are a few rules that all Nagios plugins should implement, making them suitable for use by Nagios. All plugins provide a --help option that displays information about the plugin and how it works. This feature helps a lot when you're trying to monitor a new service using a plugin you haven't used before.

For instance, to learn how the check_ssh plugin works, run the following command.

root@ducati:/usr/local/nagios/libexec# ./check_ssh -h 
check_ssh (nagios-plugins 1.3.0-alpha1) 
The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute 
copies of the plugins under the terms of the GNU General Public License. 
For more information about these matters, see the file named COPYING. 
Copyright (c) 1999 Remi Paulmier ( 

 check_ssh -t [timeout] -p [port] <host> check_ssh -V prints version info 
 check_ssh -h prints more detailed help 
by default, port is 22 

This shows us that the check_ssh plugin accepts one required parameter host, and two optional paramters, timeout and port.

There's nothing especially complicated about the plugins. In fact, you can run the plugins manually to check services on the console.

root@ducati:/usr/local/nagios/libexec# ./check_ssh 
SSH ok - protocol version 1.99- - server version 

Nagios Post-Install Configuration

Now that both Nagios and the plugins are installed, we are almost ready to start monitoring our servers. However, Nagios will not even start before we configure it properly.

Let's start by taking a look the sample configuration files.

root@ducati:~/tmp/nagios# cd /usr/local/nagios/etc 
root@ducati:/usr/local/nagios/etc# ls -1

Since these are sample files, the Nagios authors added a .cfg-sample suffix to each file. First, we need to copy or rename each one to *.cfg, so that the software can use them properly. (If you don't change the configuration filenames, Nagios will still try to access them with the .cgi extension, and not be able to find them. The authors must have wanted to ensure that everyone create their own custom configuration files.)

Before renaming the sample files, I like to take a backup of them, just in case I need to refer to them later.

root@ducati:/usr/local/nagios/etc# mkdir sample 
root@ducati:/usr/local/nagios/etc# cp *.cfg-sample sample/

You can either rename each file manually, or use the following command to take care of them all at once.

Type the following script on a single line:

root@ducati:/usr/local/nagios/etc# for i in *cfg-sample; do mv $i 
`echo $i | sed -e s/cfg-sample/cfg/`; done;

The following is what you should end up with in the etc directory.

root@ducati:/usr/local/nagios/etc# ls -1 

First we will start with the main configuration file, nagios.cfg. You can pretty much leave everything as is, becasue the Nagios installation process will make sure the file paths used in the configuration file are correct. There's one option, however, that you might want to change. The check_external_commands is set to 0 by default. If you would like to be able to change the way Nagios works, or directly run commands through the Web interface, you might want to set this to 1. There are still some other options you need to set in cgi.cfg to configure which usernames are allowed to run external commands.

In order to get Nagios running, you will need to modify all but a few of the sample configuration files. Configuring Nagios to monitor your servers is not as difficult as it looks; I have found that the best approach to configuring Nagios properly the first time is to use the debugging mode of the Nagios binary. You can run Nagios in this mode by running:

root@ducati:/usr/local/nagios/etc# ../bin/nagios -v nagios.cfg

This command will go through the configuration files and report any errors that were found. Start fixing the errors one by one, and run the command again to find the next error. For our purposes, I will disable all hosts and services definitions that come with the sample configuration files and merely use the files as templates for our own hosts and services. We will keep most of the files as is, and remove the following (we will create them from scratch):


We will not be going into the more advanced configuration that requires using dependencies.cfg and escalations.cfg, so just remove these two files so that the sample configuration in these do not stop Nagios from starting up. Still, Nagios requires that these files are present in the etc directory, so create two empty files and name them dependencies.cfg and escalations.cfg by running the following as root.

root@ducati:/usr/local/nagios/etc# touch dependencies.cfg 
root@ducati:/usr/local/nagios/etc# touch escalations.cfg

We now have all of the configuration files we need and are ready to start configuring them to suit our monitoring needs. In my next article, I will cover the configuration file basics, how to define services to be monitored, how to configure Nagios to notify people when a service is down, and how to configure and use the Web interface that comes with Nagios.

Until then, Happy Hacking.

Web Resources:

Official Nagios Web Site:
Official NetSaint Web Site:
Nagios Plugins:
Nagios ScreenShots:
htpasswd man Page:

Oktay Altunergil works for a national web hosting company as a developer concentrating on web applications on the Unix platform.

Return to

Copyright © 2017 O'Reilly Media, Inc.