Nagios Installation and Configuration

Nagios Installation in Ubuntu

Required Packages

Install the following packages on  Ubuntu installation before continuing.

  • Apache 2
  • PHP
  • GCC compiler and development libraries
  • GD development libraries

If not installed, using apt-get the above  packages can be installed as follows

  • sudo apt-get install apache2
  • sudo apt-get install libapache2-mod-php5
  • sudo apt-get install build-essential
  • sudo apt-get install libgd2-xpm-dev

Create Account Information

  • Become the root user.
    sudo -s
  • Create a new nagios user account and give it a password.

/usr/sbin/useradd -m -s /bin/bash nagios

passwd nagios

  • Create a new nagcmd group for allowing external commands to be submitted through the web interface. Add both the nagios user and the apache user to the group.

/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -a -G nagcmd nagios
/usr/sbin/usermod -a -G nagcmd www-data

Download Nagios and the Plugins

Create a directory for storing the downloads.

  • mkdir /opt/downloads
  • cd /opt/downloads

Download the source code tarballs of both Nagios and the Nagios plugins (visit http://www.nagios.org/download/ for links to the latest versions).

  • wget -c http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.0.tar.gz
  • wget -c http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.11.tar.gz

Compile and Install Nagios

Extract the Nagios source code tarball.

  • cd /opt/downloads
  • tar xzvf nagios-3.2.0.tar.gz
  • cd nagios-3.2.0

Run the Nagios configure script, passing the name of the group you created earlier like so:

  • ./configure –with-command-group=nagcmd

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
General Options:
————————-
Nagios executable:  nagios
Nagios user/group:  nagios,nagios
Command user/group:  nagios,nagcmd
Embedded Perl:  no
Event Broker:  yes
Install ${prefix}:  /usr/local/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):
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Compile the Nagios source code.

  • make all

Install binaries, init script, sample config files and set permissions on the external command directory.

  • sudo make install

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can continue with installing Nagios as follows (type ‘make’
without any arguments for a list of all possible options):

make install-init
– This installs the init script in /etc/init.d

make install-commandmode
– This installs and configures permissions on the
directory for holding the external command file

make install-config
– This installs sample config files in /usr/local/nagios/etc
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  • sudo make install-init

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/install -c -m 755 -d -o root -g root /etc/init.d
/usr/bin/install -c -m 755 -o root -g root daemon-init /etc/init.d/nagios

*** Init script installed ***
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  • sudo make install-config

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/cgi.cfg /usr/local/nagios/etc/cgi.cfg
/usr/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg /usr/local/nagios/etc/objects/templates.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/commands.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg

*** Config files installed ***

Remember, these are *SAMPLE* config files.  You’ll need to read
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  • sudo make install-commandmode

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/install -c -m 775 -o nagios -g nagcmd -d /usr/local/nagios/var/rw
chmod g+s /usr/local/nagios/var/rw

*** External command directory configured ***
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Don’t start Nagios yet – there’s still more that needs to be done…

Nagios Configuration

Sample Configuration files are available in the path

  • /usr/local/nagios/etc/
  • /usr/local/nagios/etc/objects/

a)  Configuration1: Basic Contact Info

The first components to set up are contacts and contact groups.
Contacts are people who receive notifications when a host or service is down. Nagios offers pager and e-mail notifications by default.

Contacts are stored in the /usr/local/nagios/etc/objects/contacts.cfg file and are defined as follows:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~“
define contact{
contact_name                    gama            ; Short name of user
use                             generic-contact         ; Inherit default values from generic-contact template (defined in templates.cfg) – Commented out
alias                           Nagios Admin           ; Full name of user

email                           gama@actsupport.com   ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}

define contactgroup{
contactgroup_name       admins
alias                   Nagios Administrators
members                 rama
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Create the following files – hosts.cfg and hostgroups.cfg. From the templates.cfg file, we shall get he template definitions for server “linux-server”

b) sudo vi /usr/local/nagios/etc/objects/hosts.cfg (new config file)

For every host added for monitoring, an entry needs to be put in the hosts.cfg file. An example is illustrated below, for host 10.10.36.199

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

define host{
host_name              EastColo-TestWeb
use                    linux-server
alias                  East Colo Test Web
address                10.10.36.199
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

c) sudo vi /usr/local/nagios/etc/objects/hostgroups.cfg

The host added in hosts.cfg must be made part of a hostgroup. For example, the host 10.10.36.199, is being made part of hostgroup, TestWeb. We can add as many hosts we want in a hostgroup. Each hostgroup member need to be seperated by a comma(,).

define hostgroup {
hostgroup_name TestWeb
alias          Test Web Servers
members        EastColo-TestWeb,WestColo-TestWeb
}

d) Now according to the service to be monitored for each host, an entry for each host or hostgroup need to be made in /usr/local/nagios/etc/objects/localhost.cfg.

define service{
use                             local-service         ; Name of service template to use
host_name                       localhost
hostgroup_name                  TestWeb
service_description             PING
check_command           check_ping!100.0,20%!500.0,60%
}

e) Edit the main configuration file, “nagios.cfg” under the directory /usr/local/nagios/etc/

Add the  lines

cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/hostgroups.cfg

f)  Check if the Nagios Configuration files are ok, using the command
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Configure the Web Interface – Apache Configuration

a)  cd /opt/downloads/nagios-3.2.0

b)  Install the Nagios web config file in the Apache conf.d directory.
sudo make install-webconf
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/conf.d/nagios.conf

*** Nagios/Apache conf file installed ***
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

c) Create a nagiosadmin account for logging into the Nagios web interface. Remember the password you assign to this account – you’ll need it later.
$ htpasswd -c /usr/local/nagios/etc/htpasswd.users nagadmin

d) Restart Apache
$ sudo /etc/init.d/apache2 reload

Compile and Install the Nagios Plugins
—————————————–

  • cd /opt/downloads/nagios-3.2.0
  • tar xzvf nagios-plugins-1.4.11.tar.gz
  • cd nagios-plugins-1.4.11
  • ./configure –with-nagios-user=nagios –with-nagios-group=nagios
  • make
  • sudo make install

This will install all the nagios plugin scripts under the path “/usr/local/nagios/libexec

Configure Nagios to automatically start when the system boots

  • ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios

Start Nagios

a) Verify the configuration files of Nagios

  • sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

b) If there are no errors, start Nagios.

  • sudo /etc/init.d/nagios start