Tuesday 30 January 2024

How to install nagios with NRPE

                                                    INSTALLATION  NAGIOS WITH NRPE


Nagios is a system  and network monitoring application that watches host and services that we specify as well as alerting when finds any error. It has ability to monitor network services (ike:- smtp, pop3, http,ping etc.), host resources (processor load, disk usage,etc.), automatic log file rotation etc.


How to install Nagios:


By following the below given steps you would be able to install Nagios:-


Step:1> First check if you have Apache(http), gcc compiler,glibc, glibc-common and gd development liberary install or not if not then install all these.


# yum install httpd

# yum instll gcc

# yum install glibc*

# yum install gd*


Step:2> Create a new nagios user account , group  and its password.


# useradd nagios

# passwd nagios

# groupadd nagcmd

# usermod -G nagcmd nagios 

# usermod -G nagcmd apache


Step: 3> Create a directory called download and  download Nagios and its pluggins.


# mkdir -p  /root/download

# cd  /root/download

# wget http://osdn.dl.sourceforge.net/sourceforge/nagios/nagios-3.0.2.tar.gz

# wget http://osdn.dl.spurceforge.net/sourceforge/nagiosplug/nagios-pluggins-1.4.11.tar.gz


If you are unable to download using wget than use the following link to download nagios and nagiosplug:- http://www.nagios.org/download

 

Step:4> Compile and install Nagios


# cd  /root/download 

# tar -xvzf nagios-3.0.2.tar.gz   ## extract the tar file.

# cd nagio-3.0.2

# ./configure --with-command-group=nagcmd

# make all   ## compiling the sourcecode.



Install binaries, init script, sample config file and set permissions on the external command directory.


# make install

# make install-init

# make install-config

# make install-commandmod





Step:5> Install the Nagios web config file in the Apache conf.d directory.


# make install-webconf


Step:6> Create a nagiosadmin account for logging into the Nagios web interface.


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


# /etc/init.d/httpd restart   ## To activate new settings.


Step:7> Compile and install the nagios pluggins.


# cd  /root/download

#  tar -xvzf nagios-pluggins-1.4.11.tar.gz

# cd nagios-pluggins-1.4.11

# ./configure  --with-nagios-user=nagios  --with-nagios-group=nagios

# make 

# make install

# chown nagios.nagios /usr/local/nagios   ## permissions on the pluggin directory.

# chown -R nagios.nagios /usr/local/nagios/libexec


Step:8> Add Nagios to the list of system services that it automatically start when the  system boots.


# chkconfig –add nagios

# chkconfig nagios on

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

 

Output like this:-


Nagios 3.0.2

Copyright (c) 1999-2008 Ethan Galstad (http://www.nagios.org)

Last Modified: 05-19-2008

License: GPL


Reading configuration data...


Running pre-flight check on configuration data...


Checking services...

        Checked 35 services.

Checking hosts...

        Checked 4 hosts.

Checking host groups...

        Checked 1 host groups.

Checking service groups...

        Checked 0 service groups.

Checking contacts...

        Checked 1 contacts.

Checking contact groups...

        Checked 1 contact groups.

Checking service escalations...

        Checked 0 service escalations.

Checking service dependencies...

        Checked 0 service dependencies.

Checking host escalations...

        Checked 0 host escalations.

Checking host dependencies...

        Checked 0 host dependencies.

Checking commands...

        Checked 25 commands.

Checking time periods...

        Checked 5 time periods.

Checking for circular paths between hosts...

Checking for circular host and service dependencies...

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.


If output comes like this, it mean there is no error, now start the nagios service.


# /etc/init.d/nagios start


Use the following command to run the CGIs under the  SElinux  enforcing/targated mode.


# chcon -R -t  httpd_sys_content_t  /usr/local/nagios/sbin/

# chcon -R -t httpd_sys_content_t  /usr/local/nagios/share/



Step:8> Access the Nagios web interface through your web browser:

http://localhost/nagios/





Note:- Here you will be prompted for the username(nagiosadmin) and password that is given by you at step 6 ).



















To monitor more than one remote servers or machines and  to get accurate result we need to install NRPE addon on every remote servers or machines as well as monitoring host machine(nagios installed). 

 

NRPE:

NRPE is an addon that allow you to execute pluggins on remote hosts to monitor local resources like disk  usage, CPU load, memory usage etc. on a remote host.


Step:8> On remote host,  first install the same vesion of nagios pluggins that is installed on the host monitoring machine then instll NRPE addon.


# useradd nagios

# passwd nagios

# mkdir -p  /root/download

# cd  /root/download

# wget http://osdn.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.11.tar.gz

# tar -xvzf nagios-pluggins-1.4.11.tar.gz

# cd nagios-pluggins-1.4.11

# ./configure

# make

# make install


Set the permissions on the plugins directory.


# chown nagios.nagios /usr/local/nagios

# chown -R nagios.nagios /usr/local/nagios/libexec


# yum install xinetd      ## Install the xinetd ( if not installed).


Step:9> Now install NRPE daemon


# cd  /root/download

# wget http://osdn.dl.sourceforge.net/sourceforge/nagios/nrpe-2.8.tar.gz


