今天尝试简单学习了下docker-compose
,然后参考了下官方文档,并稍作修改后【copy官方】,写了一个搭建es
集群的docker-compse
脚本,下述命令大体如复制自官方的文档:官方文档 docker-compose相关
version: '2.2'
services:
es01:
image: docker.elastic.co/elasticsearch/elasticsearch:7.8.1
container_name: es01
environment:
- node.name=es01
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es02,es03
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- data01:/usr/share/elasticsearch/data
ports:
- 9200:9200
networks:
- elastic
es02:
image: docker.elastic.co/elasticsearch/elasticsearch:7.8.1
container_name: es02
environment:
- node.name=es02
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es01,es03
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- data02:/usr/share/elasticsearch/data
networks:
- elastic
es03:
image: docker.elastic.co/elasticsearch/elasticsearch:7.8.1
container_name: es03
environment:
- node.name=es03
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es01,es02
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- data03:/usr/share/elasticsearch/data
networks:
- elastic
volumes:
data01:
driver: local
data02:
driver: local
data03:
driver: local
networks:
elastic:
driver: bridge
虽然是官方文档中原封不同的,但是很可惜,在我的CentOs8
和Mac 10.14
下均无法成功执行。
其会报一个错误:
[master-a.example.com] master not discovered yet, this node has not previously joined a bootstrapped (v7+) cluster, and this node must discover master-eligible nodes [master-a, master-b] to bootstrap a cluster: have discovered [{master-b.example.com}{...
大体意思就是说:选主没有成功。
经过我各种查找,发现如果网络模式采用bridge
无法运行,要修改为local
才可以。
好吧,说实话,如果改成local
,那么用不用docker
我认为都差不多了,下面我还是将脚本奉上
version: '2.2'
services:
elasticsearch-01:
image: elasticsearch:7.8.0
container_name: es01
network_mode: "host"
restart: always
environment:
- node.name=es01
- network.host=192.168.0.202
- http.port=9201
- transport.tcp.port=9301
- cluster.name=es-ue-cluster
- discovery.seed_hosts=192.168.0.202:9301,192.168.0.202:9302,192.168.0.202:9303
- cluster.initial_master_nodes=es01
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms1024m -Xmx1024m"
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
volumes:
- /mx-prod/docker-data/elastic/elasticsearch/es01-data:/usr/share/elasticsearch/data
ports:
- 9201:9201
elasticsearch-02:
image: elasticsearch:7.8.0
container_name: es02
network_mode: "host"
restart: always
environment:
- node.name=es02
- network.host=192.168.0.202
- http.port=9202
- transport.tcp.port=9302
- cluster.name=es-ue-cluster
- discovery.seed_hosts=192.168.0.202:9301,192.168.0.202:9302,192.168.0.202:9303
- cluster.initial_master_nodes=es01
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms1024m -Xmx1024m"
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
volumes:
- /mx-prod/docker-data/elastic/elasticsearch/es02-data:/usr/share/elasticsearch/data
elasticsearch-03:
image: elasticsearch:7.8.0
container_name: es03
network_mode: "host"
restart: always
environment:
- node.name=es03
- network.host=192.168.0.202
- http.port=9203
- transport.tcp.port=9303
- cluster.name=es-ue-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms1024m -Xmx1024m"
- discovery.seed_hosts=192.168.0.202:9301,192.168.0.202:9302,192.168.0.202:9303
- cluster.initial_master_nodes=es01
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
volumes:
- /mx-prod/docker-data/elastic/elasticsearch/es03-data:/usr/share/elasticsearch/data
kibana:
image: kibana:7.8.0
network_mode: "host"
container_name: kib1
restart: always
privileged: true
ports:
- 5601:5601
environment:
ELASTICSEARCH_URL: http://192.168.0.202:9201
ELASTICSEARCH_HOSTS: http://192.168.0.202:9201
以下为主要修改的内容:
http
和tcp
端口discovery.seed_hosts
通过ip:port
来编写network_mode: "host"
就是主机模式【这是让我最接受不了的】通过docker-compose
在一台服务器上部署elasticsearch
集群,在实际生产环境中是绝对不可取的,所以通过官方脚本无法执行也能理解。
但是,但是:官方的脚本他们自己没试过吗?我看到不少国外论坛包括github
也有人在说这个问题啊。