miércoles, 8 de enero de 2014

Como instalar Nagios Core 3.5.1 sobre Centos 6.5

Como partners de Nagios, con frecuencia instalamos la versión de código abierto (compilamos y configuramos), esta receta que dejo acá es valida para cualquier distribución de Centos o de Nagios en sentido general. Ingredientes:
Nagios
Centos
Plugins

En la pagina de nagios estan los tutoriales, aqui lo adaptamos a nuestro gusto.
Negritas para los comandos
Italicas para las salidas

Manos a la obra:

1.- Chequear  la versión de Centos
[root@localhost ~]# cat /etc/redhat-release 
CentOS release 6.5 (Final)

2.- Una recomendación que hacemos es instalar las aplicaciones y sus librerías, sobre todo para los chequeos que quieras realizar, es decir, espero hacer chequeos por snmp, instalo snmp y sus librerías, espero chequear dns, dns y sus librerías, y así.

mysql es necesario para guardar las configuraciones.
net-snmp por lo descrito arriba.
php ambientes graficos.
ssl para chequeos seguros.
gcc, glibc para las compilaciones.
gd librerías graficas.

[root@localhost ~]# yum install mysql mysql-devel
[root@localhost ~]# yum install net-snmp net-snmp-devel net-snmp-utils
[root@localhost ~]# yum install openssl openssl-devel
[root@localhost ~]# yum install php php-devel
[root@localhost ~]# yum install gcc glibc glibc-common
[root@localhost ~]# yum install gd gd-devel

3.- Vale la pena tener su propio usuario y grupo.

[root@localhost ~]# useradd -m nagios
[root@localhost ~]# passwd nagios
Changing password for user nagios.
New password: 
BAD PASSWORD: it is based on a dictionary word
BAD PASSWORD: is too simple
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@localhost ~]# groupadd nagcmd

4.- Permitamos que nagios y apache actúen en conjunto para el directorio y archivos de nagios

[root@localhost ~]# usermod -a -G nagcmd nagios
[root@localhost ~]# usermod -a -G nagcmd apache
[root@localhost ~]# 

5.- Descarguemos el paquete

[root@localhost downloads]# wget http://sourceforge.net/projects/nagios/files/nagios-3.x/nagios-3.5.1/nagios-3.5.1.tar.gz/download  

Truncado por tamaño

--2013-12-30 17:24:39--  http://softlayer-ams.dl.sourceforge.net/project/nagios/nagios-3.x/nagios-3.5.1/nagios-3.5.1.tar.gz
Resolving softlayer-ams.dl.sourceforge.net... 37.58.69.140
Connecting to softlayer-ams.dl.sourceforge.net|37.58.69.140|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1763584 (1.7M) [application/x-gzip]
Saving to: “nagios-3.5.1.tar.gz”

100%[======================================>] 1,763,584    157K/s   in 14s     

2013-12-30 17:24:54 (119 KB/s) - “nagios-3.5.1.tar.gz” saved [1763584/1763584]

6.- Desempaquetemos y descomprimamos

[root@localhost downloads]# tar xvfz nagios-3.5.1.tar.gz 

7.- Configuremos

[root@localhost downloads]# cd nagios
[root@localhost nagios]# ./configure --with-command-group=nagcmd
checking for a BSD-compatible install... /usr/bin/install -c
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for gcc... gcc
checking for library containing getservbyname... none required
checking for library containing connect... none required
checking for initgroups... yes

Truncado

checking for mail... /bin/mail
We'll use default routines (in xdata/xsddefault.*) for status data I/O...


Lo normal es obtener una salida como la que se muestra mas abajo

config.status: creating base/Makefile
config.status: creating common/Makefile
config.status: creating contrib/Makefile
config.status: creating cgi/Makefile
config.status: creating html/Makefile
config.status: creating module/Makefile
config.status: creating xdata/Makefile
config.status: creating daemon-init
config.status: creating t/Makefile
config.status: creating t-tap/Makefile
config.status: creating include/config.h
config.status: creating include/snprintf.h
Creating sample config files in sample-config/ ...


