Sie sind auf Seite 1von 18

Configuracin de Nagios (Parte I)

30 de marzo 2012 Por Ivn Mora Prez en GNU / Linux , Monitoreo . Nagios es un monitor de sistema popular que ofrece control y alerta de servidores, aplicaciones, servicios, dispositivos de red ... Es muy modular y multiplataforma, ya que el ncleo de nagios es el procesador de la salida de los plugins que se pueden desarrollar en un lenguaje diferente Perl, Java , C, Python ... Tambin Nagios permite obtener informacin con el protocolo SNMP, como carga de la CPU, procesos que se estn ejecutando, espacio en disco, interfaces de red, etc

En este tutorial voy a configurar un escenario pequeo compuesto por un servidor Nagios (192.168.1.68), servidor de correo Postfix + Dovecot (192.168.1.200), el servidor DNS (192.168.1.50) y un router (192.1681.1), y voy a configurar Nagios para monitorear los principales servicios en nuestro escenario como SMTP, POP / IMAP, DNS, MySQL ... . 1 - Instalar repositorio EPEL:
# rpm -ivh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-65.noarch.rpm # rpm --import https://fedoraproject.org/static/217521F6.txt

. 2 - Instalacin Nagios y los plugins:


# yum install nagios nagios-plugins nagios-plugins-all ndoutils-mysql mysqlserver httpd php net-snmp net-snmp-utils postfix

. 3 - Cambiar contrasea para nagiosadmin web gui:


# cd /etc/nagios/ # htpasswd passwd nagiosadmin

. 4 - Desactivar SELinux:
# setenforce 0 # vi /etc/sysconfig/selinux SELINUX=disabled

. 5 - Agregar regla de iptables para el acceso web (/ etc / sysconfig / iptables):


-A INPUT -m tcp -p tcp --dport 80 -j ACCEPT # service iptables restart

. 6 - Ejecutar servicios y aadir init nivel predeterminado para empezar:


# # # # # # chkconfig chkconfig chkconfig chkconfig chkconfig chkconfig --levels --levels --levels --levels --levels --levels 235 235 235 235 235 235 httpd on mysqld on postfix on snmpd on ndo2db on nagios on

7 - Preparar nagios para trabajar con una base de datos mysql.:


# service mysqld start # mysqladmin -u root password root # mysql -u root -p mysql> create database nagios; mysql> grant all on nagios.* to 'nagios'@'localhost' identified by 'nagios'; mysql> quit # cd /usr/share/doc/ndoutils-mysql-1.4/db # chmod +x installdb && ./installdb -u nagios -p nagios -h localhost -d nagios # vi /etc/nagios/ndo2db.cfg: db_servertype=mysql db_host=localhost db_port=3306 db_name=nagios db_prefix=nagios_ db_user=nagios db_pass=nagios # vi /etc/nagios/nagios.cfg: broker_module=/usr/lib/nagios/brokers/ndomod.so config_file=/etc/nagios/ndomod.cfg # service ndo2db start # service nagios start

8 - Configuracin de alertas de correo Postfix (/ etc / postfix / main.cf).:


# vi /etc/postfix/main.cf myhostname = nagios-server.mydomain.com inet_interfaces = localhost relay_domains = mydomain.com, $mydestination relay_host = mail.mydomain.com smtpd_recipient_restrictions = reject_unauth_destination, permit_mynetworks,reject # service postfix start

Nagios archivos de configuracin:


/ Etc / nagios / cgi.cfg: Configuracin de funciones de acceso Web. / Etc / nagios / private / resource.cfg: Este archivo de configuracin es utilizada por Nagios para definir variables internas. / Etc / nagios.nagios.cfg: Archivo de configuracin principal para Nagios

. / Etc / nagios / objetos / * cfg: Este directorio es por defecto los archivos con las definiciones de los servicios, contactos, hosts, grupos, comandos timeperiods ... usados por defecto de configuracin de Nagios. / Etc / nagios / objetos / templates.cfg: plantillas predeterminadas definidas por defecto.

- Definicin de los contactos:


# vi /etc/nagios/objects/contacts.cfg define contact{ contact_name nagiosadmin ; Short name of user use generic-contact ; Inherit default values from generic-contact template alias Nagios Admin ; Full name of user email nagios@mydomain.com ; ***CHANGE TO YOUR MAIL ADDRESS*** } define contactgroup{ contactgroup_name admins alias Nagios Administrators members nagiosadmin }

Con esta configuracin se define un contacto llamado nagiosadmin con nagios@mydomain.com mail de notificacin, y se incluye en el grupo de administradores. El contacto nagiosadmin utilizar una plantilla genrica de contacto, esta configuracin se encuentran en el templates.cfg del archivo:
define contact{ name generic-contact ; The name of this contact template service_notification_period 24x7 ; service notifications can be sent anytime host_notification_period 24x7 ; host notifications can be sent anytime service_notification_options w,u,c,r,f,s ; send notifications for all service states, flapping events, and scheduled downtime events host_notification_options d,u,r,f,s ; send notifications for all host states, flapping events, and scheduled downtime events service_notification_commands notify-service-by-email ; send service notifications via email host_notification_commands notify-host-by-email ; send host notifications via email register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE! }

Estas plantillas de contacto utilizar la notificacin de correo electrnico, timeperiod tiempo para el host y el servicio 24 x 7. Aadir en / etc / nagios / nagios.cfg:
cfg_file=/etc/nagios/objects/contacts.cfg

- Definir timeperiods:
# vi /etc/nagios/objects/timeperiods.cfg define timeperiod{ timeperiod_name 24x7

alias 24 Hours A Day, 7 Days A Week sunday 00:00-24:00 monday 00:00-24:00 tuesday 00:00-24:00 wednesday 00:00-24:00 thursday 00:00-24:00 friday 00:00-24:00 saturday 00:00-24:00 }

Con esta definicin se configura un tiempo de 24 7, por lo que puede excluir rangos de tiempo como das festivos y das de fiesta, en este timeperiod por ejemplo:
define timeperiod{ name us-holidays timeperiod_name us-holidays alias US Holidays january 1 00:00-00:00 ; New Years monday -1 may 00:00-00:00 ; Memorial Day (last Monday in May) july 4 00:00-00:00 ; Independence Day monday 1 september 00:00-00:00 ; Labor Day (first Monday in September) thursday 4 november 00:00-00:00 ; Thanksgiving (4th Thursday in November) december 25 00:00-00:00 ; Christmas } define timeperiod{ timeperiod_name 24x7-with-holidays use 24x7 ;Include all the days exclude us-holidays ;Exclude holidays }

Aadir en / etc / nagios / nagios.cfg:


cfg_file=/etc/nagios/objects/timeperiods.cfg

- La adicin de ejemplos host (/ etc / nagios / objetos / mail.mydomain.cfg):


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. hostgroups linux-servers ; Hostgroups that belongs host_name mail.mydomain.com alias mail.mydomain.com icon_image redhat.gif ;icon image that show in nagios gui statusmap_image redhat.gd2 ;icon image that show nagios in map section address 192.168.1.200 parents dns-server ;parent nodes }

Los logotipos de imagen pueden encontrar en el directorio: / usr / share / nagios / html / imagenes / logos /
define hostgroup{ hostgroup_name mail-spool ; The name of the hostgroup alias Mail spool ; Long name of the group members mail.mydomain.com ; Comma separated list of hosts that belong to this

group }

Estos registros son para definir un nuevo husped, incluido en el hostgroup linux-servidores y utiliza la plantilla linux-server:
define host{ name linux-server ; The name of this host template use generic-host ; This template inherits other values from the generic-host template check_period 24x7 ; By default, Linux hosts are checked round the clock check_interval 5 ; Actively check the host every 5 minutes retry_interval 1 ; Schedule host check retries at 1 minute intervals max_check_attempts 10 ; Check each Linux host 10 times (max) check_command check-host-alive ; Default command to check Linux hosts notification_period workhours ; Linux admins hate to be woken up, so we only notify during the day ; Note that the notification_period variable is being overridden from ; the value that is inherited from the generic-host template! notification_interval 120 ; Resend notifications every 2 hours notification_options d,u,r ; Only send notifications for specific host states contact_groups admins ; Notifications get sent to the admins by default register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE! }

