简体   繁体   English

PacketBeat无法连接到ElasticSearch泊坞窗

[英]Packetbeat not able to connect to elasticsearch docker

I am trying to dockerize all the elastic services that I need to use. 我正在尝试将我需要使用的所有弹性服务进行码头化。 The docker-compose file looks like below docker-compose文件如下所示

version: '3'
services:
  redis:
    build: ./docker/redis

  postgresql:
    build: ./docker/postgresql
    ports:
      - "5433:5432"
    env_file:
      - .env

  graphql:
    build: .
    command: npm run start
    volumes:
      - ./logs/:/usr/app/logs/
    ports:
      - "3000:3000"
    env_file:
      - .env
    depends_on:
      - "redis"
      - "postgresql"
    links:
      - "redis"
      - "postgresql"

  elasticsearch:
    build: ./docker/elasticsearch
    container_name: elasticsearch
    networks:
      - elastic
    ports:
      - "9200:9200"
    depends_on:
      - "graphql"
    links:
      - "kibana"

  kibana:
    build: ./docker/kibana
    container_name: kibana
    ports:
      - "5601:5601"
    depends_on:
      - "graphql"
    networks:
      - elastic
    environment:
      - ELASTICSEARCH_URL=http://elasticsearch:9200

  metricbeat:
    build: ./docker/metricbeat
    depends_on:
      - "graphql"
      - "elasticsearch"
      - "kibana"
    volumes:
      - /proc:/hostfs/proc:ro
      - /sys/fs/cgroup:/hostfs/sys/fs/cgroup:ro
      - /:/hostfs:ro
    networks:
      - elastic
    environment:
      - ELASTICSEARCH_URL=http://elasticsearch:9200
    command:
      - "-system.hostfs=/hostfs"

  packetbeat:
    build: ./docker/packetbeat
    depends_on:
      - "graphql"
      - "elasticsearch"
      - "kibana"
    cap_add:
      - NET_ADMIN
    networks:
      - elastic
    environment:
      - ELASTICSEARCH_URL=http://127.0.0.1:9200

  logstash:
    build: ./docker/logstash
    ports:
      - "9600:9600"
    volumes:
      - ./logs:/usr/logs
    depends_on:
      - "graphql"
      - "elasticsearch"
      - "kibana"
    networks:
      - elastic
    environment:
      - ELASTICSEARCH_URL=http://elasticsearch:9200

networks:
  elastic:
    driver: bridge

Everything works very well right now but the problem is that the packetbeat is only capturing network inside its own docker container. 现在一切都运行良好,但问题是packetbeat只在自己的docker容器内捕获网络。 In the elastic documentation reference - https://www.elastic.co/guide/en/beats/packetbeat/master/running-on-docker.html It says that I need to enable 'host' network in order to capture all the originating and arriving networks to the physical host. 在弹性文档参考中-https : //www.elastic.co/guide/zh-CN/beats/packetbeat/master/running-on-docker.html它说我需要启用“主机”网络才能捕获所有物理主机的始发和到达网络。 However, since I have configured the networks to be -elastic I am unable to add additional host network interface to packetbeat. 但是,由于我已将网络配置为-elastic无法将其他主机网络接口添加到packetbeat。 If I erase -elastic network and add -host network, I am not able to connect to elasticsearch because DNS elasticsearch no longer exists in a different network. 如果我删除-elastic网络并添加-host网络,则无法连接到elasticsearch,因为DNS elasticsearch在另一个网络中不再存在。 How can I overcome this problem? 我该如何克服这个问题?

This is a pretty common problem where the nice isolation of docker gets in your way. 这是一个很常见的问题,Docker的良好隔离会影响您的工作。 The same happens for example when using the Prometheus node_exporter that collects metrics of the host machine, which is also pretty useless when run in a container without access to the host network. 例如,在使用Prometheus node_exporter来收集主机度量的情况下,也会发生同样的情况,当在没有访问主机网络的容器中运行时,这也几乎没有用。

As you already mentioned, it is not possible to use both network_mode: host and the docker networks togehter. 正如您已经提到的,不可能同时使用network_mode: host和docker networks So for your use case, you could have the packetbeat container running with host networking and not attach it to the docker networks. 因此,对于您的用例,您可以使packetbeat容器与主机网络一起运行,而不将其附加到docker网络。 Because of that, you are no longer able to connect it to the elasticsearch instance via http://elasticsearch:9200 , so you need to replace this config value to http://your-host-ip:9200 which you already configured in your elasticsearch service as mapped port. 因此,您不再能够通过http://elasticsearch:9200将其连接到elasticsearch实例,因此您需要将此配置值替换为您已经在其中配置的http://your-host-ip:9200 。您的Elasticsearch服务作为映射端口。 Possibly http://127.0.0.1 could also work when run with network_mode: host as this should be the localhost in your host network - thus the host where the port of elasticsearch is mapped to. 当使用network_mode: host运行时,可能http://127.0.0.1也可以使用network_mode: host因为它应该是您的主机网络中的localhost主机-因此,elasticsearch端口映射到的主机。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM