| 1 | Gestion y Monitoreo de Redes |
|---|
| 2 | Instalacion y Configuracion de Nagios |
|---|
| 3 | |
|---|
| 4 | Notas: |
|---|
| 5 | ------ |
|---|
| 6 | * Comandos que empiezan con un "$" implica que deberia ejecutar el comando |
|---|
| 7 | como un usuario general - no como root. |
|---|
| 8 | * Comandos que empiezan con un "#" implica que deberia trabajar como el usuario root. |
|---|
| 9 | * Comandos con lineas mas especificas (como "GW-RTR>" o "mysql>") implica que esta |
|---|
| 10 | ejecutando el comando en un equipo remoto o dentro otro programa. |
|---|
| 11 | * Si una linea termina con un "\" esto indica que el comando sigue en la proxima |
|---|
| 12 | linea y Ud. deberia tratar el comando si como fuera en una sola linea. |
|---|
| 13 | |
|---|
| 14 | Ayuda |
|---|
| 15 | ----- |
|---|
| 16 | * Todo los archivos de configuracion estan disponible aqui: |
|---|
| 17 | |
|---|
| 18 | http://noc.ws.nsrc.org/configs/nagios3/ |
|---|
| 19 | |
|---|
| 20 | Ejercicios |
|---|
| 21 | ----------- |
|---|
| 22 | |
|---|
| 23 | Ejercicios Parte I |
|---|
| 24 | ------------------ |
|---|
| 25 | |
|---|
| 26 | 0. HAZ UNA CONECCION SSH A SU PC |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | 1. INSTALA NAGIOS |
|---|
| 30 | |
|---|
| 31 | Para instalar Nagios version 3 en Ubuntu podria hacer esto como el usuario |
|---|
| 32 | sysadmn usando "sudo" o como root. Como sysadm es asi: |
|---|
| 33 | |
|---|
| 34 | $ sudo apt-get install nagios3 |
|---|
| 35 | |
|---|
| 36 | Durante la instalacion es posible que Nagios va a instalar el programa |
|---|
| 37 | Postfix como un MTA (Servidor de Correo) para que se puede mandar correos |
|---|
| 38 | si es necesario. Si tiene que elegir como se instala Postfix responde con: |
|---|
| 39 | |
|---|
| 40 | "Internet Site" |
|---|
| 41 | |
|---|
| 42 | Cuando Nagios te pide por una contrasena usa la contrasena del curso. |
|---|
| 43 | |
|---|
| 44 | Si quieres tener la documentacion de Nagios en HTML (disponible a traves |
|---|
| 45 | el interfaz de Nagios) instala: |
|---|
| 46 | |
|---|
| 47 | $ sudo apt-get install nagios3-doc |
|---|
| 48 | |
|---|
| 49 | Ya, Nagios esta instalado. |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | 2. USAR NAGIOS |
|---|
| 53 | |
|---|
| 54 | - En un Navegador vaya al: |
|---|
| 55 | |
|---|
| 56 | http://pcN.ws.nsrc.org/nagios3/ |
|---|
| 57 | |
|---|
| 58 | - Cuando pregunta por un usuario y contrasena usa: |
|---|
| 59 | |
|---|
| 60 | user: nagiosadmin |
|---|
| 61 | pass: <clave del taller> |
|---|
| 62 | |
|---|
| 63 | Vas a ver que Nagios tiene una entrada por tu maquina (pcN.ws.nsrc.org |
|---|
| 64 | como "localhost" y por el enlace del puerto (gateway) de nuestra red |
|---|
| 65 | del taller. |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | 3. REVISAR LOS ARCHIVOS DE CONFIGURACION |
|---|
| 69 | |
|---|
| 70 | $ cd /etc/nagios3/ |
|---|
| 71 | |
|---|
| 72 | # ls -l |
|---|
| 73 | -rw-r--r-- 1 root root 1882 2008-12-18 13:42 apache2.conf |
|---|
| 74 | -rw-r--r-- 1 root root 10524 2008-12-18 13:44 cgi.cfg |
|---|
| 75 | -rw-r--r-- 1 root root 2429 2008-12-18 13:44 commands.cfg |
|---|
| 76 | drwxr-xr-x 2 root root 4096 2009-02-14 12:33 conf.d |
|---|
| 77 | -rw-r--r-- 1 root root 26 2009-02-14 12:36 htpasswd.users |
|---|
| 78 | -rw-r--r-- 1 root root 42539 2008-12-18 13:44 nagios.cfg |
|---|
| 79 | -rw-r----- 1 root nagios 1293 2008-12-18 13:42 resource.cfg |
|---|
| 80 | drwxr-xr-x 2 root root 4096 2009-02-14 12:32 stylesheets |
|---|
| 81 | |
|---|
| 82 | $ ls -l conf.d/ |
|---|
| 83 | |
|---|
| 84 | -rw-r--r-- 1 root root 1695 2008-12-18 13:42 contacts_nagios2.cfg |
|---|
| 85 | -rw-r--r-- 1 root root 418 2008-12-18 13:42 extinfo_nagios2.cfg |
|---|
| 86 | -rw-r--r-- 1 root root 1152 2008-12-18 13:42 generic-host_nagios2.cfg |
|---|
| 87 | -rw-r--r-- 1 root root 1803 2008-12-18 13:42 generic-service_nagios2.cfg |
|---|
| 88 | -rw-r--r-- 1 root root 210 2009-02-14 12:33 host-gateway_nagios3.cfg |
|---|
| 89 | -rw-r--r-- 1 root root 976 2008-12-18 13:42 hostgroups_nagios2.cfg |
|---|
| 90 | -rw-r--r-- 1 root root 2167 2008-12-18 13:42 localhost_nagios2.cfg |
|---|
| 91 | -rw-r--r-- 1 root root 1005 2008-12-18 13:42 services_nagios2.cfg |
|---|
| 92 | -rw-r--r-- 1 root root 1609 2008-12-18 13:42 timeperiods_nagios2.cfg |
|---|
| 93 | |
|---|
| 94 | Archivos con un "2" en su nombre no han cambiado desde version 2 de Nagios. |
|---|
| 95 | El archivo host-gateway_nagios3.cfg fue cambiado entre versiones, asi tiene |
|---|
| 96 | un nombre nuevo. |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | 4. REVISA EL ARCHIVO DE CONFIGURACION POR EL GATEWAY DEL CURSO |
|---|
| 100 | |
|---|
| 101 | $ cd /etc/nagios3/conf.d/ |
|---|
| 102 | $ cat host-gateway_nagios3.cfg |
|---|
| 103 | |
|---|
| 104 | Vas a ver algo como: |
|---|
| 105 | |
|---|
| 106 | # a host definition for the gateway of the default route |
|---|
| 107 | define host { |
|---|
| 108 | host_name gateway |
|---|
| 109 | alias Default Gateway |
|---|
| 110 | address 10.10.0.254 |
|---|
| 111 | use generic-host |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | Esto es solo para empezar de acustambrarse a los archivos de configuracion |
|---|
| 115 | de Nagios. |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | PARTE II |
|---|
| 120 | Configurando Equipos en Nagios |
|---|
| 121 | ----------------------------------------------------------------------------- |
|---|
| 122 | |
|---|
| 123 | 0. EL ORDEN DE LA CONFIGURACION |
|---|
| 124 | |
|---|
| 125 | Conceptualmente vamos a construir nuestra configuracion desde arriba por abajo de nuestra Red. |
|---|
| 126 | Asi, vamos a definir entradas por los rutadores y conmutadores (switches) primero. Despues |
|---|
| 127 | empezamos con los PCs. Cuando tengas todo los dispositivos configurado tienes que configurar |
|---|
| 128 | grupos de dispositivos y darlos nombres. Finalmente, agregra chequeos de servicios a los |
|---|
| 129 | grupos de dispositivos. |
|---|
| 130 | |
|---|
| 131 | Flujo Conceptual de Configuracion |
|---|
| 132 | --------------------------------- |
|---|
| 133 | |
|---|
| 134 | == Etapa 1 == |
|---|
| 135 | |
|---|
| 136 | gw-rtr ==> routers.cfg |
|---|
| 137 | | |
|---|
| 138 | | |
|---|
| 139 | sw ==> switches.cfg (padre es gw-rtr) |
|---|
| 140 | | |
|---|
| 141 | | |
|---|
| 142 | rtrN ==> routers.cfg (padre es sw) |
|---|
| 143 | | |
|---|
| 144 | | |
|---|
| 145 | pcN ==> pcs.cfg (padre es rtrN) |
|---|
| 146 | |
|---|
| 147 | == Etapa 2 == |
|---|
| 148 | |
|---|
| 149 | Agrupar los dispositivos ==> hostgroups_nagios2.cfg |
|---|
| 150 | - routers (gw-rtr,rtr1,rtr2,...,rtr6) |
|---|
| 151 | - switches (sw) |
|---|
| 152 | - pcs (pc1,pc2,...,pc24,noc) |
|---|
| 153 | - ssh-servers (localhost,pc1,pc2,...,pc24,ap1,ap2,rtr1,...,rtr6) |
|---|
| 154 | - http-servers (localhost,pc1,pc2,...,pc24) |
|---|
| 155 | |
|---|
| 156 | == Etapa 3 == |
|---|
| 157 | |
|---|
| 158 | Asignar chequeos de servicio a grupos ==> services_nagios2.cfg |
|---|
| 159 | - http-servers ==> HTTP |
|---|
| 160 | - ssh-servers ==> SSH |
|---|
| 161 | |
|---|
| 162 | == Opcional 1 == |
|---|
| 163 | |
|---|
| 164 | Configura acceso de "guest" al interfaz web ==> /etc/nagios3/cgi.cfg |
|---|
| 165 | |
|---|
| 166 | == Opcional 2 == |
|---|
| 167 | |
|---|
| 168 | Crea Grupos de Servicios ==> servicegroups.cfg |
|---|
| 169 | |
|---|
| 170 | == Opcional 3 == |
|---|
| 171 | |
|---|
| 172 | Agregar informacion extendida a los dispositivos ==> extinfo_nagios2.cfg |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | 1. CONFIGURAR NAGIOS PARA MONITOREAR LOS ROUTERS DEL CURSO |
|---|
| 176 | |
|---|
| 177 | Vamos a trabajar como el usuario root. |
|---|
| 178 | |
|---|
| 179 | # sudo bash |
|---|
| 180 | # cd /etc/nagios3/conf.d/ |
|---|
| 181 | # vi routers.cfg |
|---|
| 182 | |
|---|
| 183 | Abajo son las entradas del archivo. Sugerimos que ud. tipea uno a dos |
|---|
| 184 | de las entradas. Despues puede hacer un corte y pegar por lo demas. |
|---|
| 185 | |
|---|
| 186 | Entiende porque el "parent" de rtr1 a rtr6 es "sw"? |
|---|
| 187 | |
|---|
| 188 | Despues que terminamos con este archivo vamos a configurar la entrada por |
|---|
| 189 | el switch "sw". Se puede usar el diagrama de red como referencia. |
|---|
| 190 | |
|---|
| 191 | # |
|---|
| 192 | # Archivo con definiciones de los Routers por Nagios |
|---|
| 193 | # |
|---|
| 194 | |
|---|
| 195 | define host { |
|---|
| 196 | use generic-host |
|---|
| 197 | host_name rtr |
|---|
| 198 | alias rutador del borde |
|---|
| 199 | address 10.10.0.254 |
|---|
| 200 | } |
|---|
| 201 | |
|---|
| 202 | define host { |
|---|
| 203 | use generic-host |
|---|
| 204 | host_name rtr1 |
|---|
| 205 | alias rutador del grupo 1 de VMs |
|---|
| 206 | address 10.10.1.254 |
|---|
| 207 | parents sw |
|---|
| 208 | } |
|---|
| 209 | |
|---|
| 210 | define host { |
|---|
| 211 | use generic-host |
|---|
| 212 | host_name rtr2 |
|---|
| 213 | alias rutador del grupo 2 de VMs |
|---|
| 214 | address 10.10.2.254 |
|---|
| 215 | parents sw |
|---|
| 216 | } |
|---|
| 217 | |
|---|
| 218 | define host { |
|---|
| 219 | use generic-host |
|---|
| 220 | host_name rtr3 |
|---|
| 221 | alias rutador del grupo 3 de VMs |
|---|
| 222 | address 10.10.3.254 |
|---|
| 223 | parents sw |
|---|
| 224 | } |
|---|
| 225 | |
|---|
| 226 | define host { |
|---|
| 227 | use generic-host |
|---|
| 228 | host_name rtr4 |
|---|
| 229 | alias rutador del grupo 4 de VMs |
|---|
| 230 | address 10.10.4.254 |
|---|
| 231 | parents sw |
|---|
| 232 | } |
|---|
| 233 | |
|---|
| 234 | define host { |
|---|
| 235 | use generic-host |
|---|
| 236 | host_name rtr5 |
|---|
| 237 | alias rutador del grupo 5 de VMs |
|---|
| 238 | address 10.10.5.254 |
|---|
| 239 | parents sw |
|---|
| 240 | } |
|---|
| 241 | |
|---|
| 242 | define host { |
|---|
| 243 | use generic-host |
|---|
| 244 | host_name rtr6 |
|---|
| 245 | alias rutador del grupo 6 de VMs |
|---|
| 246 | address 10.10.6.254 |
|---|
| 247 | parents sw |
|---|
| 248 | } |
|---|
| 249 | |
|---|
| 250 | # |
|---|
| 251 | # Nuestros puntos de acceso inalambrico |
|---|
| 252 | # |
|---|
| 253 | |
|---|
| 254 | define host { |
|---|
| 255 | use generic-host |
|---|
| 256 | host_name ap1 |
|---|
| 257 | alias Access Point 1 |
|---|
| 258 | address 10.10.0.251 |
|---|
| 259 | parents sw |
|---|
| 260 | } |
|---|
| 261 | |
|---|
| 262 | define host { |
|---|
| 263 | use generic-host |
|---|
| 264 | host_name ap2 |
|---|
| 265 | alias Access Point 2 |
|---|
| 266 | address 10.10.0.252 |
|---|
| 267 | parents sw |
|---|
| 268 | } |
|---|
| 269 | |
|---|
| 270 | |
|---|
| 271 | # |
|---|
| 272 | # Fin del archivo |
|---|
| 273 | # |
|---|
| 274 | |
|---|
| 275 | Graba y salga del archivo /etc/nagios3/conf.d/routers.cfg |
|---|
| 276 | |
|---|
| 277 | |
|---|
| 278 | 2. CONFIGURACION DE LOS SWITCHES |
|---|
| 279 | |
|---|
| 280 | Nota que cada switch tendra una relacion de pariente con uno de las rutadores. |
|---|
| 281 | |
|---|
| 282 | # vi switches.cfg |
|---|
| 283 | |
|---|
| 284 | Primero el switch de "backbone" (troncal) |
|---|
| 285 | |
|---|
| 286 | # |
|---|
| 287 | # Archivo con definiciones de los Switches por Nagios |
|---|
| 288 | # |
|---|
| 289 | |
|---|
| 290 | define host { |
|---|
| 291 | use generic-host |
|---|
| 292 | host_name sw |
|---|
| 293 | alias conmuatdor troncal |
|---|
| 294 | address 10.10.0.253 |
|---|
| 295 | parents rtr |
|---|
| 296 | } |
|---|
| 297 | |
|---|
| 298 | # |
|---|
| 299 | # Fin del archivo |
|---|
| 300 | # |
|---|
| 301 | |
|---|
| 302 | Graba y salga del archivo /etc/nagios3/conf.d/switches.cfg |
|---|
| 303 | |
|---|
| 304 | Por este taller hay solo un switch para configurar. |
|---|
| 305 | |
|---|
| 306 | |
|---|
| 307 | 3. CONFIGURACION DE LOS PCS |
|---|
| 308 | |
|---|
| 309 | Ahora en un solo archivo vamos a definir todo los PCs en la sala. Puede hacer esto en varios archivos |
|---|
| 310 | (grupo1-pcs.cfg, grupo2-pcs.cfg) si quiere, pero por nuestro curso usamos un solo archivo. |
|---|
| 311 | |
|---|
| 312 | Abajo hay tres entradas de ejemplo. Usa estos para hacer las entradas por todo los PCs |
|---|
| 313 | |
|---|
| 314 | PCs de grupo 1 tienen como padre el enrutador del grupo 1, o rtr1. PCs de grupo 2 tienen como padre el |
|---|
| 315 | enrutador del grupo 2 or rtr2. Normalmente seria un switch, pero por el hecho que estamos usando maquinas |
|---|
| 316 | virtuales no hay un switch fisico disponible. |
|---|
| 317 | |
|---|
| 318 | IMPORTANTE! No agrega una entrada por tu PC. Esto ya esta hecho en el archivo |
|---|
| 319 | /etc/nagios3/conf.d/localhost_nagios2.cfg - En este archivo puede definir el "parent" por el localhost |
|---|
| 320 | para que el instante de Nagios aparesca bien en los graficos de su Red. |
|---|
| 321 | |
|---|
| 322 | Vea http://nsrcwsnoc.ddns.net/wikis/gt/wiki/DiagramaRed para ver todo los PCs, los grupos, y que |
|---|
| 323 | router pertenesca a cada grupo. |
|---|
| 324 | |
|---|
| 325 | # vi pcs.cfg |
|---|
| 326 | |
|---|
| 327 | # |
|---|
| 328 | # Archivo con definiciones de los PCs por Nagios |
|---|
| 329 | # |
|---|
| 330 | |
|---|
| 331 | # |
|---|
| 332 | # Nuestro NOC |
|---|
| 333 | # |
|---|
| 334 | |
|---|
| 335 | define host { |
|---|
| 336 | use generic-host |
|---|
| 337 | host_name noc |
|---|
| 338 | alias Centro de Operaciones |
|---|
| 339 | address 10.10.0.254 |
|---|
| 340 | parents sw |
|---|
| 341 | } |
|---|
| 342 | |
|---|
| 343 | # |
|---|
| 344 | # PCs del Grupo 1 |
|---|
| 345 | # |
|---|
| 346 | |
|---|
| 347 | define host { |
|---|
| 348 | use generic-host |
|---|
| 349 | host_name pc1 |
|---|
| 350 | alias pc1 del grupo 1 |
|---|
| 351 | address 10.10.1.1 |
|---|
| 352 | parents rtr1 |
|---|
| 353 | } |
|---|
| 354 | |
|---|
| 355 | define host { |
|---|
| 356 | use generic-host |
|---|
| 357 | host_name pc3 |
|---|
| 358 | alias pc3 del grupo 1 |
|---|
| 359 | address 10.10.1.3 |
|---|
| 360 | parents rtr1 |
|---|
| 361 | } |
|---|
| 362 | |
|---|
| 363 | # |
|---|
| 364 | # termina pc5 y pc7 |
|---|
| 365 | # |
|---|
| 366 | |
|---|
| 367 | # |
|---|
| 368 | # PCs del Grupo 2 |
|---|
| 369 | # |
|---|
| 370 | |
|---|
| 371 | define host { |
|---|
| 372 | use generic-host |
|---|
| 373 | host_name pc2 |
|---|
| 374 | alias pc2 del grupo 2 |
|---|
| 375 | address 10.10.2.2 |
|---|
| 376 | parents rtr2 |
|---|
| 377 | } |
|---|
| 378 | |
|---|
| 379 | define host { |
|---|
| 380 | use generic-host |
|---|
| 381 | host_name pc4 |
|---|
| 382 | alias pc4 del grupo 2 |
|---|
| 383 | address 10.10.2.4 |
|---|
| 384 | parents rtr2 |
|---|
| 385 | } |
|---|
| 386 | |
|---|
| 387 | # |
|---|
| 388 | # termina pc6 y pc8 |
|---|
| 389 | # |
|---|
| 390 | |
|---|
| 391 | # |
|---|
| 392 | # termina el archivo por grupos 3 a 6 |
|---|
| 393 | # |
|---|
| 394 | |
|---|
| 395 | Ahora sigue y agrega entradas por todo los PCs. |
|---|
| 396 | |
|---|
| 397 | Graba y salga del archivo /etc/nagios3/conf.d/pcs.cfg |
|---|
| 398 | |
|---|
| 399 | Ahora verificamos que nuestros archivos estan bien configurados |
|---|
| 400 | |
|---|
| 401 | |
|---|
| 402 | |
|---|
| 403 | 5. VERIFICAR CONFIGURATION DE NAGIOS |
|---|
| 404 | |
|---|
| 405 | # nagios3 -v /etc/nagios3/nagios.cfg |
|---|
| 406 | |
|---|
| 407 | ... Deberia ver : |
|---|
| 408 | |
|---|
| 409 | Total Warnings: NN (aviso de falta de chequeo de servicios. No se preocupa.) |
|---|
| 410 | Total Errors: 0 |
|---|
| 411 | |
|---|
| 412 | Things look okay - No serious problems were detected during the check. |
|---|
| 413 | |
|---|
| 414 | Si hay errores lea que dice en la pantalla y intenta reparar los problemas en |
|---|
| 415 | los archivos de configuracion. |
|---|
| 416 | |
|---|
| 417 | |
|---|
| 418 | 6. COMO PARAR, INICIALIZAR Y/O REINICIALIZR NAGIOS |
|---|
| 419 | |
|---|
| 420 | # /etc/init.d/nagios3 stop |
|---|
| 421 | # /etc/init.d/nagios3 start |
|---|
| 422 | |
|---|
| 423 | Puede hacer "restart" pero no es 100% confiable. |
|---|
| 424 | |
|---|
| 425 | |
|---|
| 426 | 7. VERIFICA LA CONFIGURACION DE NAGIOS HASTA AHORA |
|---|
| 427 | |
|---|
| 428 | Vaya al interfaz de la Web (http://pcN.ws.nsrc.org/nagios3) y verifica que las |
|---|
| 429 | entradas (PCs, conmutadores, rutadores) estan visibles. Apreta "Host Detail" |
|---|
| 430 | por la izquierda en Nagios para ver esto. |
|---|
| 431 | |
|---|
| 432 | |
|---|
| 433 | PARTE III |
|---|
| 434 | Configurar un Chequeo de Servicio por el NOC del Taller |
|---|
| 435 | ----------------------------------------------------------------------------- |
|---|
| 436 | |
|---|
| 437 | 0. CONFIGURAR CHEQUE DE SERVICIOS |
|---|
| 438 | |
|---|
| 439 | Ahora que tenemos el hardware configurado vamos a configurar monitoreo de services, hacer grupos |
|---|
| 440 | de hardware y servicios, etc. |
|---|
| 441 | |
|---|
| 442 | |
|---|
| 443 | 1. HACER UN CHEQUEO DE SERVICIO SSH POR EL ROUTER DE SU GRUPO |
|---|
| 444 | |
|---|
| 445 | # vi hostgroups_nagios2.cfg |
|---|
| 446 | |
|---|
| 447 | - Busca el hostgroup con nombre "ssh-servers". En la linea de "Members" cambia la linea: |
|---|
| 448 | |
|---|
| 449 | members localhost |
|---|
| 450 | |
|---|
| 451 | a |
|---|
| 452 | |
|---|
| 453 | members localhost,rtrN |
|---|
| 454 | |
|---|
| 455 | donde el "N" es el numero de su grupo (asi, "rtr1" por el grupo uno). |
|---|
| 456 | |
|---|
| 457 | Salga y graba el archivo. |
|---|
| 458 | |
|---|
| 459 | Verifica que todo esta bien: |
|---|
| 460 | |
|---|
| 461 | # nagios3 -v /etc/nagios3/nagios.cfg |
|---|
| 462 | |
|---|
| 463 | Reinitializar Nagios para ver los servicios nuevos asociado con el router rtrN: |
|---|
| 464 | |
|---|
| 465 | # /etc/init.d/nagios3 stop |
|---|
| 466 | # /etc/init.d/nagios3 start |
|---|
| 467 | |
|---|
| 468 | En el interfaz Web de Nagios: |
|---|
| 469 | |
|---|
| 470 | http://noc.ws.nsrc.org/nagios3/ |
|---|
| 471 | |
|---|
| 472 | Apreta "Service Detail" (menu a la izquierda) para ver su entrada nueva. |
|---|
| 473 | |
|---|
| 474 | |
|---|
| 475 | |
|---|
| 476 | PARTE IV |
|---|
| 477 | Definir Servicios por todo sus Dispositvos |
|---|
| 478 | ----------------------------------------------------------------------------- |
|---|
| 479 | |
|---|
| 480 | 0. SERVICIOS CORRIENDO |
|---|
| 481 | |
|---|
| 482 | rutadores: ssh y snmp |
|---|
| 483 | conmutadores: snmp |
|---|
| 484 | aps: ssh y snmp |
|---|
| 485 | pcs: ssh, http y snmp |
|---|
| 486 | |
|---|
| 487 | Configuramos Nagios hacer checqueos por estes servicios en las maquinas de |
|---|
| 488 | nuestro taller. La configuracion de chequeo de SSH y HTTP es facil. De SNMP |
|---|
| 489 | es mas involcrado y es un ejercicio opcional. |
|---|
| 490 | |
|---|
| 491 | |
|---|
| 492 | 1. CONFIGURAR EL CHEQUEO DE SSH POR LOS PCS, ROUTERS Y APS |
|---|
| 493 | |
|---|
| 494 | En el archivo /etc/nagios3/conf.d/hostgroups_nagios2.cfg ya hay una entrada por |
|---|
| 495 | el chequeo del servicio de SSH. Solo tiene que redefinirlo. |
|---|
| 496 | |
|---|
| 497 | Abre el archivo: |
|---|
| 498 | |
|---|
| 499 | # vi /etc/nagios3/conf.d/hostgroups_nagios2.cfg |
|---|
| 500 | |
|---|
| 501 | Al principio la entrada de ssh se vea asi: |
|---|
| 502 | |
|---|
| 503 | # A list of your ssh-accessible servers |
|---|
| 504 | define hostgroup { |
|---|
| 505 | hostgroup_name ssh-servers |
|---|
| 506 | alias SSH servers |
|---|
| 507 | members localhost,noc |
|---|
| 508 | } |
|---|
| 509 | |
|---|
| 510 | Que deberiamos cambiar? Si, la linea de "members". Va a ser largo con todo los PCs listado |
|---|
| 511 | _menos_ su PC. Por ejemplo: |
|---|
| 512 | |
|---|
| 513 | define hostgroup { |
|---|
| 514 | hostgroup_name ssh-servers |
|---|
| 515 | alias SSH servers |
|---|
| 516 | members localhost,noc,pc1,pc2,pc3,pc4....,rtr1,rtr2,rtr3,...,ap1,ap2 |
|---|
| 517 | } |
|---|
| 518 | |
|---|
| 519 | Pero, incluye todo los PCs, Routers y APs |
|---|
| 520 | |
|---|
| 521 | hora salga y graba el archivo y verifica que todo esta bien: |
|---|
| 522 | |
|---|
| 523 | # nagios3 -v /etc/nagios3/nagios.cfg |
|---|
| 524 | |
|---|
| 525 | Si todo esta bien haz: |
|---|
| 526 | |
|---|
| 527 | # /etc/init.d/nagios3 stop |
|---|
| 528 | # /etc/init.d/nagios3 start |
|---|
| 529 | |
|---|
| 530 | y revisa todo en la pagina web de Nagios que el chequeo de servicio de SSH esta |
|---|
| 531 | funcionando. |
|---|
| 532 | |
|---|
| 533 | |
|---|
| 534 | |
|---|
| 535 | 2. CONFIGURAR EL CHEQUEO DE HTTP POR TODO LOS PCS |
|---|
| 536 | |
|---|
| 537 | - Esto es casi igual que el ejercicio anterior. Solo haz el cambio por el servicio |
|---|
| 538 | HTTP agregando los miembros de cada PC (rutadores y conmutadores no). Recuerda de |
|---|
| 539 | no agregar tu maquina porque ya esta configurado como "localhost" |
|---|
| 540 | |
|---|
| 541 | |
|---|
| 542 | PARTE V |
|---|
| 543 | Crear mas Grupos del Host |
|---|
| 544 | ----------------------------------------------------------------------------- |
|---|
| 545 | |
|---|
| 546 | 1. Actualizar /etc/nagios3/conf.d/hostgroups_nagios2.cfg |
|---|
| 547 | |
|---|
| 548 | Por los ejercicios que vienen es muy util tener hech los grupos de hosts: |
|---|
| 549 | |
|---|
| 550 | debian-servers |
|---|
| 551 | routers |
|---|
| 552 | switches |
|---|
| 553 | |
|---|
| 554 | Abre el archivo /etc/nagios3/conf.d/hostgroups_nagios2.cfg y vas a ver una |
|---|
| 555 | entra para debian-servers que solo incluya el localhost. Actualizar esto |
|---|
| 556 | para incluir todo los PCs en la sala. |
|---|
| 557 | |
|---|
| 558 | # vi /etc/nagios3/conf.d/hostgroups_nagios2.cfg |
|---|
| 559 | |
|---|
| 560 | Actualizar la entrada que dice: |
|---|
| 561 | |
|---|
| 562 | # A list of your Debian GNU/Linux servers |
|---|
| 563 | define hostgroup { |
|---|
| 564 | hostgroup_name debian-servers |
|---|
| 565 | alias Debian GNU/Linux Servers |
|---|
| 566 | members localhost |
|---|
| 567 | } |
|---|
| 568 | |
|---|
| 569 | Para que "members" contiene todo los pcs. Mas o menos asi: |
|---|
| 570 | |
|---|
| 571 | members localhost,pc1,pc2,pc3,pc4,pc5,pc6,pc7,pc8,pc9 |
|---|
| 572 | pc10,pc11,pc12,pc13,pc14,pc15,pc16,pc17,pc18, etc... |
|---|
| 573 | |
|---|
| 574 | - La linea no puede tener un break. Tiene que seguir como una sola linea. |
|---|
| 575 | |
|---|
| 576 | - Despues agrega entradas por "routers" y uno por "switches" - Usa los |
|---|
| 577 | nombres "routers" y "switches" |
|---|
| 578 | |
|---|
| 579 | - Cuando terminas verifica que todo esta bien, recarga Nagios y vea si haya |
|---|
| 580 | cambos en el interfaz Web. |
|---|
| 581 | |
|---|
| 582 | |
|---|
| 583 | |
|---|
| 584 | PARTE VI (OPCIONAL) |
|---|
| 585 | Configurar acceso a "Guest" por el Interfaz Web de Nagios |
|---|
| 586 | ----------------------------------------------------------------------------- |
|---|
| 587 | |
|---|
| 588 | 1. Abre el archivo /etc/nagios3/cgi.cfg para dar acceso de solo leer (r/o) a |
|---|
| 589 | un usuario "guest" por el interfaz de Web. |
|---|
| 590 | |
|---|
| 591 | - Por defecto el usuario nagiosadmin tiene acceso leer y escribir (r/w) |
|---|
| 592 | a traves el interfaz Web de Nagios. Si quiere permitir otros usuarios |
|---|
| 593 | ver el estatus de su Red pero sin tener acceso de escribir (ejecutar |
|---|
| 594 | comandos, etc.) tenemos que hacer algunos cambios en el archivo de |
|---|
| 595 | cgi.cfg. |
|---|
| 596 | |
|---|
| 597 | - Primero hacemos el usuario "guest" con un clave en el archivo do htpasswd.user. |
|---|
| 598 | |
|---|
| 599 | # cd /etc/nagios3 |
|---|
| 600 | # htpasswd /etc/nagios3/htpasswd.users guest |
|---|
| 601 | |
|---|
| 602 | Puede usar cualquier clave, pero uno de "guest" no es tan malo... |
|---|
| 603 | |
|---|
| 604 | - Ahora abre el archivo /etc/nagios3/cgi.cfg and busca el tipo de acceso que quiere |
|---|
| 605 | dar. Vas a ver esto (hemos sacado todo los comentarios que haya en el archivo): |
|---|
| 606 | |
|---|
| 607 | authorized_for_system_information=nagiosadmin |
|---|
| 608 | authorized_for_configuration_information=nagiosadmin |
|---|
| 609 | authorized_for_system_commands=nagiosadmin |
|---|
| 610 | authorized_for_all_services=nagiosadmin |
|---|
| 611 | authorized_for_all_hosts=nagiosadmin |
|---|
| 612 | authorized_for_all_service_commands=nagiosadmin |
|---|
| 613 | authorized_for_all_host_commands=nagiosadmin |
|---|
| 614 | |
|---|
| 615 | Cambia estas entradas para permitir que el usuario "guest" tiene acceso a todo |
|---|
| 616 | la informacion que da Nagios, pero que no tiene acceso para hacer cambios. Lo |
|---|
| 617 | siguiente es tipico de acceso solo leer: |
|---|
| 618 | |
|---|
| 619 | authorized_for_system_information=nagiosadmin,guest |
|---|
| 620 | authorized_for_configuration_information=nagiosadmin,guest |
|---|
| 621 | authorized_for_system_commands=nagiosadmin |
|---|
| 622 | authorized_for_all_services=nagiosadmin,guest |
|---|
| 623 | authorized_for_all_hosts=nagiosadmin,guest |
|---|
| 624 | authorized_for_all_service_commands=nagiosadmin |
|---|
| 625 | authorized_for_all_host_commands=nagiosadmin |
|---|
| 626 | |
|---|
| 627 | - Haz los cambios, graba el archivo, salga del archivo, verifica que todo esta bien |
|---|
| 628 | y recargar Nagios. |
|---|
| 629 | |
|---|
| 630 | - Para ver si esta funcionando vay a http://localhost/nagios3 y en tu navegador tiene |
|---|
| 631 | que limpiar los "cookies" para que recibes el dialogo de login por Nagios. Haz un |
|---|
| 632 | recargar de la pagina y intenta de entrar como el usuario guest. |
|---|
| 633 | |
|---|
| 634 | |
|---|
| 635 | PARTE VII (OPCIONAL) |
|---|
| 636 | |
|---|
| 637 | Informacion Extendida de los Hosts (maquinas) - "O, hacer los graficos bonitos" |
|---|
| 638 | ------------------------------------------------------------------------------- |
|---|
| 639 | |
|---|
| 640 | 1. Actualizar extinfo_nagios2.cfg |
|---|
| 641 | |
|---|
| 642 | - Si quiere usar iconos en los opciones de graficos que tiene Nagios |
|---|
| 643 | (el Statusmap) esto es el archivo donde se define esto. Tenemos tres |
|---|
| 644 | tipos de maquinas: |
|---|
| 645 | |
|---|
| 646 | Rutadores |
|---|
| 647 | Conmutadores |
|---|
| 648 | Servidores |
|---|
| 649 | |
|---|
| 650 | Hay un repositorio bastante grande de imagenes de iconos disponible aqui: |
|---|
| 651 | |
|---|
| 652 | /usr/share/nagios/htdocs/images/logos/ |
|---|
| 653 | |
|---|
| 654 | Estan instalado por defecto cuando instalamos Nagios en Ubuntu. Hay iconos |
|---|
| 655 | muy especifico de varios modelos de equipos, pero para hacer las cosas mas |
|---|
| 656 | simples vamos a usar los siguiente iconos: |
|---|
| 657 | |
|---|
| 658 | /usr/share/nagios/htodcs/images/logos/base/debian.* |
|---|
| 659 | /usr/share/nagios/htdocs/images/logos/cook/router.* |
|---|
| 660 | /usr/share/nagios/htdocs/images/logos/cook/switch.* |
|---|
| 661 | |
|---|
| 662 | - El proximo paso es editar el archivo /etc/nagios3/conf.d/extinfo_nagios2.cfg |
|---|
| 663 | y decir a Nagios que icons usar por cada maquina. |
|---|
| 664 | |
|---|
| 665 | # vi /etc/nagios3/conf.d/extinfo_nagios2.cfg |
|---|
| 666 | |
|---|
| 667 | Aqui es una muestra de como se vea una entrad para los rutadores. Ya hay una |
|---|
| 668 | entrada por debian-servers que funciona como esta. El modelo de rutador listado |
|---|
| 669 | no esta importante. El imagen es generico. |
|---|
| 670 | |
|---|
| 671 | define hostextinfo { |
|---|
| 672 | hostgroup_name routers |
|---|
| 673 | icon_image cook/router.png |
|---|
| 674 | icon_image_alt Cisco Routers (3600) |
|---|
| 675 | vrml_image router.png |
|---|
| 676 | statusmap_image cook/router.gd2 |
|---|
| 677 | } |
|---|
| 678 | |
|---|
| 679 | Ahora agrega una entrada por tus conmutadores. Recuerda que llamaste el grupo |
|---|
| 680 | "switches". Despues, graba el archivo, verifica que todo esta bien y revise el |
|---|
| 681 | Status Map en la interfaz web para ver como esta todo. |
|---|
| 682 | |
|---|
| 683 | |
|---|
| 684 | PARTE VIII (OPCIONAL) |
|---|
| 685 | Crear Grupos de Servicio |
|---|
| 686 | ----------------------------------------------------------------------------- |
|---|
| 687 | |
|---|
| 688 | 1. Crear un grupo de servicio para ssh y http for cada PC. |
|---|
| 689 | |
|---|
| 690 | - La idea es crear dos grupos de services. Es un dispositivo y los servicios |
|---|
| 691 | asociado con el dispostivo por los dos grupos. Para hacer esto tiene que |
|---|
| 692 | crear un archivo nuevo: |
|---|
| 693 | |
|---|
| 694 | # vi /etc/nagios3/conf.d/servicegroups.cfg |
|---|
| 695 | |
|---|
| 696 | Una muestra para el grupo 1 (no es completo): |
|---|
| 697 | |
|---|
| 698 | define servicegroup { |
|---|
| 699 | servicegroup_name servidores-grupo1 |
|---|
| 700 | alias Servidores de Grupo 1 |
|---|
| 701 | members pc1,SSH,pc1,HTTP,pc2,SSH,pc2,HTTP,pc3,SSH,pc3,HTTP,pc4,SSH,pc4,HTTP,pc5,SSH, |
|---|
| 702 | pc5,HTTP,pc6,SSH,pc6,HTTP,pc7,SSH,pc7,HTTP,pc8,SSH,pc8,HTTP,pc9,SSH,pc9,HTTP |
|---|
| 703 | } |
|---|
| 704 | |
|---|
| 705 | - La linea es una sola linea. No puede tener un break. |
|---|
| 706 | |
|---|
| 707 | - SSH y FTP estan en mayuscalas porque asi es como la "service_description" esta escrito en el |
|---|
| 708 | archivo /etc/nagios3/conf.d/services_nagios2.cfg. |
|---|
| 709 | |
|---|
| 710 | - Haz una entrada por los servidores de Grupo 2. |
|---|
| 711 | |
|---|
| 712 | - Graba sus cambios y salga del archivo. Verifica que todo esta bien y recarga Nagios. |
|---|
| 713 | |
|---|
| 714 | - Vea los grupos en el interfaz web bajo los menus "Servicegroup" |
|---|
| 715 | |
|---|
| 716 | |
|---|
| 717 | OPCIONAL (No traducido) |
|---|
| 718 | ----------------------- |
|---|
| 719 | |
|---|
| 720 | 1.) Verifica que SNMP esta corriendo en el NOC |
|---|
| 721 | |
|---|
| 722 | - First you will need to add in the appropriate service check for SNMP in the file |
|---|
| 723 | /etc/nagios3/conf.d/services_nagios2.cfg. This is where Nagios is impressive. There |
|---|
| 724 | are hundreds, if not thousands, of service checks available via the various Nagios |
|---|
| 725 | sites on the web. You can see what plugins are installed by Ubuntu in the nagios3 |
|---|
| 726 | package that we've installed by looking in the following directory: |
|---|
| 727 | |
|---|
| 728 | # ls /usr/lib/nagios/plugins |
|---|
| 729 | |
|---|
| 730 | As you'll see there is already a check_snmp plugin available to us. If you are |
|---|
| 731 | interested in the options the plugin takes you can execute the plugin from the |
|---|
| 732 | command line by typing: |
|---|
| 733 | |
|---|
| 734 | # /usr/lib/nagios/plugins/check_snmp |
|---|
| 735 | |
|---|
| 736 | to see what options are available, etc. You can use the check_snmp plugin and |
|---|
| 737 | Nagios to create very complex or specific system checks. |
|---|
| 738 | |
|---|
| 739 | - Now to see all the various service/host checks that have been created using the |
|---|
| 740 | check_snmp plugin you can look in /etc/nagios-plugins/config/snmp.cfg. You will |
|---|
| 741 | see that there are a lot of preconfigured checks using snmp, including: |
|---|
| 742 | |
|---|
| 743 | snmp_load |
|---|
| 744 | snmp_cpustats |
|---|
| 745 | snmp_procname |
|---|
| 746 | snmp_disk |
|---|
| 747 | snmp_mem |
|---|
| 748 | snmp_swap |
|---|
| 749 | snmp_procs |
|---|
| 750 | snmp_users |
|---|
| 751 | snmp_mem2 |
|---|
| 752 | snmp_swap2 |
|---|
| 753 | snmp_mem3 |
|---|
| 754 | snmp_swap3 |
|---|
| 755 | snmp_disk2 |
|---|
| 756 | snmp_tcpopen |
|---|
| 757 | snmp_tcpstats |
|---|
| 758 | snmp_bgpstate |
|---|
| 759 | check_netapp_uptime |
|---|
| 760 | check_netapp_cupuload |
|---|
| 761 | check_netapp_numdisks |
|---|
| 762 | check_compaq_thermalCondition |
|---|
| 763 | |
|---|
| 764 | And, even better, you can create additional service checks quite easily. |
|---|
| 765 | For the case of verifying that snmpd (the SNMP service on Linux) is running we |
|---|
| 766 | need to ask SNMP a question. If we don't get an answer, then Nagios can assume |
|---|
| 767 | that the SNMP service is down on that host. When you use service checks such as |
|---|
| 768 | check_http, check_ssh and check_telnet this is what they are doing as well. |
|---|
| 769 | |
|---|
| 770 | - In our case, let's create a new service check and call it "check_system". This |
|---|
| 771 | service check will connect with the specified host, use the private community |
|---|
| 772 | string we have defined in class and ask a question of snmp on that ask - in this |
|---|
| 773 | case we'll ask about the System Description, or the OID "sysDescr.0" - |
|---|
| 774 | |
|---|
| 775 | - To do this start by editing the file /etc/nagios-plugins/config/snmp.cfg: |
|---|
| 776 | |
|---|
| 777 | # vi /etc/nagios-plugins/config/snmp.cfg |
|---|
| 778 | |
|---|
| 779 | At the top (or the bottom, your choice) add the following entry to the file: |
|---|
| 780 | |
|---|
| 781 | # 'check_system' command definition |
|---|
| 782 | define command{ |
|---|
| 783 | command_name check_system |
|---|
| 784 | command_line /usr/lib/nagios/plugins/check_snmp -H '$HOSTADDRESS$' -C |
|---|
| 785 | '$ARG1$' -o sysDescr.0 |
|---|
| 786 | } |
|---|
| 787 | |
|---|
| 788 | You may wish to copy and past this vs. trying to type this out. |
|---|
| 789 | |
|---|
| 790 | Note that "command_line" is a single line. If you copy and paste in vi the line |
|---|
| 791 | may not wrap properly and you may have to manually add the part: |
|---|
| 792 | |
|---|
| 793 | '$ARG1$' -o sysName.0 |
|---|
| 794 | |
|---|
| 795 | to the end of the line. |
|---|
| 796 | |
|---|
| 797 | - Now you need to edit the file /etc/nagios3/conf.d/services_nagios2.cfg and add |
|---|
| 798 | in this service check. We'll run this check against all our servers in the |
|---|
| 799 | classroom, or the hostgroup "debian-servers" |
|---|
| 800 | |
|---|
| 801 | - Edit the file /etc/nagios3/conf.d/services_nagios2.cfg |
|---|
| 802 | |
|---|
| 803 | # vi /etc/nagios3/conf.d/services_nagios2.cfg |
|---|
| 804 | |
|---|
| 805 | At the bottom of the file add the following definition: |
|---|
| 806 | |
|---|
| 807 | # check that snmp is up on all servers |
|---|
| 808 | define service { |
|---|
| 809 | hostgroup_name snmp-servers |
|---|
| 810 | service_description SNMP |
|---|
| 811 | check_command check_system!public |
|---|
| 812 | use generic-service |
|---|
| 813 | notification_interval 0 ; set > 0 if you want to be renotified |
|---|
| 814 | } |
|---|
| 815 | |
|---|
| 816 | The "xxxxxx" is the community string previously (or to be) defined in class. |
|---|
| 817 | In our case this is the class password for our PCs. |
|---|
| 818 | |
|---|
| 819 | For our routers and switches the community string is "unan-ro" - Create another |
|---|
| 820 | service entry like this: |
|---|
| 821 | |
|---|
| 822 | # check that snmp is up on all servers |
|---|
| 823 | define service { |
|---|
| 824 | hostgroup_name snmp-routers-switches |
|---|
| 825 | service_description SNMP |
|---|
| 826 | check_command check_system!unan-ro |
|---|
| 827 | use generic-service |
|---|
| 828 | notification_interval 0 ; set > 0 if you want to be renotified |
|---|
| 829 | } |
|---|
| 830 | |
|---|
| 831 | Note that we have included our private community string here vs. hard-coding |
|---|
| 832 | it in the snmp.cfg file earlier. |
|---|
| 833 | |
|---|
| 834 | - Now we must create the "snmp-servers" group in our hostgroups_nagios2.cfg file. |
|---|
| 835 | Edit the file /etc/nagios3/conf.d/hostgroups_nagios2.cfg and go to the end of the |
|---|
| 836 | file. Add in the following hostgroup definition: |
|---|
| 837 | |
|---|
| 838 | # A list of snmp-enabled devices on which we wish to run the snmp service check |
|---|
| 839 | define hostgroup { |
|---|
| 840 | hostgroup_name snmp-servers |
|---|
| 841 | alias snmp servers |
|---|
| 842 | members noc,pc1,pc2,pc3,pc4,pc5, etc... |
|---|
| 843 | } |
|---|
| 844 | |
|---|
| 845 | And for our routers and switches: |
|---|
| 846 | |
|---|
| 847 | define hostgroup { |
|---|
| 848 | hostgroup_name snmp-routers-switches |
|---|
| 849 | alias snmp on our network infrastructure |
|---|
| 850 | members gw-rtr,grupo1-rtr,grupo2-rtr,grupo1-sw,grupo2-sw |
|---|
| 851 | } |
|---|
| 852 | |
|---|
| 853 | - Now verify that your changes are correct and restart Nagios. |
|---|
| 854 | |
|---|
| 855 | - If you click on the Service Detail menu choice in web interface you should see |
|---|
| 856 | the SNMP check appear. |
|---|
| 857 | |
|---|
| 858 | - After we do the SNMP presentation and exercises in class, then you could come |
|---|
| 859 | back to this exercise and add in all the classroom PCs to the members list in the |
|---|
| 860 | hostgroups_nagios2.cfg file, snmp-servers hostgroup definition. Remember to list |
|---|
| 861 | your PC as "localhost". |
|---|
| 862 | |
|---|
| 863 | |
|---|
| 864 | Ultima actualizacion 31 de Agosto 2011 por HA |
|---|