*** Configuration summary for nagios 3.5.1 08-30-2013 ***:

 General Options:
 -------------------------
        Nagios executable:  nagios
        Nagios user/group:  nagios,nagios
       Command user/group:  nagios,nagcmd
            Embedded Perl:  no
             Event Broker:  yes
        Install ${prefix}:  /usr/local/nagios
                Lock file:  ${prefix}/var/nagios.lock
   Check result directory:  ${prefix}/var/spool/checkresults
           Init directory:  /etc/rc.d/init.d
  Apache conf.d directory:  /etc/httpd/conf.d
             Mail program:  /bin/mail
                  Host OS:  linux-gnu

 Web Interface Options:
 ------------------------
                 HTML URL:  http://localhost/nagios/
                  CGI URL:  http://localhost/nagios/cgi-bin/
 Traceroute (used by WAP):  /bin/traceroute


Review the options above for accuracy.  If they look okay,
type 'make all' to compile the main program and CGIs.


9.- Seguimos en la compilacion


[root@localhost nagios]# 
[root@localhost nagios]# make all
cd ./base && make
make[1]: Entering directory `/root/downloads/nagios/base'
gcc -Wall -g -O2 -DHAVE_CONFIG_H -DNSCORE   -c -o broker.o broker.c
gcc -Wall -g -O2 -DHAVE_CONFIG_H -DNSCORE   -c -o nebmods.o nebmods.c



Truncado


if [ xyes = xyes ]; then \
cd ./module && make; \
fi
make[1]: Entering directory `/root/downloads/nagios/module'
gcc -fPIC -g -O2 -DHAVE_CONFIG_H -o helloworld.o helloworld.c -shared  
make[1]: Leaving directory `/root/downloads/nagios/module'

*** Compile finished ***

If the main program and CGIs compiled without any errors, you
can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):

  make install
     - This installs the main program, CGIs, and HTML files

  make install-init
     - This installs the init script in /etc/rc.d/init.d

  make install-commandmode
     - This installs and configures permissions on the
       directory for holding the external command file

  make install-config
     - This installs *SAMPLE* config files in /usr/local/nagios/etc
       You'll have to modify these sample files before you can
       use Nagios.  Read the HTML documentation for more info
       on doing this.  Pay particular attention to the docs on
       object configuration files, as they determine what/how
       things get monitored!

  make install-webconf
     - This installs the Apache config file for the Nagios
       web interface

  make install-exfoliation
     - This installs the Exfoliation theme for the Nagios
       web interface

  make install-classicui
     - This installs the classic theme for the Nagios
       web interface


*** Support Notes *******************************************

If you have questions about configuring or running Nagios,
please make sure that you:

     - Look at the sample config files
     - Read the documentation on the Nagios Library at:
           http://library.nagios.com

before you post a question to one of the mailing lists.
Also make sure to include pertinent information that could
help others help you.  This might include:

     - What version of Nagios you are using
     - What version of the plugins you are using
     - Relevant snippets from your config files
     - Relevant error messages from the Nagios log file

For more information on obtaining support for Nagios, visit:

       http://support.nagios.com

*************************************************************

Enjoy.

10.- Y asi el resto de la compilacion

[root@localhost nagios]#
[root@localhost nagios]# make install
cd ./base && make install
make[1]: Entering directory `/root/downloads/nagios/base'
make install-basic
make[2]: Entering directory `/root/downloads/nagios/base'
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/bin

Truncado

make install-basic
make[1]: Entering directory `/root/downloads/nagios'
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/libexec
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/archives
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/spool/checkresults
if [ no = yes ]; then \
/usr/bin/install -c -m 664 -o nagios -g nagios p1.pl /usr/local/nagios/bin; \
fi;

*** Main program, CGIs and HTML files installed ***

