You are on page 1of 15

NAGIOS INSTALLATION

Contents

Description

Requiered Packages
Procedure
1) Scope
2) Create Account Information
3) Download Nagios and the Plugins
4) Compile and Install Nagios
5) Customize Configuration
6) Configure the Web Interface
7) Compile and Install the Nagios Plugins
8) Start Nagios
9) Login to the Web Interface
10)Other Modifications
11)add windows Machines to monitor
12)Add linux machines to monitor
13)Add switches/Routers to monitor
14)configure email alerts in nagios
. Conclusion

Scope:
This guide is intended to provide you with simple instructions on how to install Nagios from
source (code) on Ubuntu and have it monitoring your local machine inside of 20 minutes. No
advanced installation options are discussed here - just the basics that will work for 95% of
users who want to get started.
Configuration files for nagios:
If you follow these instructions, here's what you'll end up with:

Nagios and the plugins will be installed underneath /usr/local/nagios


Nagios will be configured to monitor a few aspects of your local system (CPU load, disk
usage, etc.)
The Nagios web interface will be accessible at http://localhost/nagios/

Required Packages:
Make sure you've installed the following packages on your Ubuntu installation before
continuing.

Apache 2
PHP
GCC compiler and development libraries
GD development libraries

Procedure:
You can use apt-get to install these packages by running the following commands:
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

1) 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
2) Download Nagios and the Plugins:
Create a directory for storing the downloads.
mkdir ~/downloads,cd ~/downloads
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.3.tar.gz
wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins1.4.11.tar.gz
3) Compile and Install Nagios:
Extract the Nagios source code tarball.
cd ~/downloads
tar xzf nagios-3.2.3.tar.gz
cd nagios-3.2.3
Run the Nagios configure script, passing the name of the group you created earlier like so:
./configure --with-command-group=nagcmd
Compile the Nagios source code.
make all
make install
make install-init
make install-config
make install-commandmode

Don't start Nagios yet - there's still more that needs to be done...
4) Customize Configuration:
Edit the /usr/local/nagios/etc/objects/contacts.cfg config file
vi /usr/local/nagios/etc/objects/contacts.cfg
5) Configure the Web Interface:
Install the Nagios web config file in the Apache conf.d directory.
make install-webconf
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 nagiosadmin
Restart Apache to make the new settings take effect.
/etc/init.d/apache2 reload
6) Compile and Install the Nagios Plugins:
Extract the Nagios plugins source code tarball.
cd ~/downloads
tar xzf nagios-plugins-1.4.11.tar.gz
cd nagios-plugins-1.4.11
Compile and install the plugins.
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
7) Start Nagios:
Configure Nagios to automatically start when the system boots.
ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios

Verify the sample Nagios configuration files.


/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
If there are no errors, start Nagios.
/etc/init.d/nagios start
8) Login to the Web Interface:
You should now be able to access the Nagios web interface at the URL below.
http://localhost/nagios/
9) Other Modifications:
If you want to receive email notifications for Nagios alerts, you need to install the mailx
(Postfix) package.
sudo apt-get install mailx
sudo apt-get install postfix
sudo /etc/init.d/nagios restart
Edit the nagios configuration file :
Sudo nano /usr/local/nagios/etc/objects
1)First we define contact for admin
Sudo gedit contact.cfg
define contact{
contact_name
use
alias

nagiosadmin
generic-contact
Nagios Admin

host_notifications_enabled

service_notifications_enabled 1
host_notification_period
service_notification_period
host_notification_options

24x7
24x7
d,u,r

service_notification_options w,u,c,r
email

noreply.rimc@sreesaila.com

can_submit_commands

}
10)Here to add windows Machines to monitor:
Sudo gedit /usr/local/nagios/etc/objects/windows.cfg
WINDOWS.CFG - SAMPLE CONFIG FILE
# HOST DEFINITIONs
# Define a host for the Windows machine we'll be monitoring
# Change the host_name, alias, and address to fit your situation
define host{
use

windows-server

host_name

winserver

alias

My Windows Server ; A longer name associated with the host

address

; Inherit default values from a template

; The name we're giving to this host

192.168.1.2 ; IP address of the host

}
SERVICE DEFINITIONS
# Create a service for monitoring the version of NSCLient++ that is installed
# Change the host_name to match the name of the host you defined above
define service{
use

generic-service

host_name

winserver

service_description NSClient++ Version


check_command

check_nt!CLIENTVERSION

}
# Create a service for monitoring the uptime of the server
# Change the host_name to match the name of the host you defined above

