LINUX

Cómo agregar host y administrar servicios en Icinga2

En mi artículo anterior, expliqué cómo instalar y configurar un Icinga2 con la interfaz Icinga Web2. Ahora es el momento de presentar algunos hosts a nuestro sistema de monitoreo. A diferencia de Nagios, podemos agregar los hosts automáticamente a los sistemas Icinga2. La configuración es bastante simple y fácil en comparación con otros sistemas de monitoreo.

Como se indicó anteriormente, la comunicación entre el servidor de monitoreo y los nodos cliente es más segura en comparación con otras versiones. Todas las comunicaciones están protegidas por conexiones TLS con certificados que configuran los servidores Icinga2 en la inicialización.

Comencemos con los procedimientos sobre cómo agregar hosts a nuestro sistema de monitoreo. Puedes echar un vistazo al flujo de trabajo.

pasos

Configuración del nodo maestro Icinga2

Ya hemos configurado nuestro nodo maestro Icinga2, ahora necesitamos realizar la siguiente inicialización para permitir que nuestros nodos anfitriones se conecten a ellos de forma segura. Necesitamos ejecutar este comando «icinga2 node wizard» para ejecutar el asistente de configuración.

root@ubuntu:~# icinga2 node wizard
Welcome to the Icinga 2 Setup Wizard!

We'll guide you through all required configuration details.

El asistente de configuración le preguntará si se trata de una configuración maestra o satélite. Dado que ejecutamos esto en el servidor maestro, podemos escribir ‘n’. Al escribir ‘n’, instala la configuración maestra y comienza a generar los certificados para la comunicación TLS segura.

Please specify if this is a satellite setup ('n' installs a master setup) [Y/n]: n
Starting the Master setup routine...
Please specifiy the common name (CN) [ubuntu.icinga-master.com]:
Checking for existing certificates for common name 'ubuntu.icinga-master.com'...
Certificates not yet generated. Running 'api setup' now.
information/cli: Generating new CA.
information/base: Writing private key to '/var/lib/icinga2/ca/ca.key'.
information/base: Writing X509 certificate to '/var/lib/icinga2/ca/ca.crt'.
information/cli: Generating new CSR in '/etc/icinga2/pki/ubuntu.icinga-master.com.csr'.
information/base: Writing private key to '/etc/icinga2/pki/ubuntu.icinga-master.com.key'.
information/base: Writing certificate signing request to '/etc/icinga2/pki/ubuntu.icinga-master.com.csr'.
information/cli: Signing CSR with CA and writing certificate to '/etc/icinga2/pki/ubuntu.icinga-master.com.crt'.
information/cli: Copying CA certificate to '/etc/icinga2/pki/ca.crt'.
Generating master configuration for Icinga 2.
information/cli: Adding new ApiUser 'root' in '/etc/icinga2/conf.d/api-users.conf'.
information/cli: Enabling the 'api' feature.
Enabling feature api. Make sure to restart Icinga 2 for these changes to take effect.
information/cli: Dumping config items to file '/etc/icinga2/zones.conf'.
information/cli: Created backup file '/etc/icinga2/zones.conf.orig'.

No necesitamos cambiar los puertos, así que déjelo como está.

Please specify the API bind host/port (optional):
Bind Host []:
Bind Port []:
information/cli: Created backup file '/etc/icinga2/features-available/api.conf.orig'.
information/cli: Updating constants.conf.
information/cli: Created backup file '/etc/icinga2/constants.conf.orig'.
information/cli: Updating constants file '/etc/icinga2/constants.conf'.
information/cli: Updating constants file '/etc/icinga2/constants.conf'.
information/cli: Updating constants file '/etc/icinga2/constants.conf'.
Done.

Now restart your Icinga 2 daemon to finish the installation!

Después de ejecutar este asistente de configuración, debe reiniciar el servicio Icinga2.

root@ubuntu:~# systemctl restart icinga2

Instalación y configuración de Icinga2-Client

Necesitamos instalar Icinga2 en el nodo host como paso inicial. Para eso, necesitamos agregar el repositorio Icinga2 al nodo host y actualizar los paquetes del repositorio APT.

root@ubuntu:~# apt install software-properties-common
root@ubuntu:~# add-apt-repository ppa:formorer/icinga
This PPA provides Icinga 1, Icinga 2 and Icinga web Packages for Ubuntu. They are directly derived from the Debian Packages that I maintain within Debian.
More info: https://launchpad.net/~formorer/+archive/ubuntu/icinga
Press [ENTER] to continue or ctrl-c to cancel adding it

