docker直接启动es,报如下错误
2024-08-22 10:52:27 ERROR: [1] bootstrap checks failed. You must address the points described in the following [1] lines before starting Elasticsearch.
2024-08-22 10:52:27 bootstrap check failure [1] of [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
遂寻找如何正确使用docker启动es容器
- 创建docker容器挂载目录(替换成自己的目录)
bash
mkdir -p ~/Documents/DevApp/config/elasticsearch/config
mkdir -p ~/Documents/DevApp/config/elasticsearch/data
echo "http.host: 0.0.0.0">>~/Documents/DevApp/config/elasticsearch/config/elasticsearch.yml
注意⚠️:chmod -R 777 /mydata/elasticsearch 要有访问权限
- 创建实例并启动ES
bash
sudo docker run --name elasticsearch -p 9200:9200 -p 9300:9300 \
-e ES_JAVA_OPS="-Xms256m -Xmx256m" \
-v ~/Documents/DevApp/config/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v ~/Documents/DevApp/config/elasticsearch/data:/usr/share/elasticsearch/data \
-v ~/Documents/DevApp/config/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-d elasticsearch:7.17.23
参数说明:
-p 9200:9200 将容器的9200端口映射到主机的9200端口;
--name elasticsearch 给当前启动的容器取名叫 elasticsearch
-v ~/Documents/DevApp/config/elasticsearch/data:/usr/share/elasticsearch/data 将数据文件夹挂载到主机;
-v ~/Documents/DevApp/config/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml 将配置文件挂载到主机;
-d 以后台方式运行(daemon)
-e ES_JAVA_OPS="-Xms256m -Xmx256m" 测试时限定内存小一点
- 查看ES启动状态 命令 :docker ps
- 访问elasticsearch 访问地址:http://127.0.0.1:9200/