1.下载镜像
docker pull elasticsearch:7.13.2
2. 创建目录(代理文件用)
mkdir -p /www/elasticsearch/config
mkdir -p /www/elasticsearch/data
mkdir -p /www/elasticsearch/plugins
3. 写入配置文件(跨域)
vi /www/elasticsearch/config/elasticsearch.yml
http.host: 0.0.0.0
http.cors.enabled: true
http.cors.allow-origin: '*'
3.赋权
chmod 777 /www/elasticsearch/data
chmod 777 /www/elasticsearch/plugins
chmod 777 /www/elasticsearch/config/elasticsearch.yml
docker run --privileged=true --restart=always --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms1g -Xmx2g" -v /www/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /www/elasticsearch/data:/usr/share/elasticsearch/data -v /www/elasticsearch/plugins:/usr/share/elasticsearch/plugins -d elasticsearch:7.13.2
# 其中elasticsearch.yml是挂载的配置文件
# data是挂载的数据,
# plugins是es的插件,如ik,
# 设置为单节点
-e "discovery.type=single-node"
# 指定运行最小和最大运行内存
-e ES_JAVA_OPTS="-Xms1g -Xmx2g"
--net=randeng_network --ip 192.168.1.62 #加入randeng_network,并使用192.168.1.62
--restart=always # 开机启动
--privileged=true # 特权模式
6.下载elasticsearch-head 镜像
docker pull mobz/elasticsearch-head:5
7.启动elasticsearch-head 镜像
docker run -d --name elasticsearch-head -p 9100:9100 mobz/elasticsearch-head:5
8.更改请求headers的contentType
mkdir -p /opt/docker/es/es-head
docker cp elasticsearch-head:/usr/src/app/_site/vendor.js /opt/docker/es/es-head/
cd /opt/docker/es/es-head/
contentType: “application/x-www-form-urlencoded”
改成 contentType: “application/json;charset=UTF-8”
var inspectData = s.contentType === “application/x-www-form-urlencoded”
改成 var inspectData = s.contentType === “application/json;charset=UTF-8”
也可以用shell 命令:sudo sed -i "s#application/x-www-form-urlencoded#application/json;charset=UTF-8#g" vendor.js
docker cp /opt/docker/es/es-head/vendor.js elasticsearch-head:/usr/src/app/_site
9.重启elasticsearch-head
docker restart elasticsearch-head
10.查看elasticsearch-head页面,并且成功添加索引
http://127.0.0.1:9100/