Elasticsearch5.x Head插件安裝


在5.0版本中不支持直接安裝head插件,需要啟動一個服務。

由於head插件本質上還是一個nodejs的工程,因此需要安裝node,使用npm來安裝依賴的包。(npm可以理解為maven)

1、安裝Node.js

官網nodejs,https://nodejs.org/en/download/

wget https://nodejs.org/dist/v6.10.2/node-v6.10.2-linux-x64.tar.xz
     
xz –d node-v6.10.2-linux-x64.tar.xz
tar xvf node-v6.10.2-linux-x64.tar
mv node-v6.10.2-linux-x64 /usr/local/node

vim /etc/profile
export NODE_HOME=/usr/local/node
export PATH=$PATH:$NODE_HOME/bin

source /etc/profile

 
# node –v
v6.10.2

# npm –v
3.10.10

說明:前面講了,npm相當於是maven,但npm究竟在哪?其實npm已經在Node.js安裝的時候順帶裝好了。

2、下載插件包

如果找不到git,請先安裝:

yum install –y git
git clone https://github.com/mobz/elasticsearch-head.git

3、安裝grunt

cd elasticsearch-head
npm install -g grunt --registry=https://registry.npm.taobao.org

4、安裝Head插件

npm install

在elasticsearch-head目錄下node_modules/grunt下如果沒有grunt二進制程序,需要執行:

cd elasticsearch-head
npm install grunt --save

5、修改配置

修改elasticsearch-head下Gruntfile.js文件,默認監聽在127.0.0.1下9200端口:

hostname: ‘192.168.33.50’,

修改 _site/app.js

修改http://localhost:9200字段到本機ES端口與IP:

21行:http://192.168.33.50:9200

6、修改Elasticsearch配置

修改elasticsearch.yml文件加入以下內容:

# 是否支持跨域
http.cors.enabled: true

# *表示支持所有域名
http.cors.allow-origin: "*"

7、啟動服務

/elasticsearch-head/node_modules/grunt/bin/grunt server (后台運行 + &)

瀏覽器訪問 http://192.168.33.50:9100/

附:

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM