为elasticsearch安装 head插件

1.进入github下载elasticsearch-head

【elasticsearch】为elasticsearch安装elasticsearch-head插件。坑~~~_linux

 

2.使用​​wget​​命令下载master.zip

wget https://github.com/mobz/elasticsearch-head/archive/master.zip

3.使用​​unzip master.zip​​进行解压

unzip master.zip

【elasticsearch】为elasticsearch安装elasticsearch-head插件。坑~~~_跨域_02

 

4.进入 elasticsearch-head-master使用​​npm install​​进行相应的包下载

npm install

5.使用命令启动head

npm run start

elasticsearch与head存在跨域问题,所以需要有如下配置:

在elasticsearch的config/elasticsearch.yml文件的最后添加:

【elasticsearch】为elasticsearch安装elasticsearch-head插件。坑~~~_跨域_03

 

使用命令进行后台启动elasticsearch

./bin/elasticsearch -d

再开启head插件

【elasticsearch】为elasticsearch安装elasticsearch-head插件。坑~~~_跨域_04

 

关闭elasticsearch的后台启动

1.通过jps查看elasticsearch的端口

【elasticsearch】为elasticsearch安装elasticsearch-head插件。坑~~~_字段_05

 

2.通过kill -9 端口号 杀死进程

【elasticsearch】为elasticsearch安装elasticsearch-head插件。坑~~~_跨域_06

 

CORS是什么?

wiki上的解释是 Cross-origin resource sharing (CORS) is a mechanism that allows restricted resources ,即跨域访问。

这个字段默认为false,在Elasticsearch安装集群之外的一台机上用Sense、Head等监控插件访问Elasticsearch是不允许的。这个字段最早可以追溯到1.4.x版本,而非5.x特有。

具体这个http.cors.x字段还有哪些用途和用法,见下表:

http.cors.enabled

是否支持跨域,默认为false

http.cors.allow-origin

当设置允许跨域,默认为*,表示支持所有域名,如果我们只是允许某些网站能访问,那么可以使用正则表达式。比如只允许本地地址。 /https?:\/\/localhost(:[0-9]+)?/

http.cors.max-age

浏览器发送一个“预检”OPTIONS请求,以确定CORS设置。最大年龄定义多久的结果应该缓存。默认为1728000(20天)

http.cors.allow-methods

允许跨域的请求方式,默认OPTIONS,HEAD,GET,POST,PUT,DELETE

http.cors.allow-headers

跨域允许设置的头信息,默认为X-Requested-With,Content-Type,Content-Length

http.cors.allow-credentials

是否返回设置的跨域Access-Control-Allow-Credentials头,如果设置为true,那么会返回给客户端。