使用DockerCompose搭建部署ElasticSearch集群
机器准备
模拟3台机器:
节点名称 | ip:host | 说明 |
---|---|---|
elasticsearch1 | 192.168.200.135:9300 | 映射9200给kibana访问 |
elasticsearch2 | 192.168.200.135:9302 | |
elasticsearch3 | 192.168.200.135:9303 |
需要注意的是elasticsearch1映射宿主机9200端口,主要用作给kibana访问。
官方的推荐做法是加一个协调节点,然后kibana通过该协调节点来访问。详情见:https://www.elastic.co/guide/en/kibana/6.8/production.html#load-balancing 。
其实个人觉得这种方案是有问题的,假设该协调节点故障,则会导致kibana无法连接。如果在生产环境,一般通过nginx做反向代理实现高可用,避免该协调节点故障导致kibana无法使用的问题。
docker-compolse.yml如下:
version: '3'
services:
elasticsearch1:
image: docker.elastic.co/elasticsearch/elasticsearch:6.8.13
container_name: elasticsearch1
environment:
- node.name=elasticsearch1
- node.master=true
- node.data=true
- http.cors.enabled=true
- http.cors.allow-origin=*
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
#- "discovery.zen.ping.unicast.hosts=elasticsearch"
- discovery.zen.ping.unicast.hosts=192.168.200.135:9300,192.168.200.135:9302,192.168.200.135:9303
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- esdata1:/usr/share/elasticsearch/data
- /docker/es-cluster/plugins:/usr/share/elasticsearch/plugins
ports:
- 9300:9300
- 9200:9200
networks:
- esnet
privileged: true #环境变量
elasticsearch2:
image: docker.elastic.co/elasticsearch/elasticsearch:6.8.13
container_name: elasticsearch2
environment:
- node.name=elasticsearch2
- node.master=true
- node.data=true
- http.cors.enabled=true
- http.cors.allow-origin=*
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- discovery.zen.ping.unicast.hosts=192.168.200.135:9300,192.168.200.135:9302,192.168.200.135:9303
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- esdata2:/usr/share/elasticsearch/data
- /docker/es-cluster/plugins:/usr/share/elasticsearch/plugins
ports:
- 9301:9300
networks:
- esnet
privileged: true #环境变量
elasticsearch3:
image: docker.elastic.co/elasticsearch/elasticsearch:6.8.13
container_name: elasticsearch3
environment:
- node.name=elasticsearch3
- node.master=true
- node.data=true
- http.cors.enabled=true
- http.cors.allow-origin=*
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- discovery.zen.ping.unicast.hosts=192.168.200.135:9300,192.168.200.135:9302,192.168.200.135:9303
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- esdata3:/usr/share/elasticsearch/data
- /docker/es-cluster/plugins:/usr/share/elasticsearch/plugins
ports:
- 9303:9300
networks:
- esnet
privileged: true #环境变量
kibana:
image: kibana:6.8.13
restart: always
container_name: kibana
environment:
- SERVER_NAME=kibana
- ELASTICSEARCH_URL=http://192.168.200.135:9200
- XPACK_MONITORING_ENABLED=true
#volumes:
#- /docker/kibana/kibana.yml:/usr/share/kibana/config/kibana.yml
ports:
- 5601:5601
networks:
- esnet
depends_on:
- elasticsearch1
privileged: true #环境变量
volumes:
esdata1:
driver: local
esdata2:
driver: local
esdata3:
driver: local
networks:
esnet: