jueves, 11 de julio de 2013

Instalación del cliente de NRPE para Linux


La instalación del cliente de NRPE nos permitirá monitorizar nuestros equipos con Nagios o Centreon. Hay varios metodos para su instalación. Podriamos bajarnos el código, compilarlo e instalarlo. O lo que haremos en este tutorial, bajarnos el paquete desde rpmforge.

Rpmforge es un proyecto libre donde se compilan y empaquetan programas de código abierto para distribuciones RHEL, CentOs y Scientific Linux.

Pongamos que nuestro servidor es un RHEL 6 de 64 Bits. Nos bajamos el paquete de repoforge y lo instalamos:

[root@master ~]# wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
--2013-03-11 11:52:16--  http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
Connecting to 192.168.122.1:3128... connected.
Proxy request sent, awaiting response... 200 OK
Length: 12700 (12K) [application/x-redhat-package-manager]
Saving to: “rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm”
100%[=====================================================================>] 12,700      39.4K/s   in 0.3s  
2013-03-11 11:52:17 (39.4 KB/s) - “rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm” saved [12700/12700]
[root@master ~]# rpm -Uvh rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
warning: rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 6b8d79e6: NOKEY
Preparing...                ########################################### [100%]
   1:rpmforge-release       ########################################### [100%]
[root@master ~]# yum repolist
Loaded plugins: product-id, subscription-manager
Updating certificate-based repositories.
Unable to read consumer identity
rhel-local                                                                              | 4.0 kB     00:00  
rhel-local/primary_db                                                                   | 3.1 MB     00:00  
rpmforge                                                                                | 1.9 kB     00:00  
rpmforge/primary_db                                                                     | 2.5 MB     00:00  
repo id                                repo name                                                         status
rhel-local                             Red Hat Linux 6Server - x86_64 - DVD                              3,585
rpmforge                               RHEL 6Server - RPMforge.net - dag                                 4,458
repolist: 8,043
[root@master ~]# yum install nrpe
Loaded plugins: product-id, subscription-manager
Updating certificate-based repositories.
Unable to read consumer identity
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package nagios-nrpe.x86_64 0:2.12-1.el6.rf will be installed
--> Processing Dependency: nagios-plugins for package: nagios-nrpe-2.12-1.el6.rf.x86_64
--> Running transaction check
---> Package nagios-plugins.x86_64 0:1.4.16-1.el6.rf will be installed
--> Processing Dependency: perl(Net::SNMP) for package: nagios-plugins-1.4.16-1.el6.rf.x86_64
--> Processing Dependency: fping for package: nagios-plugins-1.4.16-1.el6.rf.x86_64
--> Running transaction check
---> Package fping.x86_64 0:3.4-1.el6.rf will be installed
---> Package perl-Net-SNMP.noarch 0:5.2.0-1.2.el6.rf will be installed
--> Processing Dependency: perl(Socket6) >= 0.19 for package: perl-Net-SNMP-5.2.0-1.2.el6.rf.noarch
--> Processing Dependency: perl(Digest::HMAC) for package: perl-Net-SNMP-5.2.0-1.2.el6.rf.noarch
--> Processing Dependency: perl(Crypt::DES) for package: perl-Net-SNMP-5.2.0-1.2.el6.rf.noarch
--> Processing Dependency: perl(Digest::SHA1) for package: perl-Net-SNMP-5.2.0-1.2.el6.rf.noarch
--> Running transaction check
---> Package perl-Crypt-DES.x86_64 0:2.05-3.2.el6.rf will be installed
---> Package perl-Digest-HMAC.noarch 0:1.01-22.el6 will be installed
---> Package perl-Digest-SHA1.x86_64 0:2.12-2.el6 will be installed
---> Package perl-Socket6.x86_64 0:0.23-3.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================================================
 Package                       Arch                Version                       Repository               Size
===============================================================================================================
Installing:
 nagios-nrpe                   x86_64              2.12-1.el6.rf                 rpmforge                 34 k
Installing for dependencies:
 fping                         x86_64              3.4-1.el6.rf                  rpmforge                 47 k
 nagios-plugins                x86_64              1.4.16-1.el6.rf               rpmforge                795 k
 perl-Crypt-DES                x86_64              2.05-3.2.el6.rf               rpmforge                 41 k
 perl-Digest-HMAC              noarch              1.01-22.el6                   rhel-local               21 k
 perl-Digest-SHA1              x86_64              2.12-2.el6                    rhel-local               49 k
 perl-Net-SNMP                 noarch              5.2.0-1.2.el6.rf              rpmforge                 88 k
 perl-Socket6                  x86_64              0.23-3.el6                    rhel-local               23 k