Aadir en / etc / nagios / nagios.cfg:


cfg_file=/etc/nagios/objects/mail.mydomain.cfg

- DEFINICIONES Servicios ejemplos:


# vi /etc/nagios/objects/dns-server.cfg define service{ use generic-service host_name dns-server service_description check root check_command check_dig!192.168.1.50!.!ns notifications_enabled 1 } # vi /etc/nagios/objects/localhost.cfg: define service{ use local-service ; Name of service template to use host_name nagios-server service_description MySQL check_command check_mysql!localhost!nagios!nagios!3306 notifications_enabled 1 } # vi /etc/nagios/objects/mail.mydomain.cfg define service{ use generic-service ; Name of service template to use

host_name mail.mydomain.com service_description SMTP check_command check_smtp notifications_enabled 1 }

- Ejemplos de comandos de definicin:


# DNS check definition define command { command_name check_dns command_line $USER1$/check_dns -H $ARG1$ -s $HOSTADDRESS$ } #Dig check query for root servers define command { command_name check_dig command_line $USER1$/check_dig -H $ARG1$ -l $ARG2$ -T $ARG3$ } #check for mysql connection define command { command_name check_mysql command_line $USER1$/check_mysql -H $ARG1$ --username $ARG2$ --password $ARG3$ --port $ARG4$ }

Nagios debe reiniciarse para cada cambio.


# service nagios restart

9 - Acceso a la interfaz web (http://192.168.1.68/nagios).:

Informacin general tctico:

Los anfitriones del seguimiento:

Grupos:

Servicios:

Mapa de la red:

Nagios alertas de correo:

Comparte esto:

Participacin

Configuracin de Nagios (Parte II)


01 de abril 2012 Por Ivn Mora Prez en la base de datos , GNU / Linux , Monitoreo . NagVis es un complemento para Nagios que permiten crear nuestros propios mapas con los servicios de informacin de Nagios. El mtodo clsico para recoger datos de los servicios de Nagios est leyendo el Status.dat archivo, este archivo se actualiza cada 10 segundos por defecto definido en la status_update_interval entrada en nagios.cfg. Mc livestatus es un mdulo cargado con Nagios que envan todas las actualizaciones de estado en socket UNIX y crear sentencias SQL. Mc lo livestatus es muy popular en el revelador de addons, es muy fcil de leer los datos de este proceso y la informacin en realidad no se actualizan cada 10. NagVis utiliza estado en tiempo real de informacin sobre los hosts ledo y servicios.

- Instalacin de mk livestatus: 1 - Instalar las dependencias.:


# yum install make gcc-c++ wget

. 2 - Descargar mk livestatus:
# cd /tmp && wget http://mathias-kettner.de/download/mk-livestatus1.1.12p7.tar.gz

. 3 - Extraiga el paquete:
# tar -xzvf mk-livestatus-1.1.12p7.tar.gz

. 4 - Instalar:
# cd mk-livestatus-1.1.12p7/ && ./configure # make && make install

. 5 - Crear nuevo directorio con permisos correctos:


# mkdir /usr/lib/nagios/mk-livestatus && chown nagios:apache /usr/lib/nagios/mk-livestatus

6 - Editar / etc / nagios / nagios.cfg.:


broker_module=/usr/local/lib/mk-livestatus/livestatus.o /usr/lib/nagios/mk-livestatus/live

. 7 - Reiniciar Nagios:
# service nagios restart

. 8 - Trate de lnea de comandos:


# echo 'GET hosts' | unixcat /usr/lib/nagios/mk-livestatus/live

Para obtener ms informacin sobre la sintaxis de consulta: http://mathias-kettner.de/checkmk_livestatus.html

Configuracin NagVis 1 - Instalar las dependencias.:


# yum install php-mbstring php-gd php-pdo graphviz rsync

. 2 - Descargar NagVis:
# cd /tmp && wget http://sourceforge.net/projects/nagvis/files/NagVis%201.6/nagvis1.6.4.tar.gz/download

. 3 - Extraiga el paquete:
# tar -xzvf nagvis-1.6.4.tar.gz

4 - Instalacin NagVis.:
cd nagvis-1.6.4/ && ./install.sh +--- Checking paths ----------------------------------------------------------+ | Please enter the path to the nagios base directory [/usr/sbin/nagios]: /etc/nagios | Please enter the path to NagVis base [/usr/sbin/nagvis]: /usr/share/nagvis | Do you want to use backend mklivestatus? [y]:y | Livestatus Socket (/etc/nagios/var/rw/live) MISSING | | Valid socket formats are: tcp:127.0.0.1:7668 or unix:/path/to/live | | Please enter your MKLivestatus socket: unix:/usr/lib/nagios/mklivestatus/live

5.-Editar / usr / sbin / NagVis / etc / nagvis.ini.php:


[defaults] ; default backend (id of the default backend) backend="live_1" [backend_live_1] backendtype="mklivestatus" socket="unix:/usr/lib/nagios/mk-livestatus/live"

6 - Volver a cargar apache.:


# service httpd reload

7 - http://192.168.1.68/nagvis de acceso.: Usuario y la contrasea por defecto admin / / admin

Configuracin PNP4Nagios pnp4nagios es un complemento para Nagios que pueden construir grficos basados en rrdtool como cactus de los ejrcitos y los cheques de servicios que producen Nagios. Podemos configurar pnpp4nagios en algunos modos, aqu voy a explicar como configurar con el modo mayor, bsicamente este modo reducir el uso de CPU debido a que el proceso no se llama para cada prueba de servicio / host. Para obtener ms informacin, consulte: http://docs.pnp4nagios.org/pnp-0.6/config 1 - Instalacin pnp4nagios.:
# yum install pnp4nagios

2 - Editar / etc / nagios / nagios.cfg.:


process_performance_data=1 # *** the template definition differs from the one in the original nagios.cfg service_perfdata_file=/var/log/pnp4nagios/service-perfdata service_perfdata_file_template=DATATYPE:: SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME:: $HOSTNAME$\tSERVICEDESC:: $SERVICEDESC$\tSERVICEPERFDATA:: $SERVICEPERFDATA$\tSERVICECHECKCOMMAND:: $SERVICECHECKCOMMAND$\tHOSTSTATE:: $HOSTSTATE$\tHOSTSTATETYPE::

$HOSTSTATETYPE$\tSERVICESTATE:: $SERVICESTATE$\tSERVICESTATETYPE:: $SERVICESTATETYPE$ service_perfdata_file_mode=a service_perfdata_file_processing_interval=15 service_perfdata_file_processing_command=process-service-perfdata-file # *** the template definition differs from the one in the original nagios.cfg # host_perfdata_file=/var/log/pnp4nagios/host-perfdata host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET:: $TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA:: $HOSTPERFDATA$\tHOSTCHECKCOMMAND:: $HOSTCHECKCOMMAND$\tHOSTSTATE:: $HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$ host_perfdata_file_mode=a host_perfdata_file_processing_interval=15 host_perfdata_file_processing_command=process-host-perfdata-file

3 - Editar / etc / nagios / objetos / commands.cfg.:


define command{ command_name process-service-perfdata-file command_line /usr/libexec/pnp4nagios/process_perfdata.pl -bulk=/var/log/pnp4nagios/service-perfdata } define command{ command_name process-host-perfdata-file command_line /usr/libexec/pnp4nagios/process_perfdata.pl -bulk=/var/log/pnp4nagios/host-perfdata }

4 -. Reinicie Nagios
# service nagios restart

. 5 - Verifique la configuracin:
# cd /tmp ; wget http://verify.pnp4nagios.org/verify_pnp_config && perl verify_pnp_config --mode bulk --config=/etc/nagios/nagios.cfg -pnpcfg=/etc/pnp4nagios

Popups PNP4Nagios para Nagios . 1 - Copia el javascript estatus de cabecera de pnp4nagios a nagios:
# cp /usr/share/doc/pnp4nagios-0.6.16/contrib/ssi/status-header.ssi /usr/share/nagios/html/ssi/

. 2 - Agregar una nueva plantilla a utilizar y aplicar a los hosts y servicios para mostrar popup grfico definido en el action_url entrada:
# vi /etc/nagios/objects/templates.cfg define host{ name host-pnp action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=_HOST_' class='tips' rel='/pnp4nagios/popup?host=$HOSTNAME$&srv=_HOST_ } define service{ name service-pnp action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=$SERVICEDESC$' class='tips' rel='/pnp4nagios/popup?host=$HOSTNAME$&srv=$SERVICEDESC$ }

3 -. Reinicie Nagios
# service nagios restart

Adicin de nuevos servicios al grfico para PNP4Nagios Ahora voy a aadir un script que generar el nmero de consultas SQL de un servidor MySQL y PNP4Nagios se representa grficamente las estadsticas de consultas. . 1 - Instalacin de dependencias:
# yum install perl-Class-DBI-mysql

2 - Descargar Archivos de Comandos.: http://exchange.nagios.org/components/com_mtree/attachment.php?link_id=174&cf_id= 30 http://exchange.nagios.org/components/com_mtree/attachment.php?link_id=174&cf_id= 36 . 3 - Agregar nuevo comando y las variables internas para nagios:
#vi /etc/nagios/objects/commands.cfg define command{ command_name check_mysqld command_line $USER1$/check_mysqld.pl -H $HOSTADDRESS$ -u nagios -p $USER7$ -a uptime,threads_connected,questions,slow_queries,open_tables -w ',,,,' -c ',,,,' -A $USER21$ }

- Editar / etc / nagios / private / resource.cfg y aadir:


$USER7$=nagios $USER21$='com_select,com_update,com_insert,com_insert_select, com_commit,com_delete,com_rollback,aborted_clients, aborted_connects,binlog_cache_disk_use,binlog_cache_use, bytes_received,bytes_sent,connections,created_tmp_disk_tables, created_tmp_files,created_tmp_tables,delayed_errors, delayed_insert_threads,delayed_writes,handler_update,handler_write, handler_delete,handler_read_first,handler_read_key, handler_read_next,handler_read_prev,handler_read_rnd, handler_read_rnd_next,key_blocks_not_flushed, key_blocks_unused,key_blocks_used,key_read_requests,key_reads,

key_write_requests,key_writes,max_used_connections, not_flushed_delayed_rows,open_files,open_streams,open_tables, opened_tables,prepared_stmt_count,qcache_free_blocks, qcache_free_memory,qcache_hits,qcache_inserts, qcache_lowmem_prunes,qcache_not_cached, qcache_queries_in_cache,qcache_total_blocks,questions, select_full_join,select_rangle_check,slow_launch_threads, slow_queries,table_locks_immediate,table_locks_waited, threads_cached,threads_connected,threads_created, threads_running'

4 -. Editar / etc / nagios / objetos / localhost.cfg


define service { use local-service,service-pnp hostgroup_name nagios-pool service_description MYSQLD check_command check_mysqld!nagios!nagios }

. 5 - Copiar archivo script y php plantilla para pnp4nagios: - Crear archivo / etc/pnp4nagios/check_commands/check_mysqld.cfg y aadir:
# vi /etc/pnp4nagios/check_commands/check_mysqld.cfg # Adjust the whole RRD Database DATATYPE = COUNTER

- Copie el script en perl en el directorio de plugins por defecto para nagios (/ usr / lib / nagios / plugins):
/usr/lib/nagios/plugins/check_mysqld.pl # chmod 755 /usr/lib/nagios/plugins/check_mysqld.pl # chgrp nagios /usr/lib/nagios/plugins/check_mysqld.pl

- Copia el script php para generar datos para los grficos rrdtool:
/usr/share/nagios/html/pnp4nagios/templates.dist/check_mysqld.php

Para obtener ms informacin para crear plantillas personalizadas para pnp4nagios, vase:

http://docs.pnp4nagios.org/pnp-0.6/tpl_custom

Das könnte Ihnen auch gefallen