PacketBeat无法连接到ElasticSearch泊坞窗

时间:2018-08-16 07:29:40

标签: docker elasticsearch packetbeat

我正在尝试将我需要使用的所有弹性服务进行码头化。 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

现在一切正常,但是问题是Packetbeat只在自己的Docker容器内捕获网络。在弹性文档参考中-https://www.elastic.co/guide/en/beats/packetbeat/master/running-on-docker.html 它说,我需要启用“主机”网络,以便将所有始发和到达的网络捕获到物理主机。但是,由于我已将网络配置为-elastic,因此无法将其他主机网络接口添加到packetbeat。如果我删除-elastic网络并添加-host网络,那么我将无法连接到elasticsearch,因为DNS elasticsearch在另一个网络中不再存在。我该如何克服这个问题?

1 个答案:

答案 0 :(得分:1)

这是一个非常普遍的问题,Docker的良好隔离会影响您的工作。例如,当使用Prometheus node_exporter来收集主机度量时,会发生同样的情况,当在没有访问主机网络的容器中运行时,这也非常没用。

正如您已经提到的,不可能同时使用network_mode: host和docker networks。因此,对于您的用例,您可以使packetbeat容器与主机网络一起运行,而不将其附加到docker网络。因此,您不再能够通过http://elasticsearch:9200将其连接到elasticsearch实例,因此需要将此配置值替换为http://your-host-ip:9200,该值已经在您的Elasticsearch服务中配置为映射端口。当http://127.0.0.1network_mode: host一起运行时,可能也可以工作,因为它应该是您的主机网络中的localhost,也就是弹性搜索端口所映射到的主机。