Linux Unix help !!

"Give respect to Time, One day at right Time, Time will respect You"

Wednesday, March 16, 2011

Install Configure Nagios

xxxxxxxxxx Install & Manage NAGIOS Monitoring tool by Shirish Shukla xxxxxxxxxxxxx

Nagios® is a system and network monitoring application. (Description from some source)
Some of the many features of Nagios® include:
- Monitoring of network services (SMTP, POP3, HTTP, NNTP, PING, etc.)
- Monitoring of host resources (processor load, disk usage, etc.)
- Simple plugin design that allows users to easily develop their own service checks
- Parallelized service checks
- Ability to define network host hierarchy using "parent" hosts, allowing detection of and     distinction between hosts that are down and those that are unreachable
- Contact notifications when service or host problems occur and get resolved (via email, pager,   or user-defined method)
- Ability to define event handlers to be run during service or host events for proactive          problem resolution
- Automatic log file rotation
- Support for implementing redundant monitoring hosts
- Optional web interface for viewing current network status, notification and problem history,   log file, etc.

PREREQUISITE:
=============
Apache (https)
gcc libraries

Nagios Tols:
============
# mkdir /root/SW
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.3.tar.gz
wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.11.tar.gz

##Adduser and groups

# useradd -m nagios 
# passwd nagios

# groupadd nagios              <--Just for confirmation
# usermod -G nagios nagios     <--Just for confirmation

# groupadd nagcmd
# usermod -a -G nagcmd nagios
# usermod -a -G nagcmd wwwrun  <--Not Require(optional) need to create group wwwrun before

INSTALLATION:
=============
# cd /root/SW
# tar xzf nagios-3.2.3.tar.gz
# cd nagios-3.2.3

# ./configure --with-command-group=nagcmd
# make all
# make install
# make install-init
# make install-config
# make install-commandmode

# vi /usr/local/nagios/etc/objects/contacts.cfg
At line
35: Change --> email           youadmin-mail-id

# make install-webconf
# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Note: if you want to change admin "nagiosadmin" name  chanhe all in  "/usr/local/nagios/etc/cgi.cfg" file too .

##Start httpd(Apache)
# /etc/init.d/httpd restart
# chkconfig httpd on

### Instal nagios-plugin
# tar xzf nagios-plugins-1.4.11.tar.gz
# cd nagios-plugins-1.4.11
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
# make
# make install

#### Start nagios
# /etc/init.d/nagios restart
# chkconfig nagios on

###### How to OPERATE

# Webadmin panel
http://your-ip/nagios/  < Provide above seted id & password---

EG: To Check All Hosts without options You can set it to your default apache hosting file for your monitoring purpose
http://192.168.8.10/nagios/cgi-bin/status.cgi?host=all

### Want default as above to your ip
# vi /var/www/html/index.html
<html>
<head>
<META HTTP-EQUIV="Refresh"
CONTENT="2; URL=http://192.168.8.10/nagios/cgi-bin/status.cgi?host=all">
</head>
<body bgcolor="pink">
<br />
<br />
<br />
<br />
<br />
<br />
<Center>
<h1> <font color="green"> Wait 2 Sec.............</font></h1>
</body>
</html>

##Save and relaod httpd

Now just type your ip on browser and <---Enter

####################################################
#################Add your servers to monitor ############
###################################################
# cd /usr/local/nagios    <-- Nagios default files

# cd /usr/local/nagios/etc/objects <<-- All cfg file server's config file to monitor

# cat /usr/local/nagios/etc/nagios.cfg  <<<-- NAgios main config file

# vi /usr/local/nagios/etc/nagios.cfg  <<<--Add your own config dirs where your all server cfg file will reside

==>Add below line

  cfg_dir=/usr/local/nagios/etc/lnx-servers

# cd usr/local/nagios/etc/lnx-servers

# vi my-samba_server


##############################################################
############# HOST DEFINITION ###############################
##############################################################
 # HOST DEFINITION
   define host{
        use                     linux-server            ; defined in template
        host_name               scratch-samba.8.10
        alias                   samba-server
        address                 192.168.8.10
        }

