1.拉取ES镜像 本人安装的是7.4.2 可根据自己实际需求安装 命令:
sudo docker pull elasticsearch:7.4.2
2.创建docker容器挂在的目录
mkdir -p /mydata/elasticsearch/config/
mkdir -p /mydata/elasticsearch/data/
echo “http.host: 0.0.0.0”>>/mydata/elasticsearch/config/elasticsearch.yml
注意:chmod -R 777 /mydata/elasticsearch 要有访问权限
3.创建实例并启动ES
sudo docker run --name elasticsearch -p 9200:9200 -p 9300:9300
-e ES_JAVA_OPS=“-Xms256m -Xmx256m”
-v /mydata/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
-v /mydata/elasticsearch/data:/usr/share/elasticsearch/data
-v /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins
-d elasticsearch:7.4.2
参数说明:
-p 9200:9200 将容器的9200端口映射到主机的9200端口;
–name elasticsearch 给当前启动的容器取名叫 elasticsearch
-v /mydata/elasticsearch/data:/usr/share/elasticsearch/data 将数据文件夹挂载到主机;
-v /mydata/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml 将配置文件挂载到主机;
-d 以后台方式运行(daemon)
-e ES_JAVA_OPS=“-Xms256m -Xmx256m” 测试时限定内存小一点
4.查看ES启动状态 命令 :docker ps
5.访问elasticsearch 注意关闭防火墙 访问地址:http://192.168.91.37:9200/
附常用命令:
docker ps 查看是否启动
docker logs elasticsearch 启动日志查询
docker restart elasticsearch 重启
docker exec -it elasticsearch bash 进入