You can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):

  make install-init
     - This installs the init script in /etc/rc.d/init.d

  make install-commandmode
     - This installs and configures permissions on the
       directory for holding the external command file

  make install-config
     - This installs sample config files in /usr/local/nagios/etc

make[1]: Leaving directory `/root/downloads/nagios'


[root@localhost nagios]# 
[root@localhost nagios]# make install-init
/usr/bin/install -c -m 755 -d -o root -g root /etc/rc.d/init.d
/usr/bin/install -c -m 755 -o root -g root daemon-init /etc/rc.d/init.d/nagios

*** Init script installed ***

[root@localhost nagios]# 
[root@localhost nagios]# make install-config
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
Truncado

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg

*** Config files installed ***

Remember, these are *SAMPLE* config files.  You'll need to read
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.

[root@localhost nagios]#

[root@localhost nagios]# make install-commandmode
/usr/bin/install -c -m 775 -o nagios -g nagcmd -d /usr/local/nagios/var/rw
chmod g+s /usr/local/nagios/var/rw

*** External command directory configured ***

11.- Verifiquemos los contactos (mails), si es que deseamos cambiar el por defecto

[root@localhost nagios]# 

[root@localhost nagios]# more /usr/local/nagios/etc/objects/contacts.cfg 
###############################################################################
# CONTACTS.CFG - SAMPLE CONTACT/CONTACTGROUP DEFINITIONS
#
# Last Modified: 05-31-2007
#
# NOTES: This config file provides you with some example contact and contact
#        group definitions that you can reference in host and service
#        definitions.
#       
#        You don't need to keep these definitions in a separate file from your
#        other object definitions.  This has been done just to make things
#        easier to understand.
#
###############################################################################



###############################################################################
###############################################################################
#
# 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-con
tact' 
# template which is defined elsewhere.

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

        email                           nagios@localhost ; <<***** CHANGE
 THIS TO YOUR EMAIL ADDRESS ******
        }



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

# We only have one contact in this simple configuration file, so there is
# no need to create more than one contact group.

define contactgroup{
        contactgroup_name       admins
        alias                   Nagios Administrators
        members                 nagiosadmin
        }
[root@localhost nagios]# 

[root@localhost nagios]# make install-webconf
/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf

*** Nagios/Apache conf file installed ***



12.- Es necesario que creemos un usuario para la pagina web


[root@localhost nagios]# 
[root@localhost nagios]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password: 
Re-type new password: 
Adding password for user nagiosadmin

13.- Reiniciemos el servicio de apache

[root@localhost nagios]# 
[root@localhost nagios]# service httpd restart
Stopping httpd:                                            [FAILED]
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
                                                           [  OK  ]
[root@localhost nagios]# 
[root@localhost nagios]# cd
You have mail in /var/spool/mail/root
[root@localhost ~]# cd downloads/


14.- Procedamos con la descarga y la instalacion de los plugins, ellos se usan para el proceso de monitoreo, son los comandos que usamos en los archivos de configuracion y por consiguiente los que vemos en la herramienta.


[root@localhost downloads]# wget https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz
--2013-12-30 17:55:57--  https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz
Resolving www.nagios-plugins.org... 130.133.8.40
Connecting to www.nagios-plugins.org|130.133.8.40|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2428258 (2.3M) [application/octet-stream]
Saving to: “nagios-plugins-1.5.tar.gz”

100%[======================================>] 2,428,258   39.5K/s   in 57s     

2013-12-30 17:56:57 (41.6 KB/s) - “nagios-plugins-1.5.tar.gz” saved [2428258/2428258]

[root@localhost downloads]# 
[root@localhost downloads]# tar xvfz nagios-plugins-1.5.tar.gz 


15.- Configuramos



[root@localhost nagios-plugins-1.5]# ./configure --with-nagios-user=nagios --with-nagios-group=nagcmd


config.status: creating po/Makefile.in
config.status: creating config.h
config.status: executing depfiles commands
config.status: executing libtool commands
config.status: executing po-directories commands
config.status: creating po/POTFILES
config.status: creating po/Makefile
            --with-apt-get-command: 
              --with-ping6-command: /bin/ping6 -n -U -w %d -c %d %s
               --with-ping-command: /bin/ping -n -U -w %d -c %d %s
                       --with-ipv6: yes
                      --with-mysql: /usr/bin/mysql_config
                    --with-openssl: yes
                     --with-gnutls: no
               --enable-extra-opts: no
                       --with-perl: /usr/bin/perl
             --enable-perl-modules: no
                     --with-cgiurl: /nagios/cgi-bin
               --with-trusted-path: /bin:/sbin:/usr/bin:/usr/sbin
                   --enable-libtap: no

16.- Compilamos


[root@localhost nagios-plugins-1.5]# make


gcc -DLOCALEDIR=\"/usr/local/nagios/share/locale\" -DHAVE_CONFIG_H -I. -I..  -I.. -I../lib -I../gl -I../intl -I../plugins -I/usr/include  -DNP_VERSION='"1.5"' -g -O2 -MT check_icmp.o -MD -MP -MF .deps/check_icmp.Tpo -c -o check_icmp.o check_icmp.c

Truncado

plugins-1.5/po'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/downloads/nagios-plugins-1.5/po'
make[2]: Entering directory `/root/downloads/nagios-plugins-1.5'
make[2]: Leaving directory `/root/downloads/nagios-plugins-1.5'
make[1]: Leaving directory `/root/downloads/nagios-plugins-1.5'


[root@localhost nagios-plugins-1.5]# make install
if test "nagios-plugins" = "gettext-tools"; then \
 /bin/mkdir -p /usr/local/nagios/share/gettext/po; \
 for file in Makefile.in.in remove-potcdate.sin    Makevars.template; do \
   /usr/bin/install -c -o nagios -g nagcmd -m 644 ./$file \
   /usr/local/nagios/share/gettext/po/$file; \
 done; \
 for file in Makevars; do \
   rm -f /usr/local/nagios/share/gettext/po/$file; \
 done; \
else \
 : ; \
fi
make[1]: Leaving directory `/root/downloads/nagios-plugins-1.5/po'
make[1]: Leaving directory `/root/downloads/nagios-plugins-1.5'

17.- Hagamos un make install para llevarlos a la carpeta de nagios

[root@localhost nagios-plugins-1.5]# make install

Making install in gl
make[1]: Entering directory `/root/Downloads/nagios-plugins-1.5/gl'
make  install-recursive
make[2]: Entering directory `/root/Downloads/nagios-plugins-1.5/gl'
make[3]: Entering directory `/root/Downloads/nagios-plugins-1.5/gl'
make[4]: Entering directory `/root/Downloads/nagios-plugins-1.5/gl'
if test yes = no; then \
      case 'linux-gnu' in \
        darwin[56]*) \
          need_charset_alias=true ;; \
        darwin* | cygwin* | mingw* | pw32* | cegcc*) \
          need_charset_alias=false ;; \
        *) \
          need_charset_alias=true ;; \
      esac ; \
    else \
      need_charset_alias=false ; \
    fi ; \
    if $need_charset_alias; then \
      /bin/sh ../build-aux/mkinstalldirs /usr/local/nagios/lib ; \
    fi ; \
    if test -f /usr/local/nagios/lib/charset.alias; then \
      sed -f ref-add.sed /usr/local/nagios/lib/charset.alias > /usr/local/nagios/lib/charset.tmp ; \
      /usr/bin/install -c -o nagios -g nagcmd -m 644 /usr/local/nagios/lib/charset.tmp /usr/local/nagios/lib/charset.alias ; \
      rm -f /usr/local/nagios/lib/charset.tmp ; \
    else \
      if $need_charset_alias; then \
        sed -f ref-add.sed charset.alias > /usr/local/nagios/lib/charset.tmp ; \
        /usr/bin/install -c -o nagios -g nagcmd -m 644 /usr/local/nagios/lib/charset.tmp /usr/local/nagios/lib/charset.alias ; \
        rm -f /usr/local/nagios/lib/charset.tmp ; \
      fi ; \
    fi