Note: if unable to install then use the given link to download ( http://www.nagios.org/download/ ).


# tar -xvzf nrpe-2.8.tar.gz ## Extract the sourcecode

# cd nrpe-2.8

# ./configure ## Compile the NRPE addon

# make all


 Step:10>  Install the NRPE plugin (for testing), daemon, and sample daemon config file.


# make install-plugin

# make install-daemon

# make install-daemon-config


# make install-xinetd ## Install the NRPE daemon as a service under xinetd.


 Step:10>  Edit the /etc/xinetd.d/nrpe file and add the IP address of the monitoring server to the only_from directive.


# vi /etc/xinetd.d/nrpe


only_from            = 127.0.0.1  192.168.2.28


Note: Assuming 192.168.2.28 is the nagios_monitoring machine on which Nagios is installed.


 Step:11> Add the following entry for the NRPE daemon to the /etc/services file and restart the xinetd service.


# vi /etc/services


nrpe                5666/tcp          # NRPE


# service xinetd restart


Step:12>Make sure the nrpe daemon is running under xinetd.


# netstat -at | grep nrpe


The output out this command should show something like this:


tcp         0           0 *:nrpe    *:*          LISTEN


 If it does, great! If it doesn't, make sure of the following:


* You added the nrpe entry to your /etc/services file


* The only_from directive in the /etc/xinetd.d/nrpe file contains an entry for "127.0.0.1"


*  xinetd is installed and started


*Check the system log files for references about xinetd or nrpe and fix any problems that are reported


Next, check to make sure the NRPE daemon is functioning properly. To do this, run the check_nrpe plugin that
was installed for testing purposes.


# /usr/local/nagios/libexec/check_nrpe -H localhost


You should get a string back that tells you what version of NRPE is installed, like this:


NRPE v2.8


Note: If you are getting error message like file or directory not found than create the specified directory or file and again run the check_nrpe .


 Step:13> Open firewall rules


Make sure that the local firewall on the machine will allow the NRPE daemon to be accessed from remote servers.
To do this, run the following iptables command. Note that the RH-Firewall-1-INPUT chain name is Fedora-
specific, so it will be different on other Linux distributions.


# iptables -I RH-Firewall-1-INPUT -p tcp -m tcp –dport 5666 -j ACCEPT


# service iptables save     ## Save the new iptables rule so it will survive machine reboots.


You can test some of these  by running the following commands:


# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_users

# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_load

# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_hda1

# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_total_procs

# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_zombie_procs



Step:14>Monitoring Host (the machine that runs Nagios used to monitor other hosts)Setup


Now install NRPE daemon


# cd  /root/download

# wget http://osdn.dl.sourceforge.net/sourceforge/nagios/nrpe-2.8.tar.gz


Note:if unable to install then use the given link to download ( http://www.nagios.org/download/ ).


# tar -xvzf nrpe-2.8.tar.gz ## Extract the sourcecode

# cd nrpe-2.8

# ./configure ## Compile the NRPE addon

# make all


 Step:15>  Install the NRPE plugin (for testing), daemon, and sample daemon config file.


# make install-plugin

# make install-daemon

# make install-daemon-config


 Step:16> Test communication with the NRPE daemon


Make sure the check_nrpe plugin can talk to the NRPE daemon on the remote host. Replace "192.168.0.1" in the
command below with the IP address of the remote host that has NRPE installed.


# /usr/local/nagios/libexec/check_nrpe -H 192.168.2.27


You should get a string back that tells you what version of NRPE is installed on the remote host, like this:


NRPE v2.8


If the plugin returns a timeout error, check the following:


 Make sure there isn't a firewall between the remote host and the monitoring server that is blocking

ccmmunication


* Make sure that the NRPE daemon is installed properly under xinetd
.

* Make sure the remote host doesn't have local (iptables) firewall rules that prevent the monitoring server from
talking to the NRPE daemon


 Step:17>Create a command definition in order to use the
check_nrpe plugin. Edit the command .cfg file.


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


Add the following lines:-


define command{

        command_name check_nrpe

        command_line $USER1$/check_nrpe -H $192.168.2.27$ -c $ARG1$

        }


Note:- Assuming our host address = 192.168.2.27

  

Step:18>create a new template for each different type of host you'll be monitoring. Edit template.cfg and inser the following template.


# vi /usr/local/nagios/etc/object/template


# Define a template for station1(192.168.2.27) that we can reuse


define host{

          name                  station1             ; Name of this template

          use                   generic-host          ; Inherit default values

          check_period          24x7

          check_interval        5

          retry_interval        1

          max_check_attempts    10

          check_command         check-host-alive

          notification_period   24x7

          notification_interval 30

          notification_options  d,r

          contact_groups        admins

          register              0          

          }



Step:18> Define services to monitor for each hosts in the localhsot.cfg file.


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


# Define a host for the local machine


define host{

         use                       station1            ; 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               station1.xyz.com

        alias                   station2_27

        address                 192.168.2.27

        }


# # 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                                     generic-service         ; Name of service template to use

        host_name                         station1.xyz.com

        service_description            /dev/hda1

        check_command               check_nrpe!check_hda1

        }


define service{

        use                                    generic-service         ; Name of service template to use

        host_name                        station1.xyz.com

        service_description           /dev/hda2

        check_command              check_nrpe!check_hda2

        }



define service{

        use                                    generic-service         ; Name of service template to use

        host_name                        station1.xyz.com

        service_description           /dev/hda3

        check_command              check_nrpe!check_hda3

        }


Note: By default check_hda is defined in the /usr/local/nagios/etc/nrpe.cfg file. So you can define more services like /dev/hda1, /dev/hda2, .... on the remote host's /usr/local/nagios/etc/nrpe.cfg.


Example:-


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


add like this;-


command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda


command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1

command[check_hda2]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda2

command[check_hda3]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda3

command[check_hda5]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda5


Step:19> Verify your Nagios configuration files and restart the nagios service


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


# service nagios restart


No comments:

Post a Comment

What is RAID ?

  What is RAID?   RAID Levels - How the drives are organized   How to determine your RAID level  RAID 0 - Disk Striping   RAID 1 - Disk Mirr...

most viewed