弹性节点不共享数据?

时间:2019-08-22 14:03:53

标签: elasticsearch docker-compose

HI目前,我正在使用docker compose来启动两个弹性容器实例,并在它们之间建立网络。

在一个弹性容器中,我正在执行批量api请求,以将一些文档插入索引。

但是问题是,当我分别登录每个弹性容器并对其执行curl命令时,结果却没有。

Prasanths-MacBook-Air:api kannan$ docker ps
CONTAINER ID        IMAGE                                                 COMMAND                  CREATED             STATUS              PORTS                              NAMES
798c06a9907b        docker_elasticsearch2                                 "/docker-entrypoint.…"   8 minutes ago       Up 8 minutes        9200/tcp, 9300/tcp                 elasticsearch2
336e58a46217        docker.elastic.co/elasticsearch/elasticsearch:6.6.1   "/usr/local/bin/dock…"   8 minutes ago       Up 8 minutes        0.0.0.0:9200->9200/tcp, 9300/tcp   elasticsearch

现在尝试try curl命令登录以列出每个容器上的每个索引

Prasanths-MacBook-Air:api kannan$ docker exec -it 798c06a9907b curl '127.0.0.1:9200/_cat/indices?v&pretty'
health status index uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   test  z27UBFUWTfC3E-xFFDhLOQ   5   1          0            0      1.2kb          1.2kb
yellow open   cars  R5mvqQk2RkuspNQ6o02E4g   5   1        833            0    491.6kb        491.6kb

现在尝试以下操作

Prasanths-MacBook-Air:api kannan$ docker exec -it 336e58a46217 curl '127.0.0.1:9200/_cat/indices?v&pretty'
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size

这是使用以下命令命名为elasticsearch.yml的docker组成文件

docker-compose -f src/main/docker/elasticsearch.yml up

这是文件elasticsearch.yml的内容

version: '2.0'
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.6.1
    container_name: elasticsearch
    environment:
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata1:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
    networks:
      - esnet
  elasticsearch2:
    build:
        context: .
        dockerfile: elasticsearch/elasticsearch-Migration.Dockerfile
    container_name: elasticsearch2
    environment:
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - "discovery.zen.ping.unicast.hosts=elasticsearch"
      - network.host=0.0.0.0
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata2:/usr/share/elasticsearch/data
    networks:
      - esnet

volumes:
  esdata1:
    driver: local
  esdata2:
    driver: local

networks:
  esnet:

在我对容器elasticsearch执行curl命令时为什么索引未正确列出并且对容器elasticsearch2正常工作的任何想法

非常感谢

1 个答案:

答案 0 :(得分:0)

尝试这个yml文件,希望它能工作

version: '2.0'
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.6.1
    container_name: elasticsearch
    environment:
      - node.master=true
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata1:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
    networks:
      - esnet
  elasticsearch2:
    build:
        context: .
        dockerfile: elasticsearch/elasticsearch-Migration.Dockerfile
    container_name: elasticsearch2
    environment:
      - node.master=false
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - "discovery.zen.ping.unicast.hosts=elasticsearch"
      - network.host=0.0.0.0
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata2:/usr/share/elasticsearch/data
    networks:
      - esnet

volumes:
  esdata1:
    driver: local
  esdata2:
    driver: local

networks:
  esnet: