How to Install Nagios


  1. Nagios Installation

1.1  Install Apache, PHP and libraries

  • 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

 

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

1.2  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

 

  • Install the Nagios tarballs that were downloaded previously:

tar -zxvf nagios-3.2.1.tar.gz

 

  • Navigate to 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 will be like this:

New password: <your password>
Re-type new password: <your password>
  

  • Add  Nagios directory to apache, open apache.conf :

sudo vi /etc/apache2/apache.conf

 

And add the following 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 from the VI editor,  then restart apache2,

sudo  /etc/init.d/apache2 restart

 

1.3  Install Nagios Plugins

tar -zxvf  nagios-plugins-1.4.14.tar.gz  

 

  • Navigate to 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 symbolic link to start the service:

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

ls –altr

 

Output will be like this..

 d-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    18 2010-04-15 02:09 S99nagios -> /etc/init.d/nagios

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

 

  • Copy all the config file from /usr/local/nagios/etc/objects/ to  /usr/local/nagios/etc/

(config files -> commands. contacts.cfg, timeperiods.cfg, templates.cfg &localhost.cfg)

sudo cp /usr/local/nagios/etc/objects/*.cfg to /usr/local/nagios/etc/

ls –altr

 

  • Verify the Configuration

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

Output will be like this:

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

 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…..

.

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

1.4  Start Nagios

sudo /etc/init.d/nagios start

1.5  Access the Nagios to Monitor Resources

  http://localhost/nagios

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s