Transaction Summary
===============================================================================================================
Install       8 Package(s)
Total download size: 1.1 M
Installed size: 5.5 M
Is this ok [y/N]: y
Downloading Packages:
(1/8): fping-3.4-1.el6.rf.x86_64.rpm                                                    |  47 kB     00:00  
(2/8): nagios-nrpe-2.12-1.el6.rf.x86_64.rpm                                             |  34 kB     00:00  
(3/8): nagios-plugins-1.4.16-1.el6.rf.x86_64.rpm                                        | 795 kB     00:00  
(4/8): perl-Crypt-DES-2.05-3.2.el6.rf.x86_64.rpm                                        |  41 kB     00:00  
(5/8): perl-Digest-HMAC-1.01-22.el6.noarch.rpm                                          |  21 kB     00:00  
(6/8): perl-Digest-SHA1-2.12-2.el6.x86_64.rpm                                           |  49 kB     00:00  
(7/8): perl-Net-SNMP-5.2.0-1.2.el6.rf.noarch.rpm                                        |  88 kB     00:00  
(8/8): perl-Socket6-0.23-3.el6.x86_64.rpm                                               |  23 kB     00:00  
---------------------------------------------------------------------------------------------------------------
Total                                                                          572 kB/s | 1.1 MB     00:01  
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Installing : perl-Digest-SHA1-2.12-2.el6.x86_64                                                          1/8
  Installing : perl-Digest-HMAC-1.01-22.el6.noarch                                                         2/8
  Installing : perl-Socket6-0.23-3.el6.x86_64                                                              3/8
  Installing : perl-Crypt-DES-2.05-3.2.el6.rf.x86_64                                                       4/8
  Installing : perl-Net-SNMP-5.2.0-1.2.el6.rf.noarch                                                       5/8
  Installing : fping-3.4-1.el6.rf.x86_64                                                                   6/8
  Installing : nagios-plugins-1.4.16-1.el6.rf.x86_64                                                       7/8
  Installing : nagios-nrpe-2.12-1.el6.rf.x86_64                                                            8/8
Installed products updated.
  Verifying  : fping-3.4-1.el6.rf.x86_64                                                                   1/8
  Verifying  : nagios-nrpe-2.12-1.el6.rf.x86_64                                                            2/8
  Verifying  : perl-Digest-SHA1-2.12-2.el6.x86_64                                                          3/8
  Verifying  : perl-Net-SNMP-5.2.0-1.2.el6.rf.noarch                                                       4/8
  Verifying  : perl-Crypt-DES-2.05-3.2.el6.rf.x86_64                                                       5/8
  Verifying  : perl-Digest-HMAC-1.01-22.el6.noarch                                                         6/8
  Verifying  : perl-Socket6-0.23-3.el6.x86_64                                                              7/8
  Verifying  : nagios-plugins-1.4.16-1.el6.rf.x86_64                                                       8/8
Installed:
  nagios-nrpe.x86_64 0:2.12-1.el6.rf                                                                        
Dependency Installed:
  fping.x86_64 0:3.4-1.el6.rf                            nagios-plugins.x86_64 0:1.4.16-1.el6.rf            
  perl-Crypt-DES.x86_64 0:2.05-3.2.el6.rf                perl-Digest-HMAC.noarch 0:1.01-22.el6              
  perl-Digest-SHA1.x86_64 0:2.12-2.el6                   perl-Net-SNMP.noarch 0:5.2.0-1.2.el6.rf            
  perl-Socket6.x86_64 0:0.23-3.el6                    
Complete!

Para evitar confusiones a la hora de actualizar paquetes de sistema, deshabilitaremos el repositorio de rpmforge. Nos aseguramos que el resto de los paquetes se actualizaran desde redhat.

[root@master ~]# cd /etc/yum.repos.d/
[root@master yum.repos.d]# ls
local.repo        mirrors-rpmforge-extras   rhel-source.repo
mirrors-rpmforge  mirrors-rpmforge-testing  rpmforge.repo
[root@master yum.repos.d]# vi rpmforge.repo 

En la sección de rmpforge pondremos enable = 0

