1. 程式人生 > >Elasticsearch 5.3.x 使用 Head 插件

Elasticsearch 5.3.x 使用 Head 插件

elk

0、前言

時光荏苒,ES轉眼間就從2.X跳到了5.X。。。

憶往昔崢嶸歲月,奈何ES社區太活躍,版本跳的比房價還快啊。。。

話說回來,需要部署一套Elasticsearch 5.2.1 即本月最新推出的ES新力作,發現很多用法已經不一樣了。。。

本次首先說Head插件的安裝:

1、安裝插件head

1234567891011# 去github上下載headgit clone git://github.com/mobz/elasticsearch-head.git# 由於head基於nodejs所以安裝它yum -y install nodejs npmnpm install grunt-clinpm install
gruntgrunt -version# 修改配置文件cd elasticsearch-headvim _site/app.js# 修改 『http://localhost:9200』字段到本機ES端口與IP

2、啟動head

123cd elasticsearch-headgrunt server# 打開瀏覽器 http://localhost:9100

3、出現問題

head主控頁面是可以顯示的,但是顯示連接失敗

“集群健康值: 未連接”

4、解決方案

修改elasticsearch.yml文件

1234vim $ES_HOME$/config/elasticsearch.yml# 增加如下字段http.cors.enabled:
truehttp.cors.allow-origin: "*"

重啟es和head即可


5、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,那麽會返回給客戶端。


參考博文:http://www.cnblogs.com/zklidd/p/6433123.html


Elasticsearch 5.3.x 使用 Head 插件