linux環境安裝es插件elasticsearch-head


為什么要安裝elasticsearch-head?

ElasticSearch-head是一個H5編寫的ElasticSearch集群操作和初級管理工具,可以對集群進行傻瓜式操作。

 

下載

elasticsearch-head 在這里下載: https://github.com/mobz/elasticsearch-head

法1:從官網手動下到本地,文件下載到這個目錄:/home/liusiyi/下載/elasticsearch-head-master.zip

法2:命令下載:wget https://github.com/mobz/elasticsearch-head/archive/master.zip

 

解壓

unzip master.zip 或 unzip elasticsearch-head-master.zip

因為github強烈反對把elasticsearch-head當作插件來運行,(原話:Running as a plugin of Elasticsearch(deprecated), for Elasticsearch 5.x, 6.x, and 7.x: site plugins are not supported. Run as a standalone server)。我目前機器上是elasticsearch-6.3.2,所以我不會把它當作ES的插件來安裝或運行;還句話說,即不放在elasticsearch目錄或它的plugins/modules目錄下,也不使用elasticsearch-plugin install。

 

重命名

解壓后的目錄名,放在用戶es的home目錄下

mv elasticsearch-head-master /home/es

 

安裝nodeJS

為后面的安裝作准備,參考https://www.cnblogs.com/happyliusiyi/p/11684019.html

 

安裝grunt

grunt是基於Node.js的項目構建工具,可以進行打包壓縮、測試、執行等等工作,elasticsearch-head插件就是通過grunt啟動的。

[root@bogon elasticsearch-head-master]# npm install grunt --save-dev
npm WARN deprecated coffee-script@1.10.0: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
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

+ grunt@1.0.1
added 94 packages from 65 contributors and audited 162 packages in 13.303s
found 9 vulnerabilities (2 low, 2 moderate, 5 high)
  run `npm audit fix` to fix them, or `npm audit` for details

這里用-save-dev的原因是grunt是用於開發和測試中需要用到,項目開發完成后,執行時不依賴於它。

關於npm install/ npm install --save/ npm install --save-dev的區別,我覺得這兩篇比較中肯:

https://www.cnblogs.com/merray/p/7766172.html

https://baijiahao.baidu.com/s?id=1637471064122396966&wfr=spider&for=pc

 

安裝 npm i

[root@bogon elasticsearch-head-master]# npm install
npm WARN deprecated phantomjs-prebuilt@2.1.16: this package is now deprecated
npm WARN deprecated http2@3.3.7: Use the built-in module in node 9.0.0 or newer, instead
npm WARN deprecated json3@3.3.2: Please use the native JSON object instead of JSON 3
npm WARN deprecated json3@3.2.6: Please use the native JSON object instead of JSON 3

> phantomjs-prebuilt@2.1.16 install /home/es/elasticsearch-head-master/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...
  [========================================] 100%