gpg: keyring `/tmp/tmpcrlq876s/secring.gpg' created
gpg: keyring `/tmp/tmpcrlq876s/pubring.gpg' created
gpg: requesting key 36862847 from hkp server keyserver.ubuntu.com
gpg: /tmp/tmpcrlq876s/trustdb.gpg: trustdb created
gpg: key 36862847: public key "Launchpad PPA for Alexander Wirt" imported
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)
OK
root@ubuntu:~#apt-get update
root@ubuntu:~# apt-get install icinga2
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
icinga2-bin icinga2-common icinga2-doc libboost-program-options1.58.0 libboost-regex1.58.0 libboost-system1.58.0 libboost-thread1.58.0
libicinga2 libyajl2 monitoring-plugins-basic monitoring-plugins-common
Suggested packages:
icinga2-studio vim-icinga2 icinga | icinga | nagios3
The following NEW packages will be installed:

Creating config file /etc/nagios-plugins/config/dhcp.cfg with new version

Creating config file /etc/nagios-plugins/config/disk.cfg with new version

Creating config file /etc/nagios-plugins/config/dummy.cfg with new version

Creating config file /etc/nagios-plugins/config/ftp.cfg with new version

Creating config file /etc/nagios-plugins/config/http.cfg with new version

Creating config file /etc/nagios-plugins/config/load.cfg with new version

Creating config file /etc/nagios-plugins/config/mail.cfg with new version

Creating config file /etc/nagios-plugins/config/news.cfg with new version

Creating config file /etc/nagios-plugins/config/ntp.cfg with new version

Creating config file /etc/nagios-plugins/config/ping.cfg with new version

Creating config file /etc/nagios-plugins/config/procs.cfg with new version

Creating config file /etc/nagios-plugins/config/real.cfg with new version

Creating config file /etc/nagios-plugins/config/ssh.cfg with new version

Creating config file /etc/nagios-plugins/config/tcp_udp.cfg with new version

Creating config file /etc/nagios-plugins/config/telnet.cfg with new version

Creating config file /etc/nagios-plugins/config/users.cfg with new version
Setcap for check_icmp and check_dhcp worked!
Processing triggers for libc-bin (2.23-0ubuntu3) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for systemd (229-4ubuntu4) ...

Ahora tenemos que ejecutar el asistente de configuración en nuestro nodo host e instalar la configuración del satélite.

root@ubuntu:~# icinga2 node wizard
Welcome to the Icinga 2 Setup Wizard!

We'll guide you through all required configuration details.

Dado que esta es nuestra configuración de satélite, debemos escribir ‘Y’ para continuar con nuestra configuración de satélite.

Please specify if this is a satellite setup ('n' installs a master setup) [Y/n]: yes

Esto continuará con la configuración del nodo satélite e instalará los certificados necesarios para la comunicación TLS.

