安装
相关文档:
https://hub.docker.com/_/elasticsearch?tab=description&page=1&name=6.4
https://github.com/mobz/elasticsearch-head
- 首先拉镜像,推荐使用阿里云的镜像加速,毕竟不是都有vpn,执行 docker pull elasticsearch:6.4.0,我这儿使用的是6.4.0,按需可修改。
dailong-MacBook-Pro:~ dailong$ docker pull elasticsearch:6.4.0
6.4.0: Pulling from library/elasticsearch
256b176beaff: Pull complete
6cb472d8b34a: Pull complete
3a4f4d86c1c1: Pull complete
d185a64a7692: Pull complete
bc4d63245d6d: Pull complete
c8e97292a30a: Pull complete
c1c1a056e791: Pull complete
69b6c77c3236: Pull complete
Digest: sha256:96345f6d73c0d615ddf8b9683848d625f211efacfe3b5b8765debbd1eebc5663
Status: Downloaded newer image for elasticsearch:6.4.0
docker.io/library/elasticsearch:6.4.0
- 查看镜像:
dailong-MacBook-Pro:~ dailong$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
elasticsearch 6.4.0 1ac676545731 16 months ago 791MB
- 运行镜像:需要注意用程序连接 需要暴露9300端口,否则程序会报连接失败
dailong-MacBook-Pro:~ dailong$ docker run -d -p 9200:9200 -p 9300:9300 --name="elasticsearch" elasticsearch:6.4.0
7fcb25eb80fd538df74d2aaad9059fd72d9c9a6eb416fc7a347fa647b80c4aa2
- 查看运行镜像:
dailong-MacBook-Pro:~ dailong$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7fcb25eb80fd elasticsearch:6.4.0 "/usr/local/bin/dock…" 7 seconds ago Up 6 seconds 0.0.0.0:9200->9200/tcp, 9300/tcp elasticsearch
dailong-MacBook-Pro:~ dailong$ cd /work/elasticsearch
安装head插件,主要是为了方便调试
- 拉取镜像:
dailong-MacBook-Pro:elasticsearch dailong$ docker pull mobz/elasticsearch-head:5
5: Pulling from mobz/elasticsearch-head
75a822cd7888: Pull complete
57de64c72267: Pull complete
4306be1e8943: Pull complete
871436ab7225: Pull complete
0110c26a367a: Pull complete
1f04fe713f1b: Pull complete
723bac39028e: Pull complete
7d8cb47f1c60: Pull complete
7328dcf65c42: Pull complete
b451f2ccfb9a: Pull complete
304d5c28a4cf: Pull complete
4cf804850db1: Pull complete
Digest: sha256:55a3c82dd4ba776e304b09308411edd85de0dc9719f9d97a2f33baa320223f34
Status: Downloaded newer image for mobz/elasticsearch-head:5
docker.io/mobz/elasticsearch-head:5
- 创建容器:
dailong-MacBook-Pro:elasticsearch dailong$ docker create --name elasticsearch-head -p 9100:9100 mobz/elasticsearch-head:5
e0b064466f206c159eee458c35546dd4e2031e369cafea6a59848915f93eeef5
- 启动容器:
dailong-MacBook-Pro:elasticsearch dailong$ docker start elasticsearch-head
elasticsearch-head
-
查看head http://localhost:9100/
问题
集群未连接
如上图显示,集群未连接,按照网上说的有跨域问题,需进入docker镜像,修改docker中elasticsearch的elasticsearch.yml文件。
在文件最后加上
http.cors.enabled: true
http.cors.allow-origin: "*"
如下
dailong-MacBook-Pro:elasticsearch dailong$ docker exec -it elasticsearch /bin/bash
[root@7fcb25eb80fd elasticsearch]# vi config/elasticsearch.yml
[root@7fcb25eb80fd elasticsearch]# cat config/elasticsearch.yml
cluster.name: "docker-cluster"
network.host: 0.0.0.0
# minimum_master_nodes need to be explicitly set when bound on a public IP
# set to 1 to allow single node clusters
# Details: https://github.com/elastic/elasticsearch/pull/17288
discovery.zen.minimum_master_nodes: 1
http.cors.enabled: true
http.cors.allow-origin: "*"
[root@7fcb25eb80fd elasticsearch]# exit
exit
退出镜像,并重启服务:
dailong-MacBook-Pro:elasticsearch dailong$ docker restart elasticsearch
elasticsearch
dailong-MacBook-Pro:elasticsearch dailong$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e0b064466f20 mobz/elasticsearch-head:5 "/bin/sh -c 'grunt s…" 12 minutes ago Up 11 minutes 0.0.0.0:9100->9100/tcp elasticsearch-head
7fcb25eb80fd elasticsearch:6.4.0 "/usr/local/bin/dock…" About an hour ago Up 7 seconds 0.0.0.0:9200->9200/tcp, 9300/tcp elasticsearch
查看结果
数据浏览 f12后台错误
参考连接:https://blog.csdn.net/A_Story_Donkey/article/details/84135475
docker exec -it elasticsearch-head /bin/bash #进入es_head插件安装目录终端
head镜像无法使用vim,需要做一下操作:
apt update
apt-get install -y vim
修改vendor.js (/usr/src/app/_site/vendor.js),然后退出,重启
1. 6886行 /contentType: "application/x-www-form-urlencoded
改成 contentType: "application/json;charset=UTF-8"
2. 7574行 var inspectData = s.contentType === "application/x-www-form-urlencoded" &&
改成 var inspectData = s.contentType === "application/json;charset=UTF-8" &&
docker restart elasticsearch-head
效果: