How to install Nagios in ubuntu 9.x and 10.x

by
Share this Article: Facebook0Google+2Twitter202LinkedIn1Reddit0StumbleUpon0

Nagios is a popular open source computer system and network monitoring software application. It watches hosts and services, alerting users when things go wrong and again when they get better.

 

Nagios was originally designed to run under Linux, but also runs well on other Unix variants. It is free software, licensed under the terms of the GNU General Public License version 2 as published by the Free Software Foundation.

Before to start, if you want to install Nagios in fedora ,RHEL or centos please read our previous tutorial

 

I- Install Apache, PHP  and  some  needed  libraries

First we will install apache , php and needed librairies

  • Install some necessary compilers using the command :
sudo  apt-get install build-essential

  • Install GD Libraries using the command :
sudo apt-get install libgd2-xpm-dev

  • Install Apache2
sudo apt-get install apache2
 
  • Install PHP for  apache 2 :
sudo apt-get install php5-common php5 libapache2-mod-php5

Now configure Apache to use PHP:

Open apache2.conf file

sudo vi   /etc/apache2/apache2.conf 

and  add this line

DirectoryIndex index.html index.php index.cgi

Now  restart  your   apache

sudo  /etc/init.d/apache2   restart

II- Install and Configure Nagios :

Now  lets  install  and  configure   Nagios

First download  the latest  core  nagios  from nagios  website and before  installing create a user to run the service and a group to run external commands:

 * sudo useradd -m nagios
 * sudo passwd nagios
 * sudo groupadd nagcmd
 * sudo usermod -a -G nagcmd nagios
 * sudo usermod -a -G nagcmd www-data

Now install the Nagios tarballs that were downloaded previously:

tar -zxvf nagios-3.2.1.tar.gz 

Then cd the the extracted folder and install

cd nagios-3.2.1
sudo ./configure --with-command-group=nagcmd
sudo make all
sudo make install
sudo make install-init
sudo make install-config
sudo make install-commandmode
sudo make install-webconf
 

Add a user for the Nagios interface:

sudo  mkdir  /usr/local/nagios/etc

Create a new password

sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Output

New password:
Re-type new password:
pirat9@pirat9-desktop:~/Downloads/nagios-3.2.1$

Now add  Nagios directory to apache, first open apache.conf :

sudo vi /etc/apache2/apache.conf

and  add these lines :

ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin

Options ExecCGI

AllowOverride None

Order allow,deny

Allow from all

AuthType Basic

AuthUserFile /usr/local/nagios/etc/htpasswd.users

Require valid-user

Alias /nagios /usr/local/nagios/share

Options None

AllowOverride None

Order allow,deny

Allow from all

AuthType Basic

AuthUserFile /usr/local/nagios/etc/htpasswd.users

Require valid-user

save and exit then restart apache2


sudo  /etc/init.d/apache2 restart

Install Nagios Plugins :

tar -zxvf  nagios-plugins-1.4.14.tar.gz 
 
  • Cd the extracted folder and install the plugins
 cd nagios-plugins-1.4.14
 sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios
sudo make 
sudo make install
  • Create a link to start the service:

sudo ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios
 
ls -altr

Output

total 20

-rw-r–r–   1 root root   447 2009-09-07 20:58 README

lrwxrwxrwx   1 root root    20 2010-04-04 22:10 S70x11-common -> ../init.d/x11-common

lrwxrwxrwx   1 root root    24 2010-04-04 22:10 S70screen-cleanup -> ../init.d/screen-cleanup

lrwxrwxrwx   1 root root    17 2010-04-04 22:10 S55urandom -> ../init.d/urandom

lrwxrwxrwx   1 root root    23 2010-04-04 22:10 S49console-setup -> ../init.d/console-setup

lrwxrwxrwx   1 root root    18 2010-04-04 22:10 S37apparmor -> ../init.d/apparmor

lrwxrwxrwx   1 root root    16 2010-04-04 22:10 S25brltty -> ../init.d/brltty

lrwxrwxrwx   1 root root    21 2010-04-04 22:10 S13pcmciautils -> ../init.d/pcmciautils

lrwxrwxrwx   1 root root    24 2010-04-04 22:10 S06keyboard-setup -> ../init.d/keyboard-setup

drwxr-xr-x 132 root root 12288 2010-04-15 01:45 ..

lrwxrwxrwx   1 root root    18 2010-04-15 02:09 S99nagios -> /etc/init.d/nagios

drwxr-xr-x   2 root root  4096 2010-04-15 02:09 .

 

Please before running the configuration check and copy all config files from your nagios directory to /usr/local/nagios/etc/objects/ and /usr/local/nagios/etc/

like

config file ‘/usr/local/nagios/etc/objects/commands.cfg’…

object config file ‘/usr/local/nagios/etc/objects/contacts.cfg’…

object config file ‘/usr/local/nagios/etc/objects/timeperiods.cfg’…

object config file ‘/usr/local/nagios/etc/objects/templates.cfg’…

object config file ‘/usr/local/nagios/etc/objects/localhost.cfg’…


  • Verify the config:

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

Output :

Nagios Core 3.2.1

Copyright (c) 2009-2010 Nagios Core Development Team and Community Contributors

Copyright (c) 1999-2009 Ethan Galstad

Last Modified: 03-09-2010

License: GPL

Website: http://www.nagios.org

Reading configuration data…

Read main config file okay…

Processing object config file ‘/usr/local/nagios/etc/objects/commands.cfg’…

Processing object config file ‘/usr/local/nagios/etc/objects/contacts.cfg’…

Processing object config file ‘/usr/local/nagios/etc/objects/timeperiods.cfg’…

Processing object config file ‘/usr/local/nagios/etc/objects/templates.cfg’…

Processing object config file ‘/usr/local/nagios/etc/objects/localhost.cfg’…

Read object config files okay…

Running pre-flight check on configuration data…

Checking services…

Checked 8 services.

Checking hosts…

Checked 1 hosts.

Checking host groups…

Checked 1 host groups.

Checking service groups…

Checked 0 service groups.

Checking contacts…

Checked 1 contacts.

Checking contact groups…

Checked 1 contact groups.

Checking service escalations…

Checked 0 service escalations.

Checking service dependencies…

Checked 0 service dependencies.

Checking host escalations…

Checked 0 host escalations.

Checking host dependencies…

Checked 0 host dependencies.

Checking commands…

Checked 24 commands.

Checking time periods…

Checked 5 time periods.

Checking for circular paths between hosts…

Checking for circular host and service dependencies…

Checking global event handlers…

Checking obsessive compulsive processor commands…

Checking misc settings…

Total Warnings: 0

Total Errors:   0

Things look okay – No serious problems were detected during the pre-flight check

pirat9@pirat9-desktop:~/Downloads/nagios-3.2.1$

  • Now start Nagios:

sudo /etc/init.d/nagios start

 

  • Now you are ready to use Nagios, open your browser and type :
   http://hostname/nagios or http://ip/nagios  



{loadposition user9}

Related Articles By Tags:

{loadposition user1}

For questions please refer to our Q/A forum at : http://ask.unixmen.com/

Share this Article: Facebook0Google+2Twitter202LinkedIn1Reddit0StumbleUpon14