【问题标题】:Packetbeat not able to connect to elasticsearch dockerPacketbeat 无法连接到 elasticsearch docker
【发布时间】:2018-08-27 17:51:55
【问题描述】:

我正在尝试对我需要使用的所有弹性服务进行 dockerize。 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 不再存在于不同的网络中。我该如何克服这个问题?

【问题讨论】:

    标签: docker elasticsearch packetbeat


    【解决方案1】:

    这是一个很常见的问题,Docker 的良好隔离会妨碍您。例如,当使用收集主机指标的 Prometheus node_exporter 时也会发生同样的情况,这在没有访问主机网络的容器中运行时也非常无用。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-14
      • 2020-07-31
      • 2017-03-13
      • 2019-10-25
      • 2017-08-21
      • 2016-12-14
      • 1970-01-01
      • 2016-12-04
      相关资源
      最近更新 更多