define service{
use

generic-service

host_name

winserver

service_description Uptime
check_command

check_nt!UPTIME

}
# Create a service for monitoring CPU load
# Change the host_name to match the name of the host you defined above
define service{
use

generic-service

host_name

winserver

service_description CPU Load


check_command

check_nt!CPULOAD!-l 5,80,90

}
# Create a service for monitoring memory usage
# Change the host_name to match the name of the host you defined above
define service{
use

generic-service

host_name

winserver

service_description Memory Usage


check_command

check_nt!MEMUSE!-w 80 -c 90

}
# Create a service for monitoring C:\ disk usage
# Change the host_name to match the name of the host you defined above
define service{
use

generic-service

host_name

winserver

service_description C:\ Drive Space


check_command

check_nt!USEDDISKSPACE!-l c -w 80 -c 90

}
# Create a service for monitoring the W3SVC service
# Change the host_name to match the name of the host you defined above
define service{
use

generic-service

host_name

winserver

service_description W3SVC
check_command

check_nt!SERVICESTATE!-d SHOWALL -l W3SVC

}
# Create a service for monitoring the Explorer.exe process
# Change the host_name to match the name of the host you defined above
define service{
use

generic-service

host_name

winserver

service_description Explorer
check_command

check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe

}
11)To add linux machines to edit :
Sudo gedit localhost.cfg
define host{
use

linux-server

host_name local host


alias
address

;linux server
;computername

localhost
127.0.0.1

Now define the services:

;ip of the computer

# SERVICE DEFINITIONS
# Define a service to "ping" the local machine
define service{
use

local-service

host_name
service_description
check_command

; Name of service template to use

localhost
PING
check_ping!100.0,20%!500.0,60%

}
# Define a service to check the disk space of the root partition
# on the local machine. Warning if < 20% free, critical if
# < 10% free space on partition.
define service{
use

local-service

host_name

localhost

service_description
check_command

; Name of service template to use

Root Partition
check_local_disk!20%!10%!/

}
# Define a service to check the number of currently logged in
# users on the local machine. Warning if > 20 users, critical
# if> 50 users.
define service{
use

local-service

host_name

localhost

service_description
check_command

; Name of service template to use

Current Users
check_local_users!20!50

}
# Define a service to check the number of currently running procs

# on the local machine. Warning if > 250 processes, critical if


#> 400 users.
define service{
use

local-service

host_name
service_description
check_command

; Name of service template to use

localhost
Total Processes
check_local_procs!250!400!RSZDT

}
# Define a service to check the load on the local machine.
define service{
use

local-service

host_name

; Name of service template to use

localhost

service_description

Current Load

check_command

check_local_load!5.0,4.0,3.0!10.0,6.0,4.0

}
# Define a service to check the swap usage the local machine.
# Critical if less than 10% of swap is free, warning if less than 20% is free
define service{
use

local-service

host_name
service_description
check_command

; Name of service template to use

localhost
Swap Usage
check_local_swap!20!10

}
# Define a service to check SSH on the local machine.
# Disable notifications for this service by default, as not all users may have SSH enabled.
define service{
use

local-service

; Name of service template to use

host_name

localhost

service_description

SSH

check_command

check_ssh

notifications_enabled

}
# Define a service to check HTTP on the local machine.
# Disable notifications for this service by default, as not all users may have HTTP enabled.
define service{
use

local-service

host_name

localhost

service_description
check_command

; Name of service template to use

HTTP
check_http

notifications_enabled

}
12)To add switches /routers to edit:
Sudo gedit switches.cfg
Definehost{
Service
Host_name
Alias
Host_ip
}

generic service
adslrouter
adslrouter
192.168.100.10

# Generic service definition template - This is NOT a real service, just a template!
define service{
name

generic-service

active_checks_enabled

passive_checks_enabled
parallelize_check

1
1

; The 'name' of this service template


; Active service checks are enabled
; Passive service checks are enabled/accepted

obsess_over_service

check_freshness

notifications_enabled

event_handler_enabled

flap_detection_enabled

failure_prediction_enabled
process_perf_data

retain_status_information

retain_nonstatus_information 1
is_volatile

check_period

24x7

max_check_attempts

normal_check_interval

10

retry_check_interval
contact_groups

2
admins

notification_options

w,u,c,r

notification_interval

60

notification_period

24x7

register

}
# Local service definition template - This is NOT a real service, just a template!
define service{
name

local-service

use

generic-service

max_check_attempts

normal_check_interval

retry_check_interval

register

}
Now we edit the /usr/local/nagios/nagios.cfg
Sudo gedit nagios.cfg
In this file we remove # mark before the lines as below
/usr/local/nagios/etc/objects/windows.cfg
/usr/local/nagios/etc/objects/host.cfg
/usr/local/nagios/etc/objects/switches.cfg
/usr/local/nagios/etc/objects/printer.cfg
13)configure email alerts in nagios
Mail server configuration
Sudo apt-get install sendmail
Now go to /usr/local/nagios/etc/resource.cfg
admin_email=trainee2@sreesaila.com
admin_pager=pagenagios@localhost
and now goto /usr/local/nagios/etc/objects/commands.cfg file and edit
sudo gedit /usr/local/nagios/etc/objects/commands.cfg
# 'notify-host-by-email' command definition
define command{
command_name

notify-host-by-email

command_line
/usr/bin/sendemail -s $USER7$ -xu $USER9$ -xp $USER10$ -t
$CONTACTEMAIL$ -f $USER5$ -l /var/log/sendEmail -u "** $NOTIFICATIONTYPE$ Host Alert:
$HOSTNAME$ is $HOSTSTATE$ **" -m "***** Nagios *****\n\nNotification Type:
$NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress:
$HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" -o
timeout=120
}

# 'notify-service-by-email' command definition

define command{
command_name

notify-service-by-email

command_line
/usr/bin/sendemail -s $USER7$ -xu $USER9$ -xp $USER10$ -t
$CONTACTEMAIL$ -f $USER5$ -l /var/log/sendemail -u "** $NOTIFICATIONTYPE$ Service
Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -m "***** Nagios
*****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost:
$HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time:
$LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" -o timeout=120
}

Conclusion:
Managing your system performance in a Nagios environment is not a black and white formula it's a balancing act with the
resources available on your server. Between the configuration changes described above, using
RAM disks, and offloading MySQL, a
single Nagios server can be configured to handle well over 10,000 active checks. The key ideas
to keep in mind are:
How many checks do I need to run?
Wow often to I need to run them?
Can my hardware handle the check load it has been given?

You might also like