elasticsearch,metricbeat,Docker,elasticsearch,Metricbeat" /> elasticsearch,metricbeat,Docker,elasticsearch,Metricbeat" />

如何使用docker将metricbeat连接到elasticsearch和kibana

如何使用docker将metricbeat连接到elasticsearch和kibana,docker,elasticsearch,metricbeat,Docker,elasticsearch,Metricbeat,我已经用docker compose设置了elasticsearch和kibana。elasticsearch部署在:localhost:9200上,而kibana部署在localhost:5601 尝试使用docker run部署metricbeat时,我遇到以下错误: $ docker run docker.elastic.co/beats/metricbeat:6.3.2 setup -E setup.kibana.host=kibana:5601 -E output.elasticsea

我已经用docker compose设置了elasticsearch和kibana。elasticsearch部署在:
localhost:9200
上,而kibana部署在
localhost:5601

尝试使用docker run部署metricbeat时,我遇到以下错误:

$ docker run docker.elastic.co/beats/metricbeat:6.3.2 setup -E setup.kibana.host=kibana:5601 -E output.elasticsearch.hosts=["localhost:9200"]

Exiting: Couldn't connect to any of the configured Elasticsearch hosts. Errors: [Error connection to Elasticsearch http://localhost:9200: Get http://localhost:9200: dial tcp [::1]:9200: connect: cannot assign requested address]

Exiting: Couldn't connect to any of the configured Elasticsearch hosts. Errors: [Error connection to Elasticsearch http://elasticsearch:9200: Get http://elasticsearch:9200: lookup elasticsearch on 192.168.65.1:53: no such host]
My docker-compose.yml:

# ./docker-compose.yml

version: "3.7"
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.3.2
    environment:
#      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - elkdata:/usr/share/elasticsearch/data
    ports:
      - "9200:9200"
    restart: always
  kibana:
    image: docker.elastic.co/kibana/kibana:6.3.2
    volumes:
      - kibana:/usr/share/kibana/config
    ports:
      - "5601:5601"
    depends_on:
      - elasticsearch
    restart: always
volumes:
  elkdata:
  kibana:

首先通过添加默认docker网络的名称来编辑您的
docker compose
文件:

version: "3.7"
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.3.2
    environment:
#      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - elkdata:/usr/share/elasticsearch/data
    ports:
      - "9200:9200"
    networks:
      - my-network
    restart: always
  kibana:
    image: docker.elastic.co/kibana/kibana:6.3.2
    volumes:
      - kibana:/usr/share/kibana/config
    ports:
      - "5601:5601"
    networks:
      - my-network
    depends_on:
      - elasticsearch
    restart: always
volumes:
  elkdata:
  kibana:
networks:
  my-network:
    name: awesome-name
执行
docker compose up
,然后使用以下命令启动
metricbeat

$ docker run docker.elastic.co/beats/metricbeat:6.3.2 --network=awesome-name setup -E setup.kibana.host=kibana:5601 -E output.elasticsearch.hosts=["elasticsearch:9200"]
说明:

当您尝试部署
metricbeat
时,您提供以下环境:

  • setup.kibana.host=kibana:5601
  • output.elasticsearch.hosts=[“localhost:9200”]
我将从第二个开始。使用
docker run
命令,当您启动
metricbeat
时,您告诉容器它可以访问
localhost:9200
上的弹性搜索。因此,当容器启动时,它将访问端口9200上的本地主机,期望找到正在运行的
elasticsearch
。但是,由于容器是一个具有自己网络层的主机隔离进程,
localhost
解析为容器本身,而不是您期望的docker主机

关于
kibana
主机的设置,您应该首先了解
docker compose
的工作原理。默认情况下,当您执行
docker compose up
时,将创建一个docker网络,并将yml文件中定义的所有服务添加到此网络。在这个网络内部,只有可以通过服务名称访问服务。对于您的情况,如yml文件中所定义,它们的名称将是
elasticsearch
kibana

因此,为了使
metricbeat
容器能够与
elasticsearch
kibana
容器通信,应将其添加到同一docker网络中。这可以通过在
docker run
命令上设置
--network
标志来实现

另一种方法是通过使用与容器共享docker主机的网络,但我不建议这样做

参考资料:


使用
docker run--network=awesome name docker.elastic.co/beats/metricbeat:6.3.2 setup-E setup.kibana.host=kibana:5601-E output.elasticsearch.hosts=[“elasticsearch:9200”]
并在docker-compose.ymlI中缩进
名称:awesome name
,修复了缩进问题,乐于帮助!