爲何要安裝elasticsearch-head?css
ElasticSearch-head是一個H5編寫的ElasticSearch集羣操做和初級管理工具,能夠對集羣進行傻瓜式操做。html
下載node
elasticsearch-head 在這裏下載: https://github.com/mobz/elasticsearch-headlinux
法1:從官網手動下到本地,文件下載到這個目錄:/home/liusiyi/下載/elasticsearch-head-master.zipgit
法2:命令下載:wget https://github.com/mobz/elasticsearch-head/archive/master.zipgithub
解壓web
unzip master.zip 或 unzip elasticsearch-head-master.zipexpress
由於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。npm
重命名json
解壓後的目錄名,放在用戶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成了綠色,開薰!