Diferències
Ací es mostren les diferències entre la revisió seleccionada i la versió actual de la pàgina.
Següent revisió | Revisió prèvia | ||
info:cursos:pue:devops:sesion13 [29/03/2019 08:05] – creat mate | info:cursos:pue:devops:sesion13 [26/11/2021 04:25] (actual) – [otros] mate | ||
---|---|---|---|
Línia 1: | Línia 1: | ||
- | = sesión 13 | + | = sesión 13 ELK |
== Container Orchestration Rosetta Stone | == Container Orchestration Rosetta Stone | ||
+ | ^ ^ unidad mínima ^ Gestor de disponibilidad\\ controllers ^ expose\\ services ^ webservices\\ exterior ^ | ||
+ | | Swarm | contenedor | ||
+ | | K8S | pod | < | ||
+ | * controllers | ||
+ | * Deployments = POD + ReplicaSet | ||
+ | * Jobs = 1 sola ejecución | ||
+ | * CronJob | ||
+ | * services | ||
+ | * hostport : exponer en el host a través de un puerto | ||
+ | * clusterIP : uso interno del cluster | ||
+ | * loadbalancer : | ||
+ | * externalname : definimos el mismo nombre en el servicio en diferentes namespaces, ex: oracle (dev/ | ||
+ | * webservices (acceso exterior): | ||
+ | * Loadbalancer | ||
+ | * ingress : trabaja en kube-system, | ||
+ | * nginx+ssl, traefik | ||
+ | |||
+ | == lab | ||
+ | levantar docker swarm cluster, desplegar Portainer y ELK | ||
+ | <code yaml; portainer.yaml> | ||
+ | version: ' | ||
+ | |||
+ | services: | ||
+ | portainer: | ||
+ | image: portainer/ | ||
+ | command: '-H " | ||
+ | ports: | ||
+ | - ${PUBLIC_PORT}: | ||
+ | networks: | ||
+ | - proxy | ||
+ | - portainer_agent | ||
+ | volumes: | ||
+ | - / | ||
+ | - ${REMOTE_MOUNT}/ | ||
+ | deploy: | ||
+ | mode: replicated | ||
+ | replicas: 1 | ||
+ | labels: | ||
+ | traefik.port: | ||
+ | traefik.frontend.rule: | ||
+ | traefik.docker.network: | ||
+ | placement: | ||
+ | constraints: | ||
+ | | ||
+ | agent: | ||
+ | image: portainer/ | ||
+ | environment: | ||
+ | AGENT_CLUSTER_ADDR: | ||
+ | volumes: | ||
+ | - / | ||
+ | ports: | ||
+ | - target: 9001 | ||
+ | published: 9001 | ||
+ | protocol: tcp | ||
+ | mode: host | ||
+ | networks: | ||
+ | - portainer_agent | ||
+ | deploy: | ||
+ | mode: global | ||
+ | placement: | ||
+ | constraints: | ||
+ | |||
+ | |||
+ | |||
+ | networks: | ||
+ | portainer_agent: | ||
+ | external: true | ||
+ | proxy: | ||
+ | external: true | ||
+ | </ | ||
+ | <code yaml; elk.yaml> | ||
+ | # | ||
+ | # Based on ....... | ||
+ | # | ||
+ | # Sun Mar 4 13:15:47 CET 2018 | ||
+ | # | ||
+ | # cluster.name: | ||
+ | # bootstrap.memory_lock: | ||
+ | version: ' | ||
+ | |||
+ | services: | ||
+ | elasticsearch: | ||
+ | image: docker.elastic.co/ | ||
+ | environment: | ||
+ | ES_JAVA_OPTS: | ||
+ | LOGSPOUT: ' | ||
+ | networks: | ||
+ | - elasticsearch | ||
+ | volumes: | ||
+ | - / | ||
+ | deploy: | ||
+ | replicas: 1 | ||
+ | |||
+ | logstash: | ||
+ | image: docker.elastic.co/ | ||
+ | volumes: | ||
+ | - / | ||
+ | depends_on: | ||
+ | - elasticsearch | ||
+ | networks: | ||
+ | - elasticsearch | ||
+ | - logstash | ||
+ | environment: | ||
+ | LOGSPOUT: ' | ||
+ | deploy: | ||
+ | replicas: 1 | ||
+ | |||
+ | logspout: | ||
+ | image: bekt/ | ||
+ | environment: | ||
+ | ROUTE_URIS: ' | ||
+ | DOCKER_LABELS: | ||
+ | volumes: | ||
+ | - / | ||
+ | depends_on: | ||
+ | - logstash | ||
+ | networks: | ||
+ | - logstash | ||
+ | # environment: | ||
+ | # LOGSPOUT: ' | ||
+ | # OJO, se ignora a si mismo y no se vuelcan logs | ||
+ | deploy: | ||
+ | mode: global | ||
+ | restart_policy: | ||
+ | condition: on-failure | ||
+ | delay: 30s | ||
+ | |||
+ | kibana: | ||
+ | image: docker.elastic.co/ | ||
+ | ports: | ||
+ | - 5601:5601 | ||
+ | depends_on: | ||
+ | - elasticsearch | ||
+ | networks: | ||
+ | - elasticsearch | ||
+ | - proxy | ||
+ | environment: | ||
+ | ELASTICSEARCH_URL: | ||
+ | LOGSPOUT: ' | ||
+ | deploy: | ||
+ | replicas: 1 | ||
+ | labels: | ||
+ | traefik.port: | ||
+ | traefik.frontend.rule: | ||
+ | traefik.docker.network: | ||
+ | |||
+ | networks: | ||
+ | default: | ||
+ | driver: ' | ||
+ | logstash: | ||
+ | driver: ' | ||
+ | elasticsearch: | ||
+ | driver: ' | ||
+ | proxy: | ||
+ | external: true | ||
+ | </ | ||
+ | <code properties; var> | ||
+ | REMOTE_BIND=/ | ||
+ | STACK_NAME=Cluster3 | ||
+ | LOGS_URL=logs.local | ||
+ | </ | ||
+ | <code config; logstatsh.conf> | ||
+ | input { | ||
+ | udp { | ||
+ | port => 5000 | ||
+ | codec => json | ||
+ | } | ||
+ | } | ||
+ | |||
+ | filter { | ||
+ | if [docker][image] =~ /logstash/ { | ||
+ | drop { } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | output { | ||
+ | elasticsearch { hosts => [" | ||
+ | } | ||
+ | </ | ||
+ | [[https:// | ||
+ | |||
+ | procesar en ELK | ||
+ | |||
+ | logspout -> logstash -> kibana | ||
+ | |||
+ | - debemos habilitar las DOCKER_LABELS como variable de entorno en el deploy de la imagen (cualquier valor lo activa)< | ||
+ | version: ' | ||
+ | |||
+ | services: | ||
+ | db: | ||
+ | | ||
+ | | ||
+ | - db_data:/ | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | | ||
+ | | ||
+ | - 80 | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | volumes: | ||
+ | db_data: | ||
+ | </ | ||
+ | - añadimos una etiqueta en nuestro contenedor para poder discriminar su origen (y formato) -> NO | ||
+ | - modificamos el logstash.conf para añadir un **if** por etiqueta y decirle que formato tiene< | ||
+ | if [docker][image] =~ /^cadena/ { | ||
+ | grok { | ||
+ | match => {" | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | |||
+ | * modificamos la configuración de **logstash.conf** para que tenga un nuevo INPUT (de syslog):< | ||
+ | input { | ||
+ | syslog { | ||
+ | codec => cef | ||
+ | port => 12345 | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | <code / | ||
+ | *.* @@< | ||
+ | </ | ||
+ | * facility.priority | ||
+ | * @ -> UDP (pérdida de paquetes permitida) | ||
+ | * @@ -> TCP (seguridad de entrega) | ||
+ | * el **-** indica **buffered**, | ||
+ | * para volcar los logs a una dirección IP/Puerto hay que hacer lo anterior y habilitar el **module(load=" | ||
+ | * para ver que está escuchando: '' | ||
+ | |||
+ | == otros | ||
+ | * [[http:// | ||
+ | * grok debugger | ||
+ | * vim | ||
+ | * borrar lineas de comentarios y vacías: | ||
+ | * junto: '' | ||
+ | * comentarios: | ||
+ | * líneas vacías: '' |