Received 22866K total.
Extracting tar contents (via spawned process)
Removing /home/es/elasticsearch-head-master/node_modules/phantomjs-prebuilt/lib/phantom
Copying extracted folder /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1571214793258/phantomjs-2.1.1-linux-x86_64 -> /home/es/elasticsearch-head-master/node_modules/phantomjs-prebuilt/lib/phantom
chmod failed: phantomjs was not successfully copied to /home/es/elasticsearch-head-master/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs
npm WARN elasticsearch-head@0.0.0 license should be a valid SPDX license expression
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! phantomjs-prebuilt@2.1.16 install: `node install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the phantomjs-prebuilt@2.1.16 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-10-16T08_33_15_264Z-debug.log

這里copy phantomjs的時候報錯了,可能是因為權限問題,把目標路徑的權限改為root,然后手動copy過去即可。

 

安裝 grunt-cli

Grunt-cli 只是一個命令行工具,用來執行,而不是 Grunt 這個工具本身

[root@bogon elasticsearch-head-master]# npm install -g grunt-cli
/usr/local/nodejs/bin/grunt -> /usr/local/nodejs/lib/node_modules/grunt-cli/bin/grunt
+ grunt-cli@1.3.2
added 150 packages from 121 contributors in 6.181s

 

檢測,安裝成功!

[root@bogon elasticsearch-head-master]# grunt -version
grunt-cli v1.3.2
grunt v1.0.1

 

修改配置文件1

修改elasticsearch-head安裝目錄下的配置文件Gruntfile.js ,增加hostname屬性,設置為*,注意冒號后面要空一格!

 

修改配置文件2

修改elasticsearch-head安裝目錄下的配置文件_site/app.js,這個文件挺長。

文件有一段代碼,默認用"http://localhost:9200",我們需要做的是,先確認這個http是否和Elasticsearch目錄下的配置文件config/elasticsearch.yml 中的network.host 的值是否一致?如果人家是具體的IP地址,就把elasticsearch-head-master/_site/app.js文件里面的這行做個替換;如果人家沒有任何設置,就不需要替換,默認用localhost。

#備份一下app.js文件是有必要的
[es@bogon ~]$ cp -a elasticsearch-head-master/_site/app.js{,_$(date +%F)}

#查看備份文件
[es@bogon ~]$ ls elasticsearch-head-master/_site
app.css  app.js  app.js_2019-10-18  app.js_F%  background.js  base  fonts  i18n.js  index.html  lang  manifest.json  vendor.css  vendor.js


#把   this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200"; 
#改為  this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://192.168.1.101:9200"; #這里用我的ip來演示!

#在app.js文件中先找到需要被替換的行 [es@bogon ~]$ cat elasticsearch-head-master/_site/app.js | grep "this.base_uri = this.config.base_uri || this.prefs.get" this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200"; #替換 [es@bogon ~]$ sed -i 's/this\.base_uri = this\.config\.base_uri || this\.prefs\.get(\"app-base_uri\") || \"http:\/\/localhost:9200\"\;/this\.base_uri = this\.config\.base_uri || this\.prefs\.get(\"app-base_uri\") || \"http:\/\/192\.168\.89\.66:9200\"\;/g' elasticsearch-head-master/_site/app.js # 驗證一下,已改好 [es@bogon ~]$ cat elasticsearch-head-master/_site/app.js | grep "this.base_uri = this.config.base_uri || this.prefs.get" this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://192.168.89.66:9200";

 

啟動elasticsearch服務

切換到es用戶,進入elasticsearch的安裝目錄,執行bin/elasticsearch

在瀏覽器輸入 http://localhost:9200/_cluster/health?pretty ;如果elasticsearch目錄下的配置文件config/elasticsearch.yml 中的“network.host”已經設置了具體的ip地址,那么就需要用http://<具體的ip地址>:9200/_cluster/health?pretty ;原則就是讓插件的host和elasticsearch一一對應。

 

運行elasticsearch-head

#用es用戶,進入elasticsearch-head-master目錄
[es@bogon ~]$ cd elasticsearch-head-master

#啟動 - 前台運行
[es@bogon elasticsearch-head-master]$ grunt server
>> Local Npm module "grunt-contrib-jasmine" not found. Is it installed?

Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100

#或者啟動 - 后台運行
[es@bogon elasticsearch-head-master]$ grunt server &
#查看進程
[es@bogon elasticsearch-head-master]$ ps -ef |grep grunt
es       31898 29760  0 20:54 pts/0    00:00:00 grunt
es       32057 31986  0 20:58 pts/1    00:00:00 grep --color=auto grunt

 

通過web訪問插件

瀏覽器輸入 http://localhost:9100/ 或 http://<上面定義的ip>:910看到cluster health: not connected了嗎?集群不健康,需要在Elasticsearch中啟用CORS,在elasticsearch.yml添加兩行:

http.cors.enabled: true
http.cors.allow-origin: "*"

[es@bogon ~]$ vim elasticsearch-6.4.1/config/elasticsearch.yml

保存后重啟es服務

#重啟三步驟
#1 查找進程
[es@bogon ~]$ ps -af | grep elastic

#2 殺掉進程,填自己的進程號 [es
@bogon ~]$ kill -9 30306 30281

#后台啟動 [es@bogon ~]$ elasticsearch-6.4.1/bin/elasticsearch -d

 

 刷新頁面,cluster health成了綠色,開薰!

 


免責聲明!

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



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