docker-compose.yml for elasticsearch和kibana

时间:2016-11-02 06:02:38

标签: elasticsearch docker docker-compose kibana

我的目标是使用Docker从DockerHub获取elasticsearch和kibana图像。

这样做的诀窍和完美的工作......

docker network create mynetwork --driver=bridge

docker run -p 5601:5601 --name kibana -d --network mynetwork kibana 
docker run -p 9200:9200 -p 9300:9300 --name elasticsearch -d --network mynetwork elasticsearch

今天一只鸟在我耳边低声说我应该学习码头组合。所以我尝试在docker-compose.yml中完成上述所有操作。

这是我的尝试。

version: "2.0"
services:
  elasticsearch:
    image: elasticsearch:latest
    ports:
      - "9200:9200"
      - "9300:9300"
    networks:
      - docker_elk
  kibana:
    image: kibana:latest
    ports:
      - "5601:5601"
    networks:
      - docker_elk
networks:
  docker_elk:
    driver: bridge

不幸的是,这不起作用。当我运行docker-compse时,为什么我总是得到如下所示的ECONNREFUSED错误,我一直绞尽脑汁。

$ docker-compose up
Starting training_elasticsearch_1
Recreating training_kibana_1
Attaching to training_elasticsearch_1, training_kibana_1
elasticsearch_1  | [2016-11-02 22:39:55,798][WARN ][bootstrap                ] unable to install syscall filter: seccomp unavailable: your kernel is buggy and you should upgrade
elasticsearch_1  | [2016-11-02 22:39:56,036][INFO ][node                     ] [Caliban] version[2.4.1], pid[1], build[c67dc32/2016-09-27T18:57:55Z]
elasticsearch_1  | [2016-11-02 22:39:56,036][INFO ][node                     ] [Caliban] initializing ...
elasticsearch_1  | [2016-11-02 22:39:56,713][INFO ][plugins                  ] [Caliban] modules [reindex, lang-expression, lang-groovy], plugins [], sites []
elasticsearch_1  | [2016-11-02 22:39:56,749][INFO ][env                      ] [Caliban] using [1] data paths, mounts [[/usr/share/elasticsearch/data (/dev/vda2)]], net usable_space [54.8gb], net total_space [59gb], spins? [possibly], types [ext4]
elasticsearch_1  | [2016-11-02 22:39:56,749][INFO ][env                      ] [Caliban] heap size [990.7mb], compressed ordinary object pointers [true]
kibana_1         | {"type":"log","@timestamp":"2016-11-02T22:39:58Z","tags":["status","plugin:kibana@1.0.0","info"],"pid":11,"state":"green","message":"Status changed from uninitialized to green - Ready","prevState":"uninitialized","prevMsg":"uninitialized"}
kibana_1         | {"type":"log","@timestamp":"2016-11-02T22:39:58Z","tags":["status","plugin:elasticsearch@1.0.0","info"],"pid":11,"state":"yellow","message":"Status changed from uninitialized to yellow - Waiting for Elasticsearch","prevState":"uninitialized","prevMsg":"uninitialized"}
kibana_1         | {"type":"log","@timestamp":"2016-11-02T22:39:58Z","tags":["error","elasticsearch"],"pid":11,"message":"Request error, retrying -- connect ECONNREFUSED 172.20.0.2:9200"}
kibana_1         | {"type":"log","@timestamp":"2016-11-02T22:39:58Z","tags":["status","plugin:kbn_vislib_vis_types@1.0.0","info"],"pid":11,"state":"green","message":"Status changed from uninitialized to green - Ready","prevState":"uninitialized","prevMsg":"uninitialized"}
kibana_1         | {"type":"log","@timestamp":"2016-11-02T22:39:58Z","tags":["warning","elasticsearch"],"pid":11,"message":"Unable to revive connection: http://elasticsearch:9200/"}
kibana_1         | {"type":"log","@timestamp":"2016-11-02T22:39:58Z","tags":["warning","elasticsearch"],"pid":11,"message":"No living connections"}
kibana_1         | {"type":"log","@timestamp":"2016-11-02T22:39:58Z","tags":["status","plugin:elasticsearch@1.0.0","error"],"pid":11,"state":"red","message":"Status changed from yellow to red - Unable to connect to Elasticsearch at http://elasticsearch:9200.","prevState":"yellow","prevMsg":"Waiting for Elasticsearch"}
kibana_1         | {"type":"log","@timestamp":"2016-11-02T22:39:58Z","tags":["status","plugin:markdown_vis@1.0.0","info"],"pid":11,"state":"green","message":"Status changed from uninitialized to green - Ready","prevState":"uninitialized","prevMsg":"uninitialized"}
kibana_1         | {"type":"log","@timestamp":"2016-11-02T22:39:58Z","tags":["status","plugin:metric_vis@1.0.0","info"],"pid":11,"state":"green","message":"Status changed from uninitialized to green - Ready","prevState":"uninitialized","prevMsg":"uninitialized"}
kibana_1         | {"type":"log","@timestamp":"2016-11-02T22:39:58Z","tags":["status","plugin:spyModes@1.0.0","info"],"pid":11,"state":"green","message":"Status changed from uninitialized to green - Ready","prevState":"uninitialized","prevMsg":"uninitialized"}
kibana_1         | {"type":"log","@timestamp":"2016-11-02T22:39:58Z","tags":["status","plugin:statusPage@1.0.0","info"],"pid":11,"state":"green","message":"Status changed from uninitialized to green - Ready","prevState":"uninitialized","prevMsg":"uninitialized"}
kibana_1         | {"type":"log","@timestamp":"2016-11-02T22:39:58Z","tags":["status","plugin:table_vis@1.0.0","info"],"pid":11,"state":"green","message":"Status changed from uninitialized to green - Ready","prevState":"uninitialized","prevMsg":"uninitialized"}
kibana_1         | {"type":"log","@timestamp":"2016-11-02T22:39:58Z","tags":["listening","info"],"pid":11,"message":"Server running at http://0.0.0.0:5601"}
elasticsearch_1  | [2016-11-02 22:39:58,515][INFO ][node                     ] [Caliban] initialized
elasticsearch_1  | [2016-11-02 22:39:58,515][INFO ][node                     ] [Caliban] starting ...
elasticsearch_1  | [2016-11-02 22:39:58,587][INFO ][transport                ] [Caliban] publish_address {172.20.0.2:9300}, bound_addresses {[::]:9300}
elasticsearch_1  | [2016-11-02 22:39:58,594][INFO ][discovery                ] [Caliban] elasticsearch/1Cf9qz7CSCqHBEEuwG7PQw
kibana_1         | {"type":"log","@timestamp":"2016-11-02T22:40:00Z","tags":["warning","elasticsearch"],"pid":11,"message":"Unable to revive connection: http://elasticsearch:9200/"}
kibana_1         | {"type":"log","@timestamp":"2016-11-02T22:40:00Z","tags":["warning","elasticsearch"],"pid":11,"message":"No living connections"}
elasticsearch_1  | [2016-11-02 22:40:01,650][INFO ][cluster.service          ] [Caliban] new_master {Caliban}{1Cf9qz7CSCqHBEEuwG7PQw}{172.20.0.2}{172.20.0.2:9300}, reason: zen-disco-join(elected_as_master, [0] joins received)
elasticsearch_1  | [2016-11-02 22:40:01,661][INFO ][http                     ] [Caliban] publish_address {172.20.0.2:9200}, bound_addresses {[::]:9200}
elasticsearch_1  | [2016-11-02 22:40:01,661][INFO ][node                     ] [Caliban] started
elasticsearch_1  | [2016-11-02 22:40:01,798][INFO ][gateway                  ] [Caliban] recovered [1] indices into cluster_state
elasticsearch_1  | [2016-11-02 22:40:02,149][INFO ][cluster.routing.allocation] [Caliban] Cluster health status changed from [RED] to [YELLOW] (reason: [shards started [[.kibana][0]] ...]).
kibana_1         | {"type":"log","@timestamp":"2016-11-02T22:40:03Z","tags":["status","plugin:elasticsearch@1.0.0","info"],"pid":11,"state":"green","message":"Status changed from red to green - Kibana index ready","prevState":"red","prevMsg":"Unable to connect to Elasticsearch at http://elasticsearch:9200."}
^CGracefully stopping... (press Ctrl+C again to force)
Stopping training_kibana_1 ... done
Stopping training_elasticsearch_1 ... done

