Home   Profile   Fun
#156 Linux  07.01.2008

Nagios 3 installation tutorial for Gentoo


This tutorial explains the installation of Nagios 3.0rc2 from source on a Gentoo x86_64 AMD platform. It is derived from the official quickstart installation guide from www.nagios.org. You will need the GD libraries and the Apache web server as prerequisites. To run Nagios the Nagios core package must be installed together with the official Nagios plugins. After that the monitoring orgy can start.

To compile Nagios 3 we need the GD development libraries.
emerge -va gd

Then download the source for Nagios 3 and its official plugins.
cd /root
wget http://ovh.dl.sourceforge.net/sourceforge/nagios/nagios-3.0rc2.tar.gz
wget http://surfnet.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.11.tar.gz

We need a system account which is used to run the Nagios daemon
useradd nagios
passwd nagios
and a system group for Nagios which is used to run the external command CGIs from the Nagios web interface.
groupadd nagcmd

Then we add the nagios user and the Apache user to this group.
usermod -G nagcmd nagios
usermod -G nagcmd apache

Extract Nagios3 and the Nagios plugins.
tar xfvzp nagios-3.0rc2.tar.gz
tar xfvzp nagios-plugins-1.4.11.tar.gz

First Nagios will be installed then the plugins. By default the Nagios installation path is /usr/local/nagios/. If you want to install it into a different directory use --prefix=/your/path.
cd nagios-3.0rc2
./configure --with-command-group=nagcmd

Compile the Nagios source code.
make all

Install Nagios binaries.
make install

Install Nagios init scripts.
make install-init

Install sample configuration files.
make install-config

Set permissions of the external command directory.
make install-commandmode


We continue with some basic configuration. At least the Nagios admin email address should be changed to something valid. Nagios will send alerts to this address.
vi /usr/local/nagios/etc/objects/contacts.cfg

Look for the following lines (comments removed):
define contact{
  contact_name  nagiosadmin; 
  use                  generic-contact; 
  alias                 Nagios Admin; 

  email                nagios@localhost; 

and change nagios@localhost to your email address.


Now it's time to configure Apache for Nagios. I am using a vhost for Nagios. So I put the content of ./sample-config/httpd.conf inside the <VirtualHost> directive of my virtual host configuration in /etc/apache2/vhosts.d/mynagiosdomain.conf.

What is still needed is an account for the Nagios web interface which we call nagiosadmin. Not everybody should be allowed to see the monitoring information. The access to the web interface is protected through a htpasswd file which contains the data of valid Nagios users. There will be no .htaccess file. Instead the information has already been inserted directly into the Apache vhost configuration. It is a part of the sample-config/httpd.conf file.
Create the htpasswd.users file and add a record for the user nagiosadmin.
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Restart the web server.
/etc/init.d/apache2

Nagios itself is a container for the actual checks. These checks are done by the Nagios plugins. Without them Nagios cannot monitor anything. So the next step is to compile and install these plugins.
cd ../nagios-plugins-1.4.11
./configure --with-nagios-user=nagios --with-nagios-group=nagios
Usually you get some warnings about missing software, e.g.
...
checking for smbclient... no
configure: WARNING: Get smbclient from Samba.org to monitor SMB shares
...
Depending on which services you want to monitor you have to install additional software and run configure again.

Compile and install the Nagios plugins.
make
make install

Add the Nagios daemon to the default runlevel.
rc-update add nagios default

Before we start Nagios with the sample configuration files as a daemon we start it in foreground to check for errors.
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Then finally start Nagios with the init script and make sure that it's running.
/etc/init.d/nagios start
ps aux | grep nagios


Now you can log in to the Nagios weg page. The page must be password protected. Use nagiosadmin along with the password you have set before.
http://mynagiosdomain/nagios

nagios 3 main page screenshot

If you click on "Service Detail" you can see the preconfigured checks for the local machine from the sample configuration files.

nagios 3 service detail screenshot

I would recommend to study the official Nagios documentation now. The configuration is too complex for trial and error. It will save you a lot of time in the future.


Nagios and Cacti
Nagios Training