查看官网最新版本7.12.1 ,下载镜像文件
docker pull elasticsearch:7.12.1
创建es文件夹,es下再创建三个目录conf、data、plugins,准备做数据挂载
为es文件夹添加777权限(不添加启动时会报错)
chmod -R 777 es
conf文件夹中添加配置文件elasticsearch.yml
cluster.name: "docker-cluster"
network.host: 0.0.0.0
http.port: 9200
node.name: node-1
path.data: /usr/share/elasticsearch/data
path.logs: /usr/share/elasticsearch/logs
cluster.initial_master_nodes: ["node-1"]
indices.fielddata.cache.size: 50%
生成创建容器
docker run -itd -p 9200:9200 --name elasticsearch -e ES_JAVA_OPTS="-Xms512m -Xmx512m" -v /docker/es/conf/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /docker/es/data:/usr/share/elasticsearch/data -v /docker/es/plugins:/usr/share/elasticsearch/plugins --privileged=true elasticsearch:7.12.1
elasticsearch启动的时候经常出现的两个原因错误
ERROR: [2] bootstrap checks failed. You must address the points described in the following [2] lines before starting Elasticsearch.
bootstrap check failure [1] of [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
bootstrap check failure [2] of [2]: 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
第一个问题就是配置问题,默认配置是无法启动elasticsearch的,配置文件没有设置如下两项,就会出现第一个错误
node.name: node-1
cluster.initial_master_nodes: ["node-1"]
第二个问题意思就是vm.max_map_count 太小了,请至少增加到262144
查看vm.max_map_count
sysctl -a|grep vm.max_map_count
修改文件
vim /etc/sysctl.conf
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210522124414489.png
从指定的文件加载系统参数,如不指定即从/etc/sysctl.conf中加载
sysctl -p
再次查看,修改成功
重新启等docker,成功