Table of Contents

Setup Nagios

This Howto explains how to set up nagios, so you can monitor your server.

1. Install the nagios package

At first, you have to install the nagios2 package:

# apt-get update && apt-get install nagios2

2. Create the necessary files and directories for the webinterface

You can't use the default apache-config-file which comes with nagios, because in ispCP, Websites have to be under /var/www.

So you have to create a directory there, /var/www/nagios and copy the contents of /usr/share/nagios2/htdocs into this directory.

# mkdir -p /var/www/nagios/htdocs
# cp -R /usr/share/nagios2/htdocs/* /var/www/nagios/htdocs/

This directory has to be owned by the www-data - User:

# chown -R www-data.www-data /var/www/nagios

Now you can create a file /etc/apache2/sites-available/nagios2.conf with the following content:

#
# nagios Virtual Host Webinterface
#

<VirtualHost xxx.xxx.xxx.xxx:80>                           <-- insert your IP here
        ServerAdmin     admin@yourdomain.com               <-- insert your mail adress here
        DocumentRoot    /var/www/nagios/htdocs

        ServerName      nagios.yourdomain.com              <-- insert your domain here

        ErrorLog        /var/log/apache2/nagios.yourdomain.com-error.log  <-- dito
        CustomLog       /var/log/apache2/nagios.yourdomain.com-access.log combined  <-- dito

        ScriptAlias /cgi-bin/nagios2 /var/www/nagios/cgi-bin
        ScriptAlias /nagios2/cgi-bin /var/www/nagios/cgi-bin

        <Directory /var/www/nagios>
                Options FollowSymLinks

                DirectoryIndex index.html

                AllowOverride AuthConfig
                Order Allow,Deny
                Allow From All

                AuthName "Nagios Access"
                AuthType Basic
                AuthUserFile /etc/nagios2/htpasswd.users
                require valid-user
        </Directory>

        <Directory "/usr/lib/cgi-bin/nagios2">
                Options ExecCGI

                AllowOverride None
                Order allow,deny
                Allow from all

                AuthName "Nagios Access"
                AuthType Basic
                AuthUserFile /etc/nagios2/htpasswd.users
                Require valid-user
        </Directory>

</VirtualHost>

and enabled it via

# a2ensite nagios2.conf

In order to be able to run a subdomain like nagios.yourdomain.com you have to edit the files /etc/apache2/sites-available/ispcp.conf and /etc/ispcp/apache/working/ispcp.conf, go to the vhost-section of yourdomain.com and delete the *.yourdomain.com in this line:

ServerAlias     www.yourdomain.com yourdomain.com *.yourdomain.com

After all this, you have to reload the apache configuration:

# /etc/init.d/apache2 reload

3. Change the nagios configuration

In the file /etc/nagios2/cgi.cfg you have to change the values physical_html_path and url_html_path as shown below:

physical_html_path=/var/www/nagios/htdocs
url_html_path=/

4. Create password file for nagios

Now you have to create a password file for nagios which has to be placed under /etc/nagios2/htpasswd.users:

# htpasswd -c /etc/nagios2/htpasswd.users nagiosadmin
New password:
Re-type new password:

5. Finished

Now, you should be able to access nagios via http://nagios.yourdomain.com, login with the username nagiosadmin and the password specified under 4.

The nagios configuration is done under /etc/nagios2/, you find the nagios documentation here: http://nagios.sourceforge.net/docs/2_0/