一、查找Elasticsearch镜像
[root@staging ~]# docker search elasticsearch
二、拉取Elasticsearch镜像
[root@staging ~]# docker pull elasticsearch:7.14.2
三、编写配置文件
[root@staging ~]# mkdir -p /data2/elasticsearch/config
[root@staging config]# vim elasticsearch.yml
cluster.name: "docker-cluster"
network.host: 0.0.0.0
http.cors.enabled: true
http.cors.allow-origin: "*"
[root@staging config]# chmod -R 777 /data2/elasticsearch/
四、运行Elasticsearch
[root@staging ~]# docker run \
-itd \
-p 9200:9200 \
-p 9300:9300 \
-v /data2/elasticsearch/data:/usr/share/elasticsearch/data \
-v /data2/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /data2/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-v /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime \
-e discovery.type=single-node \
-e ES_JAVA_OPTS="-Xms64m -Xmx512m" \
--restart always \
--privileged=true \
--name es \
elasticsearch:7.14.2
五、验证Elasticsearch容器
[root@staging config]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7e1f75c1dd67 elasticsearch:7.14.2 "/bin/tini -- /usr/l…" 7 seconds ago Up 3 seconds 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp es
六、浏览器测试访问
输入IP+Port,本机192.168.2.18:9200,输入正确的用户名和修改过后的密码即可正常登陆。
七、安装head插件
#1.拉取镜像
[root@staging ~]# docker pull mobz/elasticsearch-head:5
#2.启动es-head容器
[root@staging ~]# docker run \
-itd \
-p 9100:9100 \
-v /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime \
--restart always \
--privileged=true \
--name es_head
mobz/elasticsearch-head:5
八、浏览器访问
浏览器访问ip:9100,连接es填入http://192.168.2.18:9200点击连接看到状态为绿色表示正常。