Starting the Node setup routine...
Please specifiy the common name (CN) [host1.icinga2server.com]:
Please specify the master endpoint(s) this node should connect to:
Master Common Name (CN from your master setup): ubuntu.icinga-master.com
Do you want to establish a connection to the master from this node? [Y/n]: y
Please fill out the master connection information:
Master endpoint host (Your master's IP address or FQDN): 139.162.55.62
Master endpoint port [5665]:
Add more master endpoints? [y/N]:
Please specify the master connection for CSR auto-signing (defaults to master endpoint host):
Host [139.162.55.62]:
Port [5665]:
information/base: Writing private key to '/etc/icinga2/pki/host1.icinga2server.com.key'.
information/base: Writing X509 certificate to '/etc/icinga2/pki/host1.icinga2server.com.crt'.
information/cli: Fetching public certificate from master (139.162.55.62, 5665):

Certificate information:

Subject: CN = ubuntu.icinga-master.com
Issuer: CN = Icinga CA
Valid From: Jun 26 06:49:50 2016 GMT
Valid Until: Jun 23 06:49:50 2031 GMT
Fingerprint: 13 8A 73 C5 36 E7 1D DA FE 9D E1 E6 1E 32 ED E2 3C 6B 48 E8

Is this information correct? [y/N]: yes

Necesitamos proporcionar la información del host y la información del servidor maestro para completar la configuración del nodo. Después de proporcionar los detalles, ingresará a la firma automática de CSR. Después de esto, Icinga 2 guarda alguna configuración en el nodo host y establece una conexión segura con él.

Después de guardar estos certificados, el maestro debe validarlos para demostrar que realmente está al mando de ambos servidores y aprueba esta comunicación segura. Para eso, ejecuto este «ticket icinga2 pki –cn ‘host1.icinga2server.com» en mi servidor maestro y proporcioné el código generado en la configuración del nodo para continuar.

Please specify the request ticket generated on your Icinga 2 master.
(Hint: # icinga2 pki ticket --cn 'host1.icinga2server.com'): 836289c1bcd427879b06703dfb35aa122bf89dc2
information/cli: Requesting certificate with ticket '836289c1bcd427879b06703dfb35aa122bf89dc2'.

warning/cli: Backup file '/etc/icinga2/pki/host1.icinga2server.com.crt.orig' already exists. Skipping backup.
information/cli: Writing signed certificate to file '/etc/icinga2/pki/host1.icinga2server.com.crt'.
information/cli: Writing CA certificate to file '/etc/icinga2/pki/ca.crt'.

Después de firmar los certificados, solicita el puerto de enlace / API. Podemos omitir estas secciones como antes y continuar con el restablecimiento de las configuraciones.

Please specify the API bind host/port (optional):
Bind Host []:
Bind Port []:
Accept config from master? [y/N]: y
Accept commands from master? [y/N]: y
information/cli: Disabling the Notification feature.
Disabling feature notification. Make sure to restart Icinga 2 for these changes to take effect.
information/cli: Enabling the Api listener feature.
Enabling feature api. Make sure to restart Icinga 2 for these changes to take effect.

information/cli: Created backup file '/etc/icinga2/features-available/api.conf.orig'.
information/cli: Generating local zones.conf.
information/cli: Dumping config items to file '/etc/icinga2/zones.conf'.
information/cli: Created backup file '/etc/icinga2/zones.conf.orig'.
information/cli: Updating constants.conf.
information/cli: Created backup file '/etc/icinga2/constants.conf.orig'.
information/cli: Updating constants file '/etc/icinga2/constants.conf'.
information/cli: Updating constants file '/etc/icinga2/constants.conf'.
Done.

Now restart your Icinga 2 daemon to finish the installation!

Una vez que se completa la configuración del nodo, debemos reiniciar el demonio Icinga2 en el lado del host.

Actualización de las configuraciones de cliente a maestro

Ahora podemos volver a nuestro servidor maestro y confirmar con la adición de host. Podemos ejecutar este comando para enumerar los nodos de host y los servicios agregados al servidor.

root@ubuntu:~# icinga2 node list
Node 'host1.icinga2server.com' (last seen: Sun Jun 26 07:03:40 2016)
* Host 'host1.icinga2server.com'
* Service 'apt'
* Service 'disk'
* Service 'disk /'
* Service 'http'
* Service 'icinga'
* Service 'load'
* Service 'ping4'
* Service 'ping6'
* Service 'procs'
* Service 'ssh'
* Service 'swap'
* Service 'users'
root@ubuntu:~#

Ahora necesitamos actualizar la configuración maestra de Icinga2 para actualizar estas modificaciones y agregar los nodos de host a las comprobaciones de monitoreo.

root@ubuntu:~#icinga2 node update-config
root@ubuntu:~# systemctl restart icinga2

Finalmente podemos reiniciar los servicios para guardar estos cambios y ver nuestro nodo host en la interfaz de Icinga Web2. Podemos iniciar sesión en la interfaz web de Icinga en http://139.162.55.62/icingaweb2/ con nuestras credenciales de administrador y confirmar el estado del host.

Hospedadores
httpservicio

Gestión de servicios en Icinga2

Como puede ver en mi captura de pantalla anterior, el servicio http se muestra crítico en mi servidor cliente. No he instalado Apache en mi servidor cliente, por lo que en realidad no necesito que el servicio HTTP sea monitoreado en nuestro servidor cliente. Veamos cómo voy a eliminar ese servicio de los servicios de monitoreo.

Cuando se agrega un servidor cliente al maestro, crea una carpeta para ese servidor cliente dentro de la carpeta repository.d en el servidor maestro en la ruta de configuración de Icinga2 con su nombre de host como se muestra a continuación:

root@ubuntu:/etc/icinga2/repository.d/hosts# ls -l
total 8
drwxr-x--- 2 nagios nagios 4096 Jun 26 07:04 host1.icinga2server.com
-rw-r--r-- 1 root root 100 Jun 26 07:04 host1.icinga2server.com.conf
root@ubuntu:/etc/icinga2/repository.d/hosts#

Necesitamos entrar en la carpeta del cliente «host1.icinga2server.com» y ver los archivos de servicio que se agregan a los hosts en la inicialización.

root@ubuntu:/etc/icinga2/repository.d/hosts/host1.icinga2server.com# ls -l
total 48
-rw-r--r-- 1 root root 152 Jun 26 07:04 apt.conf
-rw-r--r-- 1 root root 155 Jun 26 07:04 disk %2F.conf
-rw-r--r-- 1 root root 153 Jun 26 07:04 disk.conf
-rw-r--r-- 1 root root 153 Jun 26 07:04 http.conf
-rw-r--r-- 1 root root 155 Jun 26 07:04 icinga.conf
-rw-r--r-- 1 root root 153 Jun 26 07:04 load.conf
-rw-r--r-- 1 root root 154 Jun 26 07:04 ping4.conf
-rw-r--r-- 1 root root 154 Jun 26 07:04 ping6.conf
-rw-r--r-- 1 root root 154 Jun 26 07:04 procs.conf
-rw-r--r-- 1 root root 152 Jun 26 07:04 ssh.conf
-rw-r--r-- 1 root root 153 Jun 26 07:04 swap.conf
-rw-r--r-- 1 root root 154 Jun 26 07:04 users.conf

Podemos ver todos los archivos de configuración del servicio para ese host en particular que residen dentro de esta carpeta. Ahora debemos eliminar el archivo de verificación de servicio que debemos deshabilitar del monitoreo.

Por ejemplo: en nuestro caso, necesitamos deshabilitar el servicio http, por lo tanto, estoy moviendo http.conf de esta carpeta. Puede eliminarlo o simplemente mover estos archivos.

root@ubuntu:/etc/icinga2/repository.d/hosts/host1.icinga2server.com# mv http.conf http.conf-disabled

Después de realizar cualquier cambio, debemos volver a cargar el servicio Icinga2 en el servidor.

root@ubuntu:/etc/icinga2# service icinga2 reload

Podemos confirmarlo desde la interfaz web, si se eliminan esos servicios.

disabledservicefinal

Pero esta supervisión del servicio se puede volver a habilitar al actualizar la configuración del nodo en el servidor maestro. si ese servicio todavía aparece en la lista para ese cliente de la siguiente manera:

root@ubuntu:~# icinga2 node list
Node 'host1.icinga2server.com' (last seen: Wed Jun 29 12:31:20 2016)
* Host 'host1.icinga2server.com'
* Service 'Icinga Web 2'
* Service 'apt'
* Service 'disk'
* Service 'disk /'
* Service 'http'
* Service 'icinga'
* Service 'load'
* Service 'ping4'
* Service 'ping6'
* Service 'procs'
* Service 'ssh'
* Service 'swap'
* Service 'users'

Por lo tanto, debemos eliminar esto de la lista de nodos. Veamos cómo podemos hacer eso.

1. Inicie sesión en el servidor del Cliente y muévase a la carpeta llamada «/etc/icinga2/conf.d», allí podemos ver el archivo hosts.conf.

root@host1:/etc/icinga2/conf.d# ls -l
total 48
-rw-r--r-- 1 root root 35 May 19 12:56 app.conf
-rw-r--r-- 1 root root 114 May 17 11:03 apt.conf
-rw-r--r-- 1 root root 1300 May 19 12:56 commands.conf
-rw-r--r-- 1 root root 542 May 19 12:56 downtimes.conf
-rw-r--r-- 1 root root 638 May 19 12:56 groups.conf
-rw-r--r-- 1 root root 1501 May 19 12:56 hosts.conf
-rw-r--r-- 1 root root 674 May 19 12:56 notifications.conf
-rw-r--r-- 1 root root 801 May 19 12:56 satellite.conf
-rw-r--r-- 1 root root 2131 Jun 29 06:37 services.conf
-rw-r--r-- 1 root root 1654 May 19 12:56 templates.conf
-rw-r--r-- 1 root root 906 May 19 12:56 timeperiods.conf
-rw-r--r-- 1 root root 308 May 19 12:56 users.conf

Ahora necesitamos editar el archivo hosts.conf y comentar la parte de verificación del servicio http desde allí.

desactivar

Reinicie el servicio Icinga2 en el servidor del cliente para actualizar estos cambios.

2. Vuelva a su servidor maestro, vuelva a cargar el servicio Icinga2 y actualice la configuración del nodo.

root @ ubuntu: / etc / icinga2 # service icinga2 reload

root@ubuntu:/etc/icinga2# icinga2 node update-config

eliminando httpd

Ahora podemos confirmar la eliminación del servicio http de la configuración maestra.

root@ubuntu:~# icinga2 node list
Node 'host1.icinga2server.com' (last seen: Wed Jun 29 12:46:51 2016)
* Host 'host1.icinga2server.com'
* Service 'Icinga Web 2'
* Service 'apt'
* Service 'disk'
* Service 'disk /'
* Service 'icinga'
* Service 'load'
* Service 'ping4'
* Service 'ping6'
* Service 'procs'
* Service 'ssh'
* Service 'swap'
* Service 'users'

Asimismo, podemos agregar o eliminar cualquier servicio en Icinga2. Creo que este artículo es informativo y útil. Recomendaría sus valiosas sugerencias y comentarios al respecto. Feliz lectura 🙂

Publicaciones relacionadas

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

Botón volver arriba
Cerrar