我已经用docker compose设置了elasticsearch和kibana。localhost:9200elasticsearch 部署在:kibana部署在localhost:5601
localhost:9200
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]
我的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-compose通过添加默认码头工人网络的名称来编辑文件:
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-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,您需要提供以下envar:
setup.kibana.host=kibana:5601
output.elasticsearch.hosts=["localhost:9200"]
我将从第二个开始。使用dockerrun命令,在启动时metricbeat,您告诉容器它可以访问上的elasticsearchlocalhost:9200。因此,当容器启动时,它将访问端口9200上的localhost,期望找到elasticsearch运行状态。但是,由于容器是一个主机隔离的进程,具有自己的网络层,因此localhost解析为容器本身 ,而不是您所期望的docker主机。
dockerrun
elasticsearch
localhost
关于kibana主机的设置,首先应了解其docker-compose工作原理。默认情况下,当您执行时docker-composeup,将创建一个docker网络,并将yml文件上定义的所有服务都添加到该网络。 仅 在 该网络 内部,可以通过服务名称访问服务。对于你的情况下,阳明文件的定义,他们的名字将是elasticsearch,kibana。
kibana
docker-composeup
因此,为了使metricbeat容器能够与elasticsearch和kibana容器进行通信,应将其添加到同一docker网络中。这可以通过--network在dockerrun命令上设置标志来实现。
--network
另一种方法是使用网络模式host与容器共享docker主机的网络,但我不建议这样做。
参考文献:
Docker撰写
docker运行