有人可以帮我解释一下原因吗?

感谢

4 个答案:

答案 0 :(得分:14)

您需要加入links

version: "2.0"
services:
  elasticsearch:
    image: elasticsearch:latest
    ports:
      - "9200:9200"
      - "9300:9300"
    networks:
      - docker_elk
  kibana:
    image: kibana:latest
    ports:
      - "5601:5601"
    links:
      - elasticsearch
    networks:
      - docker_elk
networks:
  docker_elk:
    driver: bridge

<强>已更新

使用图片elasticsearch:latest时,它是Elasticsearch 5.0并要求我们增加Docker主机虚拟内存。

在运行docker-compose之前,请确保在Docker主机上运行此命令。

Linux的:

su root
sysctl -w vm.max_map_count=262144

Windows(boot2docker)

docker-machine ssh default
sudo sysctl -w vm.max_map_count=262144

如果您不想更改Docker主机,只需使用2.x上的Elasticsearch elasticsearch:2图片

答案 1 :(得分:9)

要为kibana添加对弹性搜索的硬依赖性,您需要设置 depends_on 变量,如下所示。另外,要添加@Phil McMillan的答案,您可以使用Docker's inbuilt DNS mechanism在kibana中设置elasticsearch_url变量,不使用静态寻址。

version: '2.1'
services:
     elasticsearch:
       image: docker.elastic.co/elasticsearch/elasticsearch:5.4.3
       container_name: elasticsearch
       networks:
           docker-elk:

     kibana:
       image: docker.elastic.co/kibana/kibana:5.4.3
       container_name: kibana
       environment:
          - "ELASTICSEARCH_URL=http://elasticsearch:9200"
       networks:
          - docker-elk
       depends_on:
          - elasticsearch

networks:
  docker-elk:
    driver: bridge

请注意,环境变量ELASTICSEARCH_URL = http://elasticsearch:9200只使用具有Docker DNS服务器能够解析的容器名称(elasticsearch)。

答案 2 :(得分:1)

我有这个工作。不需要任何链接,它与在kibana之前开始的elasticsearch没有任何关系。问题是,在compose下运行时,会使用自己的IP集定义新的桥接网络。 Kibana需要通过这个桥接网络与集群进行通信 - &#34; localhost&#34;不再可用于连接。

你需要做几件事:

  1. 你需要在kibana.yml或环境下设置几个值:compose文件中的kibana部分:
  2. 一个。 kibana.yml中的elasticsearch.url(或环境下的ELASTICSEARCH_URL:撰写文件中的kibana部分)必须设置为群集的特定IP和端口9200 - localhost将不起作用,就像在compose外部运行时一样

    elasticsearch.url: "http://172.16.238.10:9200"
    

    湾您还需要将server.host(SERVER_HOST)设置为Kibana容器的桥接IP。

    server.host: "172.16.238.12"  
    

    注意:您仍然可以使用http://127.0.0.1:5601访问kibana UI,但仍然需要这些&#34;端口&#34;命令!

    1. 你需要设置一个&#34; ipam&#34;您的桥接网络下的配置并分配elasticsearch和kibana静态ips,以便kibana可以通过上面的配置访问它。
    2. 这样的事情应该足够了:

      elasticsearch:
        networks:
          esnet:
            ipv4_address: 172.16.238.10
      kibana:
        networks:
          esnet:
            ipv4_address: 172.16.238.12
      networks:
        esnet:
          driver: bridge
          ipam:
            driver: default
            config:
              - subnet: 172.16.238.0/24
      

      请勿忘记使用其中一种记录方法来设置Kibana配置 - 需要设置ELASTICSEARCH_URL!

      我有一个docker compose文件,它创建了两个elasticsearch节点和一个kibana实例,它们都在同一个桥接网络上运行。这是可能的。

答案 3 :(得分:0)

这对我有用 docker-composer.yml

version: '3'
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.6.2
    environment:
      - discovery.type=single-node
    ports:
      - 9200:9200
  kibana:
    image: docker.elastic.co/kibana/kibana:7.6.2
    ports:
      - 5601:5601