# HOST GROUP DEFINITION (Optional, you can add multiple members to your already created group seperated by comma)
define hostgroup{
        hostgroup_name  my-servers             ; The name of the hostgroup
        alias           MY Linux Servers         ; Long name of the group
        members         scratch-samba.8.10      ; Comma separated list of hosts that belong to this group
       }

##############################################################
####################### SERVICE DEFINITIONS #################
##############################################################

###Ping check
define service{
        use                             local-service                 ; defined in template /usr/local/nagios/etc/objects/templates.cfg
        host_name                       scratch-samba.8.10
        service_description             PING
        check_command                   check_ping!100.0,20%!500.0,60% ; Defined in commnd file /usr/local/nagios/etc/objects/commands.cfg
        }


### SSH service Check
define service{
        use                             local-service        
        host_name                       scratch-samba.8.10
        service_description             SSH
        check_command                   check_ssh!-t 5 -r "OpenSSH_4.2"
        }

define service{
        use                             local-service         ; Name of service template to use
        host_name                       scratch-samba.8.10
        service_description             samba
        check_command                   check_http
        }

define service{

        use                     local-service           ; Inherit default values from a template
        host_name               scratch-samba.8.10
        service_description     SMTP
        check_command           check_smtp
        }

#check port 139
define service{
        use                     local-service           ; Inherit default values from a template
        host_name               scratch-samba.8.10
        service_description     Samba_port139
        check_command           check_tcp!139
        }

##########################################################################


## Nagios Fine tunning file (Do not replace original line comment that then add below line)
# vi /usr/local/nagios/etc/cgi.cfg

### Don't show pending satate of service
use_pending_states=0

### Disable webadmin auth
use_authentication=0

### Want  to authorize an user shukla to have all admin rights for weadmin panel
authorized_for_system_information=shukla
authorized_for_configuration_information=shukla
authorized_for_system_commands=shukla
authorized_for_all_hosts=shukla
authorized_for_all_services=shukla
authorized_for_all_service_commands=shukla
authorized_for_all_host_commands=shukla


### Want default guest user, WARN: dont' allow this
default_user_name=guest

### Want an read only user
#htpasswd -c /usr/local/nagios/etc/htpasswd.users user1
#using command add more users
authorized_for_read_only=user1

### Want to change ping syntax
ping_syntax=/bin/ping -n -U -c 5 $HOSTADDRESS$

### Refresh rate of cgi (status, statusmap, extinfo, and outages) in sec
refresh_rate=60

### Want to play sound on webpanel if error occour on network
## Plcace your audio file at
# /usr/local/nagios/share/media
##Un commen tbelow lines after adding resp audio files
#host_unreachable_sound=hostdown.wav
#host_down_sound=hostdown.wav
#service_critical_sound=critical.wav
#service_warning_sound=warning.wav
#service_unknown_sound=warning.wav
#normal_sound=noproblem.wav

### dont allow to change author name while submitting comment
lock_author_names=0


# vi /usr/local/nagios/etc/nagios.cfg

### Change log path
log_file=/usr/local/nagios/var/nagios.log

## Add your specific cfg file of server to monitor
cfg_file=/usr/local/nagios/etc/objects/myserver.cfg

## Add you dir contain your server cdf file to monitor all
cfg_dir=/usr/local/nagios/etc/my-lnx-servers

## Host update interval in sec
status_update_interval=5

## Change nagios user & Group (NOT Recomended)
nagios_user=nagios
nagios_group=nagios

## Add you own command file
check_external_commands=0
command_check_interval=-1
command_file=/usr/local/nagios/var/rw/nagios.cmd <<--As you want
external_command_buffer_slots=4096

## Nagios store his pid at
lock_file=/usr/local/nagios/var/nagios.lock


##### agios Log rotation
#       n       = None - don't rotate the log
#       h       = Hourly rotation (top of the hour)
#       d       = Daily rotation (midnight every day)
#       w       = Weekly rotation (midnight on Saturday evening)
#       m       = Monthly rotation (midnight last day of month)

