Monitoring

Nagios Install & Configuration

Nagios is one of the Open Source monitoring tool to monitor Networks, Servers and Services. Here I’m sharing the steps that I used to install and configure Nagios for a production environment.

Pre-Requesits:
OS : CentOS-6-x86_64

Step 1:  Update all system software to the latest version

yum -y update

Step 2:Install Required dependencies

 yum install -y httpd php gcc glibc glibc-common gd gd-devel make net-snmp

Step 3: Create a new user and group account for nagios and set a password.

useradd nagios
groupadd nagcmd

Step 4:  Add both the nagios user and the apache user to the group nagcmd .

usermod -G nagcmd nagios
usermod -G nagcmd apache

Step 5: Download Nagios Core  and Nagios Plugin 

mkdir /root/nagios
cd /root/nagios
 wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.2.0.tar.gz
 wget https://www.nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz

Step 6: Extract compressed files installation files and start installation process

 tar -xvf nagios-4.2.0.tar.gz
 tar -xvf nagios-plugins-2.1.2.tar.gz
 cd nagios-4.2.0
 ./configure --with-command-group=nagcmd
 make all
 make install
 make install-init
 make install-commandmode
 make install-config
 make install-webconf

Step 7: Set Password for Nagios Web admin user

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

Step 8: Restart Web service

service httpd start

Step 9: Install Nagios Plugins

cd /root/nagios
cd nagios-plugins-2.1.2/
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install

Step 10: Configure Nagios and Add Hots

Default nagios conf file location is : /usr/local/nagios/etc/nagios.cfg ,  there we are defining all other config file locations.  By default main configuration files are:

I)  /usr/local/nagios/etc/objects/contacts.cfg     = Contact and contact group can be define here

Sample:

define contact{
  contact_name nagiosadmin ;  
  use generic-contact ;  
  alias Nagios Admin ;  
  email nagios@localhost ;  
 }

define contact{
      contact_name integral ; 
      use generic-contact ; 
      alias Integral Servers ; 
      email email@gmail.com ; 
 }


###############################################################################
# CONTACT GROUPS
###############################################################################

define contactgroup{
 contactgroup_name admins
 alias Nagios Administrators
 members nagiosadmin
 }

define contactgroup{
 contactgroup_name integraladmins
 alias Integralhost Nagios Administrators
 members integral
 }

II) /usr/local/nagios/etc/objects/groups.cfg        = To defind host group here,

Sample:

define hostgroup{
 hostgroup_name linux-shared ; The name of the hostgroup
 alias Linux Shared Servers ; Long name of the group
 members linux24.integralhost.net ; Comma separated list of hosts that belong to this group
 }

III) /usr/local/nagios/etc/objects/commands.cfg  – It contains object definitions that Nagios should use for monitoring

IV) /usr/local/nagios/etc/objects/servername.cfg  = Host server details are defined here. We can place this file anywhere, but we should define it on nagios.cfg like below:

cfg_file=/usr/local/nagios/etc/objects/servername.cfg

Note: Rename “servername.cfg” with exact server host name. It will help admin to easily identify.

Sample:

###############################################################################
# HOST DEFINITION
###############################################################################

define host {
 use generic-host
 host_name server.domain.com
 _localaddress server.domain.com
 alias ibis
 hostgroups linux-shared
 address 104.255.67.38
 check_period 24x7
 check_interval 2
 retry_interval 2
 max_check_attempts 2
 #check_command check_host
 notification_period 24x7
 notification_interval 2
 notification_options d,u,r
 notifications_enabled 1
 contact_groups integraladmins
}

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

# Define a service to "ping" the local machine

define service{
 use local-service ; Name of service template to use
 host_name server.domain.com
 service_description PING
 check_command 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 ; Name of service template to use
 host_name server.domain.com
 service_description Root Partition
 check_command 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 ; Name of service template to use
 host_name server.domain.com
 service_description Current Users
 check_command 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 processes.

define service{
 use local-service ; Name of service template to use
 host_name server.domain.com
 service_description Total Processes
 check_command check_local_procs!250!400!RSZDT
 }

# Define a service to check the load on the local machine.
define service{
 use local-service ; Name of service template to use
 host_name server.domain.com
 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 ; Name of service template to use
 host_name server.domain.com
 service_description Swap Usage
 check_command 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 server.domain.com
 service_description SSH
 check_command check_ssh
 notifications_enabled 0
 }
# 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 ; Name of service template to use
 host_name server.domain.com
 service_description HTTP
 check_command check_http
 notifications_enabled 0
 }

Step 11: Verify Nagios config files:

Execute this before every nagios restart, since if there is any mistake in configuration files, below command will list them.

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

Step 12: Restart Nagios:

/etc/init.d/nagios restart

Now you can access Nagios using the URL http://IPaddress/nagios .

 

Thank you!