web-dev-qa-db-fra.com

docker-compose.yml pour elasticsearch et kibana

Mon objectif est de faire en sorte que les images elasticsearch et kibana de DockerHub fonctionnent localement avec Docker.

Cela fait l'affaire et fonctionne parfaitement ...

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

Aujourd'hui, un oiseau m'a murmuré à l'oreille et m'a dit que je devrais apprendre à composer des dockers. J'ai donc essayé de faire tout ce qui précède dans un fichier docker-compose.yml.

Voici ma tentative.

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

Malheureusement ça ne fonctionne pas. Je me suis demandé pourquoi je reçois toujours l'erreur ECONNREFUSED, comme indiqué ci-dessous, lorsque je lance docker-compse up.

$ 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:[email protected]","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:[email protected]","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:[email protected]","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:[email protected]","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:[email protected]","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:[email protected]","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:[email protected]","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:[email protected]","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:[email protected]","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:[email protected]","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

Quelqu'un peut-il m'aider s'il vous plaît avec pourquoi?

merci

5
Richie

Pour ajouter la forte dépendance à elasticsearch pour kibana, vous devez définir la variable depend_on comme indiqué ci-dessous. En outre, pour ajouter à la réponse de @Phil McMillan, vous pouvez définir la variable elasticsearch_url dans kibana, sans adressage statique à l'aide de Le mécanisme DNS intégré de Docker .

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

Notez que la variable d'environnement ELASTICSEARCH_URL = http: // elasticsearch: 9200 utilise simplement le nom du conteneur (elasticsearch) que le serveur DNS Docker est capable de résoudre.

4
oche

Vous devez inclure la 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

MIS À JOUR

Lorsque vous utilisez l'image elasticsearch:latest, c'est Elasticsearch 5.0 et nous impose d'augmenter la mémoire virtuelle de notre hôte Docker.

Avant d’exécuter le docker-compose, assurez-vous d’exécuter cette commande sur votre hôte 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

Si vous ne souhaitez pas modifier votre hôte Docker, utilisez simplement l'image Elasticsearch 2.x à elasticsearch:2.

13
Tuan

J'ai ce travail. Aucun lien n'est nécessaire et cela n'a rien à voir avec elasticsearch commençant avant kibana. Le problème est que lors de l’exécution de la composition, un nouveau réseau ponté est défini avec son propre ensemble d’adresses IP. Kibana doit communiquer avec le cluster via ce réseau ponté - "localhost" n'est plus disponible pour la connectivité. 

Vous devez faire quelques choses:

  1. Vous devez définir quelques valeurs dans kibana.yml ou sous l’environnement: section de kibana dans le fichier de composition):

une. elasticsearch.url dans kibana.yml (ou ELASTICSEARCH_URL sous l'environnement: section de kibana dans le fichier compose) doit être défini sur l'adresse IP spécifique du cluster et le port 9200 - localhost ne fonctionnera pas, comme cela se produit lorsque vous exécutez en dehors de la composition .

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

b. Vous devez également définir server.Host (SERVER_Host) sur l'adresse IP pontée du conteneur Kibana.

server.Host: "172.16.238.12"  

Remarque: vous avez toujours accès à l'interface utilisateur de kibana à partir de http://127.0.0.1:5601 et vous avez toujours besoin de ces commandes "ports"!

  1. Vous devez définir une configuration "ipam" sous votre réseau ponté et attribuer des ips statiques à elasticsearch et kibana afin que kibana puisse y accéder via la configuration ci-dessus.

Quelque chose comme ça devrait suffire:

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

N'oubliez pas d'utiliser l'une des méthodes documentées pour définir la configuration de Kibana - ELASTICSEARCH_URL doit être défini!

J'ai un fichier de composition de docker qui crée deux nœuds elasticsearch et une instance de kibana fonctionnant tous sur le même réseau ponté. C'est possible.

1
Phil McMillan