[root@master yum.repos.d]# cat rpmforge.repo
### Name: RPMforge RPM Repository for RHEL 6 - dag
### URL: http://rpmforge.net/
[rpmforge]
name = RHEL $releasever - RPMforge.net - dag
baseurl = http://apt.sw.be/redhat/el6/en/$basearch/rpmforge
mirrorlist = http://apt.sw.be/redhat/el6/en/mirrors-rpmforge
#mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge
enabled = 0
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck = 1
[rpmforge-extras]
name = RHEL $releasever - RPMforge.net - extras
baseurl = http://apt.sw.be/redhat/el6/en/$basearch/extras
mirrorlist = http://apt.sw.be/redhat/el6/en/mirrors-rpmforge-extras
#mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge-extras
enabled = 0
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck = 1
[rpmforge-testing]
name = RHEL $releasever - RPMforge.net - testing
baseurl = http://apt.sw.be/redhat/el6/en/$basearch/testing
mirrorlist = http://apt.sw.be/redhat/el6/en/mirrors-rpmforge-testing
#mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge-testing
enabled = 0
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck = 1
[root@master yum.repos.d]# yum repolist
Loaded plugins: product-id, subscription-manager
Updating certificate-based repositories.
Unable to read consumer identity
repo id                                repo name                                                         status
rhel-local                             Red Hat Linux 6Server - x86_64 - DVD                              3,585
repolist: 3,585

Podemos comprobar que el servicio se ha instalado. Lo ejecutamos y vemos cual es el fichero de configuración que está usando.

[root@master yum.repos.d]# service nrpe status
nrpe is stopped
[root@master yum.repos.d]# service nrpe start
Starting Nagios NRPE daemon (nrpe):                        [  OK  ]
[root@master yum.repos.d]# ps -ef |grep nrpe
nagios    1504     1  0 11:59 ?        00:00:00 nrpe -c /etc/nagios/nrpe.cfg -d
root      1507  1402  0 11:59 pts/0    00:00:00 grep nrpe

Modificaremos el fichero de configuración y añadiremos los datos que hacen referencia a nuestro servidor, puerto, etc, etc...

[root@master yum.repos.d]# cat /etc/nagios/nrpe.cfg
#############################################################################
# Sample NRPE Config File
# Written by: Ethan Galstad (nagios@nagios.org)
#
# Last Modified: 11-23-2007
#
# NOTES:
# This is a sample configuration file for the NRPE daemon.  It needs to be
# located on the remote host that is running the NRPE daemon, not the host
# from which the check_nrpe client is being executed.
#############################################################################

# LOG FACILITY
# The syslog facility that should be used for logging purposes.
log_facility=daemon


# PID FILE
# The name of the file in which the NRPE daemon should write it's process ID
# number.  The file is only written if the NRPE daemon is started by the root
# user and is running in standalone mode.
pid_file=/var/run/nrpe.pid


# PORT NUMBER
# Port number we should wait for connections on.
# NOTE: This must be a non-priviledged port (i.e. > 1024).
# NOTE: This option is ignored if NRPE is running under either inetd or xinetd
server_port=5666


# SERVER ADDRESS
# Address that nrpe should bind to in case there are more than one interface
# and you do not want nrpe to bind on all interfaces.
# NOTE: This option is ignored if NRPE is running under either inetd or xinetd
#server_address=127.0.0.1


# NRPE USER
# This determines the effective user that the NRPE daemon should run as.
# You can either supply a username or a UID.
#
# NOTE: This option is ignored if NRPE is running under either inetd or xinetd
nrpe_user=nagios


# NRPE GROUP
# This determines the effective group that the NRPE daemon should run as.
# You can either supply a group name or a GID.
#
# NOTE: This option is ignored if NRPE is running under either inetd or xinetd
nrpe_group=nagios


# ALLOWED HOST ADDRESSES
# This is an optional comma-delimited list of IP address or hostnames
# that are allowed to talk to the NRPE daemon.
#
# Note: The daemon only does rudimentary checking of the client's IP
# address.  I would highly recommend adding entries in your /etc/hosts.allow
# file to allow only the specified host to connect to the port
# you are running this daemon on.
#
# NOTE: This option is ignored if NRPE is running under either inetd or xinetd
allowed_hosts=127.0.0.1


# COMMAND ARGUMENT PROCESSING
# This option determines whether or not the NRPE daemon will allow clients
# to specify arguments to commands that are executed.  This option only works
# if the daemon was configured with the --enable-command-args configure script
# option.
#
# *** ENABLING THIS OPTION IS A SECURITY RISK! ***
# Read the SECURITY file for information on some of the security implications
# of enabling this variable.
#
# Values: 0=do not allow arguments, 1=allow command arguments
dont_blame_nrpe=0


# COMMAND PREFIX
# This option allows you to prefix all commands with a user-defined string.
# A space is automatically added between the specified prefix string and the
# command line from the command definition.
#
# *** THIS EXAMPLE MAY POSE A POTENTIAL SECURITY RISK, SO USE WITH CAUTION! ***
# Usage scenario:
# Execute restricted commmands using sudo.  For this to work, you need to add
# the nagios user to your /etc/sudoers.  An example entry for alllowing
# execution of the plugins from might be:
#
# nagios          ALL=(ALL) NOPASSWD: /usr/lib/nagios/plugins/
#
# This lets the nagios user run all commands in that directory (and only them)
# without asking for a password.  If you do this, make sure you don't give
# random users write access to that directory or its contents!
# command_prefix=/usr/bin/sudo


# DEBUGGING OPTION
# This option determines whether or not debugging messages are logged to the
# syslog facility.
# Values: 0=debugging off, 1=debugging on
debug=0


# COMMAND TIMEOUT
# This specifies the maximum number of seconds that the NRPE daemon will
# allow plugins to finish executing before killing them off.
command_timeout=60


# CONNECTION TIMEOUT
# This specifies the maximum number of seconds that the NRPE daemon will
# wait for a connection to be established before exiting. This is sometimes
# seen where a network problem stops the SSL being established even though
# all network sessions are connected. This causes the nrpe daemons to
# accumulate, eating system resources. Do not set this too low.
connection_timeout=300


# WEEK RANDOM SEED OPTION
# This directive allows you to use SSL even if your system does not have
# a /dev/random or /dev/urandom (on purpose or because the necessary patches
# were not applied). The random number generator will be seeded from a file
# which is either a file pointed to by the environment valiable $RANDFILE
# or $HOME/.rnd. If neither exists, the pseudo random number generator will
# be initialized and a warning will be issued.
# Values: 0=only seed from /dev/[u]random, 1=also seed from weak randomness
#allow_weak_random_seed=1


# INCLUDE CONFIG FILE
# This directive allows you to include definitions from an external config file.
#include=<somefile.cfg>


# INCLUDE CONFIG DIRECTORY
# This directive allows you to include definitions from config files (with a
# .cfg extension) in one or more directories (with recursion).
#include_dir=<somedirectory>
#include_dir=<someotherdirectory>


# COMMAND DEFINITIONS
# Command definitions that this daemon will run.  Definitions
# are in the following format:
#
# command[<command_name>]=<command_line>
#
# When the daemon receives a request to return the results of <command_name>
# it will execute the command specified by the <command_line> argument.
#
# Unlike Nagios, the command line cannot contain macros - it must be
# typed exactly as it should be executed.
#
# Note: Any plugins that are used in the command lines must reside
# on the machine that this daemon is running on!  The examples below
# assume that you have plugins installed in a /usr/local/nagios/libexec
# directory.  Also note that you will have to modify the definitions below
# to match the argument format the plugins expect.  Remember, these are
# examples only!

# The following examples use hardcoded command arguments...
command[check_users]=/usr/lib64/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib64/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1
command[check_zombie_procs]=/usr/lib64/nagios/plugins/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/lib64/nagios/plugins/check_procs -w 150 -c 200

# The following examples allow user-supplied arguments and can
# only be used if the NRPE daemon was compiled with support for
# command arguments *AND* the dont_blame_nrpe directive in this
# config file is set to '1'.  This poses a potential security risk, so
# make sure you read the SECURITY file before doing this.
#command[check_users]=/usr/lib64/nagios/plugins/check_users -w $ARG1$ -c $ARG2$
#command[check_load]=/usr/lib64/nagios/plugins/check_load -w $ARG1$ -c $ARG2$
#command[check_disk]=/usr/lib64/nagios/plugins/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
#command[check_procs]=/usr/lib64/nagios/plugins/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$

Reiniciaremos el demonio...

[root@master yum.repos.d]# service nrpe restart

 ...y ya desde Nagios/Centreon configuraremos las nuevas alertas.

No hay comentarios:

Publicar un comentario