做實驗時需要了解Elasticsearch叢集如何操作?通過使用docker-compose可以批量建立docker容器,啟動ES叢集。

先配置檔案docker-compose.yml檔案如下:

 1 version: '2.2'
 2 networks:
 3   esnet:
 4 services:
 5   es00:
 6     image: docker.elastic.co/elasticsearch/elasticsearch:6.5.1
 7     container_name: es00
 8     environment:
 9       - cluster.name=esdocker-cluster
10       - node.name=node-00
11       - bootstrap.memory_lock=true
12       - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
13       - http.cors.enabled=true
14       - http.cors.allow-origin=*
15     ulimits:
16       memlock:
17         soft: -1
18         hard: -1
19     volumes:
20       - .\es00:/usr/share/elasticsearch/data
21     ports:
22       - 9200:9200
23       - 9300:9300
24     networks:
25       - esnet
26   es01:
27     image: docker.elastic.co/elasticsearch/elasticsearch:6.5.1
28     container_name: es01
29     environment:
30       - cluster.name=esdocker-cluster
31       - node.name=node-01
32       - bootstrap.memory_lock=true
33       - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
34       - "discovery.zen.ping.unicast.hosts=es00"
35     ulimits:
36       memlock:
37         soft: -1
38         hard: -1
39     volumes:
40       - .\es01:/usr/share/elasticsearch/data
41     ports:
42       - 9201:9200
43       - 9301:9300
44     networks:
45       - esnet
46     depends_on:
47       - es00
48   es02:
49     image: docker.elastic.co/elasticsearch/elasticsearch:6.5.1
50     container_name: es02
51     environment:
52       - cluster.name=esdocker-cluster
53       - node.name=node-02
54       - bootstrap.memory_lock=true
55       - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
56       - "discovery.zen.ping.unicast.hosts=es00"
57     ulimits:
58       memlock:
59         soft: -1
60         hard: -1
61     volumes:
62       - .\es02:/usr/share/elasticsearch/data
63     ports:
64       - 9202:9200
65       - 9302:9300
66     networks:
67       - esnet
68     depends_on:
69       - es00
70 
71   kibana:
72     image: docker.elastic.co/kibana/kibana:6.5.1
73     container_name: kibana
74     environment:
75       - SERVER_NAME=kibana
76       - ELASTICSEARCH_URL=http://es00:9200
77       - XPACK_MONITORING_ENABLED=true
78     ports:
79       - 5601:5601
80     networks:
81       - esnet
82     depends_on:
83       - es00
84     external_links:
85       - es00

說明:

第一個networks貌似得放前面,不然後面網路找不到es00,貌似這是和官方文件唯一的區別,坑了好久。
也可以像下面這樣寫,但是必須在啟動之前先建立docker網路,執行命令(docker network create esnet)即可。
1 networks:
2   esnet:
3     external: true

執行docker-compose up即可啟動Elasticsearch叢集和kibana。

docker-compose down 刪除docker。

參考官方文件: