You are on page 1of 10

Instalacion de Nagios

1.- Requisitos: Tener instalado las sgtes librerias: libpng-1.2.2-16 zlib-1.1.4-8 libjpeg-6b-26 2.- Descargar y Desempaquetar Nagios Descargar nagios : http://www.nagios.org/download/ Es necesario tambien descargar los plugins y desmpaquetarlos en /usr/local/nagios # cp nagios-1.2.tar.gz /usr/local/ Desempaquetar nagios: # cd /usr/local/ # tar zxvf nagios-1.2.tar.gz # mv nagios-1.2/* nagios/ 3.- Instalar Nagios Primero crear usuario nagios # adduser nagios # cd /usr/local/nagios # ./configure # make all # make install # make install-init # make install-config Luego instalar los plugins # cd /usr/local/nagios # tar zxvf nagios-plugins-1.3.0.tar.gz # mv nagios-plugins-1.3.0/* /nagios-plugins # cd /usr/local/nagios/nagios-plugins/ # ./configure # make all # make install Al culminar la instalacion tendremos los sgtes directorios: - bin/ ( Archivos binarios de Nagios ) - etc/ ( Directorios de Configuracion ) - sbin/ ( cgis ) - share/ ( Archivos html ) - var/ ( Directorio de Logs ) - libexec ( Archivos Plugins de Nagios ) Si se desea personalizar podria compilarse asi: # ./configure prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagiosgrp=nagios --with-cgiurl=/nagios/cgi-bin --with-htmurl=/nagios # make all -s # make install -s # make install-init -s

# make install-config -s Para los Plugins se podria personalizar asi: # cd /usr/local/nagios/nagios-plugins # ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagiosgroup=nagios # make all s # make install s Para instalar desde rpms bajarlos de: # wget c http://dag.wieers.com/packages/nagios/nagios-1.2-0.rh90.dag.i386.rpm # wegt c http://dag.wieers.com/packages/nagios/nagios-devel-1.2-0.rh90.dag.i386.rpm # wget c http://dag.wieers.com/packages/nagios-plugins/nagios-plugins-1.3.110.rh90.dag.i386.rpm 4.- Configurar Nagios 4.1.- Nagios.cfg Por defecto no hace falta tocar este archivo, como viene funciona perfectamente, posteriormente se podria cambiar para aprovechar al maximo Nagios. # cd /etc/nagios #pico nagios.cfg log_file=/var/log/nagios/nagios.log cfg_file=/etc/nagios/checkcommands.cfg cfg_file=/etc/nagios/misccommands.cfg cfg_file=/etc/nagios/contactgroups.cfg cfg_file=/etc/nagios/contacts.cfg cfg_file=/etc/nagios/dependencies.cfg cfg_file=/etc/nagios/escalations.cfg cfg_file=/etc/nagios/hostsgroups.cfg cfg_file=/etc/nagios/hosts.cfg cfg_file=/etc/nagios/services.cfg cfg_file=/etc/nagios/timeperiods.cfg 4.2 Cgi.cfg Configuramos las sgtes. Lineas para que el usuario web nagiosadmin tenga acceso total a Nagios. # cd /etc/nagios # pico cgi.cfg authorized_for_system_information=nagiosadmin authorized_for_configuration_information=nagiosadmin authorized_for_system_commands=nagiosadmin authorized_for_all_services=nagiosadmin authorized_for_all_hosts=nagiosadmin authorized_for_all_service_commands=nagiosadmin authorized_for_all_host_commands=nagiosadmin 4.3.- Hosts.cfg Aqui debemos incluir todas las Pcs que queremos monitorear , cada maquina debe tener al menos un servicio bien sea check_ping, check_http, check_ftp ,etc.

# cd /etc/nagios # pico hosts.cfg define host{ name generic-host ; Nombre del template del host notifications_enabled 1 ; Notificaciones activadas event_handler_enabled 1 ; Host event handler is enabled flap_detection_enabled 1 ; Flap detection is enabled process_perf_data 1 ; Process performance data retain_status_information 1 ; Retain status information across program restarts retain_nonstatus_information 1 ; Retain non-status information across program restarts register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST ATEMPLATE! } Podemos agregar las Pcs de la sgte manera: # cd /etc/nagios # pico hosts.cfg # Definicion de host para 'Router' define host{ use generic-host ; Name of host template to use host_name Router alias Router IBM 2210 address 200.48.185.49 check_command check-host-alive max_check_attempts 20 notification_interval 60 notification_period 24x7 notification_options d,u,r } # 'Proxyq' host definition define host{ use generic-host

; Name of host template to use

host_name Proxyq alias Proxy Adm address 200.48.185.53 parents Router check_command check-host-alive max_check_attempts 10 notification_interval 120 notification_period 24x7 notification_options d,u,r } # 'Labsq' host definition define host{ use generic-host

; Name of host template to use

host_name Labsq alias Proxy Labsq address 200.48.185.52 parents Router check_command check-host-alive max_check_attempts 10 notification_interval 120 notification_period 24x7 notification_options d,u,r } # 'Proxyq2' host definition define host{ use generic-host

; Name of host template to use

host_name Proxyq2 alias Correo Web address 200.48.185.51 parents Router check_command check-host-alive max_check_attempts 10 notification_interval 120 notification_period 24x7 notification_options d,u,r } 4.4.- Hostgroups.cfg Cada host debe pertenecer a un hostgroups y cada hostgroups tener al menos un contacs_groups . Las maquinas Router, Proxyq, Labs y Proxyq2 perteneceran al grupo: red , y el grupo de contactos sera: admins . # cd /etc/nagios # pico hostgroups.cfg define hostgroup{ hostgroup_name red alias Red contact_groups admins members Router,Proxyq,Labsq,Proxyq2 } 4.5 Contacts.cfg Los contactos son las personas a las que se les notificara de las posibles incidencias de las maquinas de la Red. En este caso se le notificara al usuario nagios mediante un email . # cd /etc/nagios # pico contacts.cfg define contact{ contact_name nagios alias Nagios Admin

service_notification_period 24x7 host_notification_period 24x7 service_notification_options w,u,c,r host_notification_options d,u,r service_notification_commands notify-by-email host_notification_commands host-notify-by-email email admin@localhost.localdomain } 4.6.- Contactgroups.cfg Cada contacto debe pertenecer a un grupo de contacto, como solo tenemos un contacto debemos crear un grupo al que pertenezca nuestro contacto : nagios , creamos el grupo de contacto: admins . # cd /etc/nagios # pico contactgroups.cfg define contactgroup{ contactgroup_name admins alias Administrators members nagios } 4.7 Services.cfg Aqu incluimos los servicos que deseamos monitorizar como : Ping , Ftp , http . # cd /etc/nagios # pico services.cfg

define service{ name generic-service ; The 'name' of this service template referenced in other service definitions active_checks_enabled 1 ; Active service checks are enabled passive_checks_enabled 1 ; Passive service checks are enabled/accepted parallelize_check 1 ; Active service checks should be parallelized (disabling this can lead to major performance problems) obsess_over_service 1 ; We should obsess over this service (if necessary) check_freshness 0 ; Default is to NOT check service 'freshness' notifications_enabled 1 ; Service notifications are enabled event_handler_enabled 1 ; Service event handler is enabled flap_detection_enabled 1 ; Flap detection is enabled process_perf_data 1 ; Process performance data retain_status_information 1 ; Retain status information across program restarts retain_nonstatus_information 1 ; Retain non-status information across program restarts register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE! } #Para el Router IBM define service{ use template to use

generic-service

; Name of service

host_name service_description is_volatile check_period max_check_attempts normal_check_interval retry_check_interval contact_groups notification_interval notification_period notification_options check_command }

Router PING 0 24x7 3 5 1 admins 240 24x7 c,r check_ping!100.0,20%!500.0,60%

# Para comprobar conexion de Proxyq # Service definition define service{ use generic-service template to use host_name service_description is_volatile check_period max_check_attempts normal_check_interval retry_check_interval contact_groups notification_interval notification_period notification_options check_command }

; Name of service

Proxyq PING 0 24x7 3 5 1 admins 240 24x7 c,r check_ping!100.0,20%!500.0,60%

# Para comprobar servico Web de Proxyq # Service definition define service{ use generic-service template to use host_name service_description is_volatile check_period max_check_attempts normal_check_interval retry_check_interval contact_groups notification_interval notification_period notification_options check_command } Proxyq HTTP 0 24x7 3 5 1 admins 120 24x7 w,u,c,r check_http

; Name of service

# Para comprobar servicio SMTP de Proxyq # Service definition define service{ use generic-service template to use

; Name of service

host_name service_description is_volatile check_period max_check_attempts normal_check_interval retry_check_interval contact_groups notification_interval notification_period notification_options check_command }

Proxyq SMTP 0 24x7 3 3 1 admins 120 24x7 w,u,c,r check_smtp

# Para comprobar conexion de Labsq # Service definition define service{ use generic-service template to use host_name service_description is_volatile check_period max_check_attempts normal_check_interval retry_check_interval contact_groups notification_interval notification_period notification_options check_command } Labsq 0 PING

; Name of service

24x7 3 5 1 admins 240 24x7 c,r check_ping!100.0,20%!500.0,60%

# Para comprobar servicio Web de Labsq # Service definition define service{ use generic-service template to use host_name service_description is_volatile check_period max_check_attempts normal_check_interval retry_check_interval contact_groups notification_interval notification_period notification_options check_command } Labsq 0 HTTP 24x7 3 5 1 admins 240 24x7 w,u,c,r check_http

; Name of service

# Para comprobar conexion de Proxyq2 # Service definition define service{

use template to use host_name service_description is_volatile check_period max_check_attempts normal_check_interval retry_check_interval contact_groups notification_interval notification_period notification_options check_command }

generic-service

; Name of service

Proxyq2 PING 0 24x7 3 5 1 admins 240 24x7 c,r check_ping!100.0,20%!500.0,60%

4.8 .- Escalations.cfg y Dependencies.cfg Se pueden comentar y nagios funcionar perfectamente, para ello comentar todo el contenido de estos archivos. 5.- Verificando la configuracion Una vez culminado de configurar los archivos cfg , probamos Nagios . # nagios - v /etc/nagios/nagios.cfg ##Debera aparecer sin ningun error lo sgte: Nagios 1.2 Copyright (c) 1999-2004 Ethan Galstad (nagios@nagios.org) Last Modified: 02-02-2004 License: GPL Reading configuration data... Running pre-flight check on configuration data... Checking services... Checked 7 services. Checking hosts... Checked 4 hosts. Checking host groups... Checked 1 host groups. Checking contacts... Checked 1 contacts. Checking contact groups... Checked 1 contact groups. Checking service escalations... Checked 0 service escalations. Checking host group escalations... Checked 0 host group 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 22 commands. Checking time periods... Checked 4 time periods. Checking for circular paths between hosts... Checking for circular service execution dependencies... Checking global event handlers... Checking obsessive compulsive service processor command... Checking misc settings... Total Warnings: 0 Total Errors: 0 Things look okay - No serious problems were detected during the pre-flight check 6.- Configuracion de Interfaz Web 6.1 Httpd.conf Editar httpd.conf # cd /etc/httpd/conf # pico httpd.conf ScriptAlias /nagios/cgi-bin/ /usr/lib/nagios/cgi/ <Directory /usr/lib/nagios/cgi/> AllowOverride AuthConfig Options ExecCGI Order allow,deny Allow from all </Directory> Alias /nagios/ /usr/share/nagios/ <Directory /usr/share/nagios/> Options ExecCGI AllowOverride AuthConfig Order allow,deny Allow from all </Directory> 6.2 Creacion de .htaccess Creamos el archivo .htaccess # cd /usr/share/nagios # pico .htaccess AuthName "Acceso a Nagios" AuthType Basic AuthUserFile /etc/nagios/htpasswd.users require valid-user Este archivo tambien debe de estar en el directorio de los cgi: # cd /usr/share/nagios # cp .htaccess /usr/lib/nagios/cgi

6.3.- Creacion de Usuario Web Creamos el usuario web : nagiosadmin para acceder desde el web # cd /usr/share/nagios # htpasswd -c /etc/nagios/htpasswd.users nagiosadmin # Aqu le damos el password para accesar via Web. # chown apache:apache /etc/nagios/htpasswd.users Listo reiniciamos los servicios httpd , nagios y probamos via web: http://200.48.185.51/nagios/