0、前言
時光荏苒,ES轉眼間就從2.X跳到了5.X。。。
憶往昔崢嶸歲月,奈何ES社區太活躍,版本跳的比房價還快啊。。。
話說回來,需要部署一套Elasticsearch 5.2.1 即本月最新推出的ES新力作,發現很多用法已經不一樣了。。。
本次首先說Head插件的安裝:
1、安裝插件head
# 去github上下載head git clone git://github.com/mobz/elasticsearch-head.git # 由於head基於nodejs所以安裝它 yum -y install nodejs npm npm install grunt-cli npm install grunt grunt -version # 修改配置文件 cd elasticsearch-head vim _site/app.js # 修改 『http://localhost:9200』字段到本機ES端口與IP
2、啟動head
cd elasticsearch-head grunt server # 打開瀏覽器 http://localhost:9100
3、出現問題
head主控頁面是可以顯示的,但是顯示連接失敗
“集群健康值: 未連接”
4、解決方案
修改elasticsearch.yml文件
vim $ES_HOME$/config/elasticsearch.yml # 增加如下字段 http.cors.enabled: true http.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,那么會返回給客戶端。 |