Skip to main content

NAGIOS 4.2.0 SERVER/CLIENT CONFIGURATION IN CENTOS

Nagios is a best server monitoring software on the market. Server monitoring is made easy in Nagios because of the flexibility to monitor your servers with both agent-based and agentless monitoring.In this article we will explain about configuring nagios server and host which we will monitor.

Install the required packages
#yum install -y httpd php gcc glibc glibc-common gd gd-devel make net-snmp unzip

Create a new nagios user and nagcmd group account and set a password.
# useradd nagios
# groupadd nagcmd
add both the nagios user and the apache user to the nagcmd group.
# usermod -G nagios Nagios
# usermod -G nagios apache

Download Nagios Core 4.2.0 and Nagios Plugin 2.1.2
#mkdir /root/nagios
#cd /root/Nagios

Now download latest Nagios Core 4.2.0 and Nagios plugins 2.1.2 packages with wget command.
# 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

Extract the downloaded files
# tar -xvf nagios-4.2.0.tar.gz
# tar -xvf nagios-plugins-2.1.2.tar.gz

Configure Nagios Core
# cd nagios-4.2.0
# ./configure --with-command-group=nagios
# make all
# make install
# make install-init
# make install-commandmode
# make install-config

Customizing Nagios Configuration
#vi /usr/local/nagios/etc/objects/contacts.cfg

--------------------------------------------------------------------------
###############################################################################
###############################################################################
#
# CONTACTS
#
###############################################################################
###############################################################################

# Just one contact defined by default - the Nagios admin (that's you)
# This contact definition inherits a lot of default values from the 'generic-contact'
# template which is defined elsewhere.

define contact{
       contact_name                    nagiosadmin             ; Short name of user
       use                             generic-contact         ; Inherit default values from generic-contact template (defined above)
       alias                           Nagios Admin            ; Full name of user

       email                           arunm8489@gmail.com     ; *** CHANGE THIS TO YOUR EMAIL ADDRESS ****
       }
-------------------------------------------------------------------------

We have to give our mailid to receive alerts here.

The below command will Configure Web interface for Nagios and a web admin user will be created “nagiosadmin”
#make install-webconf

In this step, we will be creating a password for “nagiosadmin”. After executing this command, please provide a password twice and keep it remember because this password will be used when you login in the Nagios Web interface.
#htpasswd -s -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

#service httpd start
Compile and Install Nagios Plugin
#cd /root/Nagios
#cd nagios-plugins-2.1.2/
#./configure --with-nagios-user=nagios --with-nagios-group=Nagios
# make
# make install

Verify Nagios Configuration Files
#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Sample output:
---------------------------------------------------------------------------
Nagios Core 4.2.0
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 08-01-2016
License: GPL

Website: https://www.nagios.org
Reading configuration data...
   Read main config file okay...
   Read object config files okay...

Running pre-flight check on configuration data...

Checking objects...
Checked 8 services.
Checked 1 hosts.
Checked 1 host groups.
Checked 0 service groups.
Checked 1 contacts.
Checked 1 contact groups.
Checked 24 commands.
Checked 5 time periods.
Checked 0 host escalations.
Checked 0 service escalations.
Checking for circular paths...
Checked 1 hosts
Checked 0 service dependencies
Checked 0 host dependencies
Checked 5 timeperiods
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
----------------------------------------------------------------------------

# systemctl restart httpd
#systemctl enable httpd
#systemctl start Nagios
#systemctl enable Nagios

open it in your browser with “http://Your-server-IP-address/nagios” 





Now we have to configure a host which we will monitor using our nagios server:

First install epel-release package to get required packages
#yum install epel-release
Install required packages
# yum install nrpe nagios-plugins-all openssl

# vi /etc/nagios/nrpe.cfg

Here add your Nagios server ip address
---------------------------------------------------------------------------------------
[...]
## Line 81 - Add the Nagios server IP ##
allowed_hosts=127.0.0.1 192.168.2.1
[...]
---------------------------------------------------------------------------------------

Now start nrpe service
#service nrpe start
# chkconfig nrpe on

Now go back to your Nagios server to add the clients to be monitored through nagios server. Edit “/usr/local/etc/nagios/nagios.cfg” file,

# vi /usr/local/nagios/etc/nagios.cfg
and uncomment the following lines.

## Line 52 - Uncomment ##
cfg_dir=/usr/local/etc/nagios/servers

Create a server directory
# mkdir /usr/local/etc/nagios/servers

# vi /usr/local/etc/nagios/servers/clients.cfg
---------------------------------------------------------------------------------------
define host{

use                             linux-server

host_name                       client

alias                           client

#mention the ip of host which we want to monitor
address                         192.168.2.2 

max_check_attempts              5

check_period                    24x7

notification_interval           30

notification_period             24x7

}
--------------------------------------------------------------------------


Restart nagios service

#service nagios restart