Nagios Monitoring System Quick Setup Guide

You can use the open-source Nagios monitoring software as a low-cost solution to monitor your hosts and services.

In our opinion, Nagios can be divided into three components. The first one is the daemon that runs in the background scheduling checks, storing check results and etc. The second one is the Web interface that gives you all the information about your hosts and services. It contacts the daemon to get the states of various hosts and services and can accept commands from users to enable/disable certain checks and notifications and etc. The third component is the various plugins that actually do the checks and return the results in a format that is recognizable by the daemon.

In this article, we describe how to setup Nagios as a non-root user in a Linux environment. By using the least privileges, you can reduce the risk of interrupting any existing services. Suppose your user name is joe and user group users.

First you can download the latest nagios and nagios-plugins packages. At the time of writing, nagios' version is 3.0.4 and nagios-plugins' is 1.14.13. Unpack them from the same directory and you will have the two nagios-3.0.4/ and nagios-plugins-1.4.13/ directories created.

Now go into the nagios-3.0.4/ directory, configure, compile and install the daemon and default configurations with the following commands:

cd nagios-3.0.4/
./configure --with-nagios-user=joe --with-nagios-group=users --prefix=/opt/dev/nagios
# Builds Nagios daemon and CGI programs
gmake all
# Install Nagios daemon and CGI programs
gmake install
# Install Nagios sample configuration files
gmake install-config

Please adapt the user name, user group and the directory to your local environment. We prefer to keep all Nagios files in one directory so upgrade can be done more easily later.

Next you can copy the sample Nagios configuration file for Apache to your local Apache server's configuration directly. Please note that this configuration file is different from the ones we installed earlier with the command gmake install-config. If you have followed our guide on creating a local LAMP (Linux, Apache, MySQL and PHP/Perl) development environment, then the configuration file's location is /opt/dev/apache/conf and you can run the following command:

# Assume you are in the source directory nagios-3.0.4/
cp sample-config/httpd.conf /opt/dev/apache/conf/nagios.conf

Then you need to modify the main Apache configuration file /opt/dev/apache/conf/httpd.conf to include the additional Nagios' configuration file for Apache. You can just add the following line to the end of the httpd.conf file:

Include conf/nagios.conf

Now it is the time to install the Nagios plugin package which is used by the Nagios daemon to do all the checks. You need to tell it where Nagios is installed so the plugins will be installed in the right place and Nagios configuration files can reference them correctly. In addition, some plugins may require extra packages be installed on your box. For example, if you want to install some plugins that check MySQL server, then you need to tell it where to find the MySQL header and library files installed on your system.

Assuming you have MySQL installed on /opt/dev/mysql, then you can run the following commands to configure, compile and install the plugins package.

export NAGIOS=/opt/dev/nagios
./configure --prefix=$NAGIOS --with-mysql=/opt/dev/mysql
gmake
gmake install

From now on, we just use $NAGIOS to reference the Nagios installation directory. Next you need to create the $NAGIOS/var/rw/ directory in which Nagios will create the pipe file nagios.cmd to communicate with outside programs including Nagios CGI programs. Most of the time Nagios can just receive commands through the pipe.

Now you can verify the default Nagios configuration file with the -v flag.

$NAGIOS/bin/nagios -v $NAGIOS/etc/nagios.conf

You may need to change the default configuration file to provide a numeric value for the time_change_threshold configuration variable. You can use 900 which is the default value. After verifying the configuration file, you can start Nagios.

$NAGIOS/bin/nagios $NAGIOS/etc/nagios.conf

Before using the Nagios Web interface, you also need to create the $NAGIOS/etc/htpasswd.users file to store the user names and passwords for accessing the Web interface. The default Nagios configuration file for Apache uses HTTP Basic Authentication and we can just use that for testing purpose.

In the default Nagios configuration files, only the nagiosadmin user can access all the features provided through the Web interface, so you need to create this user or update the configuration file to reference the username you want to use. Then you can run the following command to create the nagiosadmin user and set its password:

htpasswd -c $NAGIOS/etc/htpasswd.users nagiosadmin

The resulting file looks like this:

nagiosadmin:HEkU/1L8lQU/U

Now restart Apache and point your favorite browser to http://<host>:<port>/nagios/ and after logging in as user nagiosadmin, you should see Nagios up and running. Now you should be able to explore all the features that Nagios has provided confidently given that you have a basic setup working.

References

Back to articles on management