一、簡介:
elasticsearch-head是一個用於瀏覽ElasticSearch集群並與其進行交互的Web項目
GitHub托管地址:https://github.com/mobz/elasticsearch-head
二、安裝
1、插件安裝(我這里以新版本為主):
從ElasticSearch5.x開始 不在支持 插件方式啟動 必須作為獨立服務器運行
對於Elasticsearch 2.x: sudo elasticsearch/bin/plugin install mobz/elasticsearch-head
對於Elasticsearch 1.x: sudo elasticsearch/bin/plugin -install mobz/elasticsearch-head/1.x
對於Elasticsearch 0.x: sudo elasticsearch/bin/plugin -install mobz/elasticsearch-head/0.9
2、瀏覽器插件(Chrome擴展程序)
地址:https://chrome.google.com/webstore/detail/elasticsearch-head/ffmkiejjmecolpfloofpjologoblkegm/
CSDN:點擊下載
下載后解壓 拖到瀏覽器完成安裝
如圖:
3、作為服務安裝在服務器
需要環境:Node.js
1>、安裝Node.js
[root@gameServer ~]# cd /usr/local/
[root@gameServer local]# wget https://nodejs.org/dist/v9.9.0/node-v9.9.0-linux-x64.tar.xz
--2018-06-09 08:24:13-- https://nodejs.org/dist/v9.9.0/node-v9.9.0-linux-x64.tar.xz
正在解析主機 nodejs.org... 104.20.22.46, 104.20.23.46, 2400:cb00:2048:1::6814:162e, ...
正在連接 nodejs.org|104.20.22.46|:443... 已連接。
已發出 HTTP 請求,正在等待回應... 200 OK
長度:11445048 (11M) [application/x-xz]
正在保存至: “node-v9.9.0-linux-x64.tar.xz”
100%[======================================================>] 11,445,048 1.15M/s in 11s
2018-06-09 08:24:33 (989 KB/s) - 已保存 “node-v9.9.0-linux-x64.tar.xz” [11445048/11445048])
[root@gameServer local]# tar -xf node-v9.9.0-linux-x64.tar.xz
[root@gameServer local]# mv node-v9.9.0-linux-x64 nodeJs
[root@gameServer local]# vim /etc/profile.d/dev.sh
# Set Dev Path
JAVA_HOME=/usr/local/java/jdk1.8.0_161/
export JAVA_HOME
export NODE_HOME=/usr/local/nodeJs
export PATH=$PATH:$JAVA_HOME/bin:$NODE_HOME/bin
[root@gameServer local]# source /etc/profile.d/dev.sh
[root@gameServer local]# node -v
v9.9.0
2>、下載Head插件
[root@gameServer local]# su payment
[payment@gameServer local]$ cd ~/elasticSearch/
[payment@gameServer elasticSearch]$ ll
總用量 28388
drwxr-xr-x. 9 payment payment 4096 6月 6 10:21 elasticsearch-6.2.4-1
drwxr-xr-x. 9 payment payment 4096 6月 6 14:13 elasticsearch-6.2.4-2
drwxr-xr-x. 9 payment payment 4096 6月 6 14:13 elasticsearch-6.2.4-3
-rw-rw-r--. 1 payment payment 29056810 5月 15 12:56 elasticsearch-6.2.4.tar.gz
[payment@gameServer elasticSearch]$ git clone git://github.com/mobz/elasticsearch-head.git
Initialized empty Git repository in /home/payment/elasticSearch/elasticsearch-head/.git/
remote: Counting objects: 4224, done.
remote: Total 4224 (delta 0), reused 0 (delta 0), pack-reused 4224
Receiving objects: 100% (4224/4224), 2.16 MiB | 875 KiB/s, done.
Resolving deltas: 100% (2329/2329), done.
[payment@gameServer elasticSearch]$
3>、編譯啟動
別的博客有推薦
#使用淘寶的鏡像庫進行下載,速度很快
npm config set registry https://registry.npm.taobao.org
我這里不建議使用:我在使用過程中、出現了找不到包
我用的官網的
npm config set registry http://registry.cnpmjs.org
[payment@gameServer elasticsearch-head]$ npm config set registry http://registry.cnpmjs.org
[payment@gameServer elasticsearch-head]$
[payment@gameServer elasticsearch-head]$ npm install
npm WARN deprecated http2@3.3.7: Use the built-in module in node 9.0.0 or newer, instead
npm WARN deprecated coffee-script@1.10.0: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
> phantomjs-prebuilt@2.1.16 install /home/payment/elasticSearch/elasticsearch-head/node_modules/phantomjs-prebuilt
> node install.js
PhantomJS not found on PATH
Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-linux-x86_64.tar.bz2
Saving to /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
Receiving...
[=======================================-] 98%
Received 22866K total.
Extracting tar contents (via spawned process)
Removing /home/payment/elasticSearch/elasticsearch-head/node_modules/phantomjs-prebuilt/lib/phantom
Copying extracted folder /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1528505043238/phantomjs-2.1.1-linux-x86_64 -> /home/payment/elasticSearch/elasticsearch-head/node_modules/phantomjs-prebuilt/lib/phantom
Writing location.js file
Done. Phantomjs binary available at /home/payment/elasticSearch/elasticsearch-head/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN elasticsearch-head@0.0.0 license should be a valid SPDX license expression
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
added 382 packages in 44.016s
[payment@gameServer elasticsearch-head]$
[payment@gameServer elasticsearch-head]$ npm run start
> elasticsearch-head@0.0.0 start /home/payment/elasticSearch/elasticsearch-head
> grunt server
(node:9942) ExperimentalWarning: The http2 module is an experimental API.
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100
修改配置:並且后台啟動
[payment@gameServer elasticsearch-head]$ pwd
/home/payment/elasticSearch/elasticsearch-head
[payment@gameServer elasticsearch-head]$ vim Gruntfile.js
# 找到並修改如下配置
connect: {
server: {
options: {
port: 9100,
base: '.',
keepalive: true,
hostname: '*'
}
}
}
[payment@gameServer elasticsearch-head]$ vim _site/app.js
# 找到如下配置並修改:
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://172.17.63.15:9200";
[payment@gameServer elasticsearch-head]$ npm run start &
三、ElasticSeatch修改配置(已經配置的忽略此步)
連接到elasticsearch
默認情況下,elasticsearch會在彈性搜索頭連接的端口9200上公開一個http rest API。
在elasticsearch中啟用CORS
當不作為elasticsearch的插件運行時,您必須在elasticsearch中啟用CORS,否則您的瀏覽器將拒絕跨域。
在elasticsearch配置中;
加 http.cors.enabled: true
您還必須設置,http.cors.allow-origin因為默認情況下不允許跨域。http.cors.allow-origin: "*" 是允許配置的,但由於這樣配置的任何地方都可以訪問,所以有安全風險。
我在集群安裝的時候已經配好了、如果你剛配置、需要重啟ElasticSearch服務
http.cors.enabled: true
http.cors.allow-origin: "*"
四、測試head插件(選擇你對應的安裝方式)
1、測試瀏覽器插件
點擊插件按鈕進入頁面
修改鏈接地址:鏈接集群 你可以看到節點信息 以及狀態
2、測試服務安裝的插件
進入:http://ip地址:9100(如圖)
到這里 ElasticSearch Head插件就徹底安裝OK了
