yml用于ElasticSearch和kibana

smdnsysy  于 2022-12-09  发布在  Kibana
关注(0)|答案(6)|浏览(197)

我的目标是让ElasticSearch和kibana图像从DockerHub工作本地使用Docker。
这就成功了,效果很好。

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,所以我试着在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

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

$ 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

有人能告诉我为什么吗?
谢谢

bogh5gae

bogh5gae1#

要为kibana添加对elasticsearch的硬依赖,您需要如下所示设置depends_on变量。另外,要添加到@Phil McMillan的答案,您可以在kibana中设置elasticsearch_url变量,* 而不 * 使用Docker内置的DNS机制进行静态寻址。

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)。

5sxhfpxr

5sxhfpxr2#

您需要包含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(引导文件扩展)

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

如果你不想改变你的Docker主机,只要使用Elasticsearch 2.x图片在elasticsearch:2

uinbv5nw

uinbv5nw3#

我使用的是docker-compose v3格式,符合this post

version: '3'
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.10.2
    container_name: elasticsearch
    environment:
      - node.name=es-node
      - cluster.name=es-cluster
      - discovery.type=single-node
    ports:
      - 9200:9200
      - 9300:9300
    volumes:
      - local-es:/usr/share/elasticsearch/data
    networks:
      - es-net

  kibana:
    image: docker.elastic.co/kibana/kibana:7.10.2
    container_name: kibana
    environment:
      - "ELASTICSEARCH_URL=http://elasticsearch:9200"
    ports:
      - 5601:5601
    networks:
      - es-net
    depends_on:
      - elasticsearch
    restart: "unless-stopped"

networks:
  es-net:

volumes:
  local-es:
3duebb1j

3duebb1j4#

这对我很有效docker-compose.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
lskq00tm

lskq00tm5#

我有这个工作。不需要链接,它没有任何关系的elasticsearch开始kibana之前。问题是,当运行在组成,一个新的桥接网络定义了自己的一组IP。Kibana需要与集群通信在这个桥接网络-“localhost”是不可用的连接了。
您需要执行以下操作:
1.您需要在kibana.yml中或在以下环境中设置几个值:部分):
a. kibana.yml中的elasticsearch.url(或环境下的ElastICSEARCH_URL:部分)必须设置为群集的特定IP,并且端口9200 - localhost将不起作用,这与在compose之外运行时相同。

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

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

server.host: "172.16.238.12"

注意:您仍然可以使用http://127.0.0.1:5601从访问kibana UI,并且仍然需要那些“ports”命令!
1.你需要在你的桥接网络下设置一个“ipam”配置,并分配elasticsearch和kibana静态ip,以便kibana可以通过上面的配置访问它。
下面这样就足够了:

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合成文件,它创建了两个elasticsearch节点和一个kibana示例,它们都运行在同一个桥接网络上。

neskvpey

neskvpey6#

文件docker-compose.yml

version: '3'
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.5.2
    container_name: elasticsearch
    environment:
      - node.name=es-node
      - cluster.name=es-cluster
      - discovery.type=single-node
      - xpack.security.enabled=false
    ports:
      - 9200:9200
      - 9300:9300
    volumes:
      - ./docker-data/elasticsearch/data:/usr/share/elasticsearch/data
    networks:
      - elastic
  kibana:
    image: docker.elastic.co/kibana/kibana:8.5.2
    container_name: kibana
    ports:
      - 5601:5601
    networks:
      - elastic
    depends_on:
      - elasticsearch
    restart: 'unless-stopped'

networks:
  elastic:

正式文件:
Install Kibana with Docker

相关问题