单节点ElasticSearch 7 docker-compose.yml
Elasticsearch 7 集群启动
在开发环境,往往只需要启动单节点的ElasticSearch进行开发。对于ElasticSearch 6,启动一个单节点集群和多节点集群是相同的。
从ElasticSearch 7开始,首次启动集群,需要在集群的主节点中明确定义初始主节点集(即设置参数cluster.initial_master_nodes),集群启动过程中做一个引导启动检查,称为bootstrap checks。对于单节点,按集群默认方式启动,在bootstrap check阶段就会失败。
单节点错误类似:
ERROR: [1] bootstrap checks failed
[1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
单节点启动
ElasticSearche 7设置为开发模式,启动单节点,需要设置参数discovery.type
为single-node
。docker-compose.yml 示例如下
version: '3.7'
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.16.0
container_name: elasticsearch
environment:
- xpack.security.enabled=false
- discovery.type=single-node
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
cap_add:
- IPC_LOCK
volumes:
- elasticsearch-data:/usr/share/elasticsearch/data
- elasticsearch-plugins:/usr/share/elasticsearch/plugins
ports:
- 9200:9200
- 9300:9300
networks:
- elastic
volumes:
elasticsearch-data:
driver: local
elasticsearch-plugins:
driver: local
networks:
elastic:
driver: bridge
这是一个单节点版,可以在开发环境中使用的一个elasticsearch 7 docker-compose.yml。
其中:
- 9200作为Http协议,主要用于外部通讯
- 9300作为Tcp协议,jar之间就是通过tcp协议通讯
- ES集群之间是通过9300进行通讯
xpack.security.enabled
设置为false,表示禁止xpack- volumes可以根据实际来设置一个本地的路径。
ES_JAVA_OPTS=-Xms512m -Xmx512m
设置ES允许的jvm大小
启动单机集群
启动elasticsearch 单机集群,进入docker-compose.yml文件同级目录,执行:
docker-compose up -d
停止elastsearch集群,进入docker-compose.yml文件同级目录,执行:
docker-compose down
如果想停止集群的时候,同时删除volume,执行:
docker-compse down -v
启动后测试:
sudo curl http://127.0.0.1:9200/
显示结果类似,则表示部署成功:
{
"name" : "8f0257230088",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "5dsUbbM7SFWszH4n8nbTbA",
"version" : {
"number" : "7.16.0",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "6fc81662312141fe7691d7c1c91b8658ac17aa0d",
"build_date" : "2021-12-02T15:46:35.697268109Z",
"build_snapshot" : false,
"lucene_version" : "8.10.1",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}