Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: Installing and Configuring Nagios  (Read 2735 times)

0 Members and 1 Guest are viewing this topic.

Leo.Prince

  • Guest
Installing and Configuring Nagios
« on: November 03, 2013, 04:34:55 pm »
Hi,

Nagios is a wonderful tool to check and monitor services at a remote host. We can check many services like ping, server load etc. Before we begin, we need to install some packages on the remote host for Nagios to work fine.

Code: [Select]
yum install elinks gcc make gcc-c++
yum -y install openssl-devel
useradd nagios
passwd nagios
cd /usr/src/

Then install Nagios plugin and NRPE on remote host.

Install Plug-in

Follow these steps

Code: [Select]
wget http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.15/nagios-plugins-1.4.15.tar.gz/download
tar -zxvf nagios-plugins-1.4.15.tar.gz && cd nagios-plugins-1.4.15
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
chown nagios:nagios /usr/local/nagios
chown -R nagios:nagios /usr/local/nagios/libexec
cd ..

Install NRPE

Code: [Select]
wget http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.12/nrpe-2.12.tar.gz/download
tar -zxvf nrpe-2.12.tar.gz && cd nrpe-2.12
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd

Edit Xinetd NRPE entry

Code: [Select]
vi /etc/xinetd.d/nrpe
only_from = 127.0.0.1 Server-IP (nagios monitoring server ip-address is: )
:wq (save and exit)

Edit services file entry

Code: [Select]
vi /etc/services
nrpe 5666/tcp # Entry for NRPE daemon
:wq (save and exit)

Restart xinetd

Code: [Select]
service xinetd restart
Verify whether NRPE is listening

You can use netstat command to see if it is up and running in the corresponding port

Code: [Select]
netstat -at |grep nrpe

# output -: tcp 0 0 *:nrpe *.* LISTEN

Verify to make sure the NRPE is functioning properly

Code: [Select]
/usr/local/nagios/libexec/check_nrpe -H localhost
#output NRPE v2.12

Configuring Nagios monitoring server to monitor the remote host

Code: [Select]
cd /usr/src
wget http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.12/nrpe-2.12.tar.gz/download
tar -zxvf nrpe-2.12.tar.gz && cd nrpe-2.12
yum -y install openssl-devel
yum install perl
./configure
make all
make install-plugin

Create a command definition

Code: [Select]
vi /home/nagios/public_html/etc/objects/commands.cfg
Add the following to the file and save

Code: [Select]
# NRPE CHECK COMMAND
# Command to use NRPE to check remote host systems
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

Create configuration file for remote host

Code: [Select]
# cp –prf /home/nagios/www/etc/objects/ localhost.cfg /home/nagios/www/etc/objects/remotehost.cfg
Code: [Select]
# vi /home/nagios/www/etc/objects/remotehost.cfg
Replace the values “host_name” “alias” “address” with the values that match your setup

The “host_name” you set for the “define_host” section must match the “host_name” in the “define_service” section

Code: [Select]
# Define a host for the remote machine
define host{
       use      linux-server     ; Name of host template to use
                                         ; This host definition will inherit all variables that are defined
                                         ; in (or inherited by) the linux-server host template definition.
        host_name         your_host_name
        alias                    your_alias_name
        address              remote_machine_ip
        }
# SERVICE DEFINITIONS
# Define a service to "ping" the local machine

define service{
        use                              generic-service         ; Name of service template to use
        host_name                  your_host_name
        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.

define service{
        use                             generic-service         ; Name of service template to use
        host_name                 your_host_name
        service_description     Root Partition
        check_command          check_nrpe!check_disk
        }

# Define a service to check the number of currently logged in users on the remotehost.

define service{
        use                             generic-service         ; Name of service template to use
        host_name                 your_host_name
        service_description     Current Users
        check_command         check_nrpe!check_users
        }
# Define a service to check the number of currently running processes on the remote host.

define service{
        use                              generic-service         ; Name of service template to use
        host_name                  your_host_name
        service_description     Total Processes
        check_command          check_nrpe!check_total_procs
        }
# Define a service to check the load on the remote host.

define service{
        use                             generic-service         ; Name of service template to use
        host_name                 your_host_name
        service_description     Current Load
        check_command         check_nrpe!check_load
        }

# Define a service to check SSH on the remote host.
# Disable notifications for this service by default, as not all users may have SSH enabled.
define service{
        use                             generic-service         ; Name of service template to use
        host_name                 your_host_name
        service_description     SSH
        check_command          check_nrpe!check_ssh
        notifications_enabled  0
        }
# Define a service to check HTTP on the remote host.
# Disable notifications for this service by default, as not all users may have HTTP enabled.
define service{
        use                              generic-service         ; Name of service template to use
        host_name                  your_host_name
        service_description      HTTP
        check_command           check_nrpe!check_http
        notifications_enabled   0
        }

Activate the remotehost.cfg template

Code: [Select]
vi /usr/local/nagios/etc/nagios.cfg
 #Definitions for monitoring remote Linux machine
cfg_file=/home/nagios/www/etc/objects/remotehost.cfg

Verify Nagios Configuration Files

Code: [Select]
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
/home/nagios/public_html/bin/nagios -v /home/nagios/public_html/etc/nagios.cfg (In nagios host server)

Output :

Things look okay - No serious problems were detected during the pre-flight check


Verify whether nagios monitoring server can talk to the remote host

Code: [Select]
/usr/local/nagios/libexec/check_nrpe -H remotehost_ip
NRPE v2.12

Start nagios

Code: [Select]
/home/nagios/www/bin/nagios -d /home/nagios/www/etc/nagios.cfg
Restart nagios (if already running)

Code: [Select]
kill -HUP <nagios_pid>
Code: [Select]
/usr/local/nagios/libexec/check_nrpe -H 62.75.215.12 -c check_load (To check the load of the remote server)

OK - load average: 0.35, 0.30, 0.23|load1=0.350;15.000;30.000;0; load5=0.300;10.000;25.000;0; load15=0.230;5.000;20.000;0;

(Usage: check_nrpe -H <host> [-n] [-u] [-p <port>] [-t <timeout>] [-c <command>] [-a <arglist...>])

That is it. Your nagios server is all set to monitor your remote machine.  8)