log_rotation_method=d
log_archive_path=/usr/local/nagios/var/archives

##Use syslog to do so
use_syslog=1

##### MAXIMUM SERVICE CHECK SPREAD in munute
max_service_check_spread=30

### HOST FRESHNESS CHECK OPTION (Nagios chek periodically freshmess of hosts)
check_host_freshness=1
host_freshness_check_interval=20

### Change date format
#       us              (MM-DD-YYYY HH:MM:SS)
#       euro            (DD-MM-YYYY HH:MM:SS)
#       iso8601         (YYYY-MM-DD HH:MM:SS)
#       strict-iso8601  (YYYY-MM-DDTHH:MM:SS)
date_format=us

##Enable perl support
##not in use if u have not compliled nagios with perl
p1_file=/usr/local/nagios/bin/p1.pl
###disable =0
enable_embedded_perl=1

# ADMINISTRATOR EMAIL/PAGER ADDRESSES
admin_email=nagios@localhost

# DEBUG LEVEL
#          -1 = Everything
#          0 = Nothing
#          1 = Functions
#          2 = Configuration
#          4 = Process information
#          8 = Scheduled events
#          16 = Host/service checks
#          32 = Notifications
#          64 = Event broker
#          128 = External commands
#          256 = Commands
#          512 = Scheduled downtime
#          1024 = Comments

debug_level=0

# DEBUG VERBOSITY
# Values: 0 = Brief output
#         1 = More detailed
#         2 = Very detailed

debug_verbosity=1

# DEBUG FILE
debug_file=/usr/local/nagios/var/nagios.debug


############################ BASIC Checking #############################

### Check Your Config files for error

# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
# /etc/init.d/nagios start



########## Tunnning

1> Want any new updates to be check every minute (Default 5 minute)
# vi /usr/local/nagios/etc/objects/templates.cfg

check_interval      1 ; Actively check the host every 1 minutes

2> I want to check default ping of my server
check_command                   check-ping

3> I want to use all config waht i defined in my template linux-server to windows-server
Add below line in windows.cfg
use  linux-server


xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

# Faced any problem Feedback in above contact me
#===============================Scratch===============================#
# AND Many More .....................Linux is Endless                 #
#========================== Hope you Liked IT ========================#
#                                         NAGIOS -- BY Shirish Shukla #
#                                                   RHC Engineer 2010 #
#                                             shirish.linux@gmail.com #
#                                           shirishlinux.blogspot.com #
# "Give Respect To Time One Day At Right Time, Time Will Respect You" #
#=====================================================================#
# TRy Hard theres nothing that are un-achievable by HARDdd-WORKkk     #
#=====================================================================#
Nagios, Nagios linux , install nagios, config nagios linux, nagios refresh, nagios configuration linux, how to install nagios linux, basic nagios; shirish, shukla, linux engineer, linux, alert, monitoring tool linux

6 comments:

  1. Great Looking for script to automate installing and adding servers in nagios... Hope you could help me in this..

    --Jay Garg

    ReplyDelete
  2. ##################
    1> Trouble shooting
    http:/your-ip/nagios <-- Access forbidden /nagios/

    Solution# Some php files missing
    # Yum -y install php

    2> While REstarting Apache [/etc/init.d/httpd restart ] Getting error as
    Invalid command 'AuthUserFile' ......

    Solution: # yum erase httpd*
    # yum -y install httpd

    * I know it's not a recommended solution but instead of asking you to check the logs and correct the error by adding modules and all
    I recommended above .

    ReplyDelete
  3. Definitely Garg I will help you but right moment am bit busy in some work will look for it in coming time .

    ReplyDelete
  4. HI sirish
    Thanks For Sharing Can you guide me how can we monitor windows hosts with snmp ..... :-)

    ReplyDelete
  5. Nice blog shirish

    virtual servers same configured in nagios?

    ReplyDelete
  6. 35: Change --> email youadmin-mail-id
    please explain it how to in this line.

    ReplyDelete

Write Here .. your comments are always wellcome ..but no spam please !!

Followers

Pls LIKE my Story !!!