代码之家  ›  专栏  ›  技术社区  ›  forJ

Packetbeat无法连接到elasticsearch docker

  •  0
  • forJ  · 技术社区  · 6 年前

    我正在尝试对接所有需要使用的弹性服务。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。如果我删除 -弹性的 网络和添加 -host 网络,我不能连接到弹性搜索,因为DNS弹性搜索不再存在于不同的网络中。我怎样才能克服这个问题?

    1 回复  |  直到 6 年前
        1
  •  1
  •   Andreas Jägle    6 年前

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

    network_mode: host 还有码头工人 networks 一起。因此,对于您的用例,您可以让packetbeat容器与主机网络一起运行,而不将其附加到docker网络。因此,您无法再通过 http://elasticsearch:9200 http://your-host-ip:9200 您已经在elasticsearch服务中将其配置为映射端口。可能 http://127.0.0.1 也可以在跑步时使用 因为这应该是 localhost 在您的主机网络中-因此是elasticsearch端口映射到的主机。