..................................


make[1]: Entering directory `/root/Downloads/nagios-plugins-1.5/po'
/bin/mkdir -p /usr/local/nagios/share
installing fr.gmo as /usr/local/nagios/share/locale/fr/LC_MESSAGES/nagios-plugins.mo
installing de.gmo as /usr/local/nagios/share/locale/de/LC_MESSAGES/nagios-plugins.mo
if test "nagios-plugins" = "gettext-tools"; then \
      /bin/mkdir -p /usr/local/nagios/share/gettext/po; \
      for file in Makefile.in.in remove-potcdate.sin    Makevars.template; do \
        /usr/bin/install -c -o nagios -g nagcmd -m 644 ./$file \
                /usr/local/nagios/share/gettext/po/$file; \
      done; \
      for file in Makevars; do \
        rm -f /usr/local/nagios/share/gettext/po/$file; \
      done; \
    else \
      : ; \
    fi
make[1]: Leaving directory `/root/Downloads/nagios-plugins-1.5/po'
make[1]: Entering directory `/root/Downloads/nagios-plugins-1.5'
make[2]: Entering directory `/root/Downloads/nagios-plugins-1.5'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/root/Downloads/nagios-plugins-1.5'
make[1]: Leaving directory `/root/Downloads/nagios-plugins-1.5'



18.- Hagamos de nagios un servicio de centos

[root@localhost nagios-plugins-1.5]# chkconfig --add nagios
[root@localhost nagios-plugins-1.5]# chkconfig nagios on
[root@localhost nagios-plugins-1.5]# 

19.- Verifiquemos si nagios, no nos da error (cada vez que cambiamos un archivo de configuracion, recomendamos usar el comando abajo).

[root@localhost libexec]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg 

Nagios Core 3.5.1
Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 08-30-2013
License: GPL

Website: http://www.nagios.org
Reading configuration data...
   Read main config file okay...
Processing object config file '/usr/local/nagios/etc/objects/commands.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/contacts.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/timeperiods.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/templates.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/localhost.cfg'...
   Read object config files okay...

Running pre-flight check on configuration data...

Checking services...
Checked 8 services.
Checking hosts...
Checked 1 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 24 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

20.- Iniciemos nagios

[root@localhost libexec]# service nagios start
Starting nagios: done.


21.- Modifiquemos selinux para mas facil comunicacion de los plugins con sus clientes


[root@localhost libexec]# getenforce
Enforcing
[root@localhost libexec]# setenforce 0
[root@localhost libexec]# getenforce
Permissive

[root@localhost libexec]# vi /etc/sysconfig/selinux 


[root@localhost libexec]# 
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
#SELINUX=enforcing
SELINUX=permissive
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted



22.- Y vayamos a nuestro navegador preferido y ejecutemos:
http://localhost/nagios


Y voila........



6 comentarios:

  1. Buen día, necesito ayuda para integrar Nagios XI con Network Analizer, agradezco su ayuda mi correo es eabanto2@hotmail.com

    ResponderEliminar
  2. Hola Edgar, ya te respondi el mail, gracias :D

    ResponderEliminar
  3. Hola Dario, muy bueno tu post, pero tengo dudas de como agregar hosts y servicios, podrias darme una ayuda? gracias , mi correo es pablo18111976@hotmail.com

    ResponderEliminar
    Respuestas
    1. Hola, aqui te lo puse :D http://www.cacaoadmin.com/2014/09/monitorear-servidor-solaris-10-sobre.html

      Eliminar
  4. Uff que pena Pablo, voy con un post para eso, lo publico en unos dias, gracias!

    ResponderEliminar
  5. ok... muy bueno tu post... tiene alguna referencia de como trabajar con servidores de terminales ligeras?... investigo pero no doy con un inicio concreto...

    ResponderEliminar