ElasticSearch6.2.3安裝Head插件


1、環境

Linux centos7

elasticsearch-head的zip包,github網址如下:https://github.com/mobz/elasticsearch-head

nodejs的linux對應位數下載:https://nodejs.org/en/download/

2、安裝nodejs

解壓后如下圖所示:

進入bin執行下面的三個可執行文件:

 

[root@mycentos bin]# ./node -v
[root@mycentos bin]# ./npm -v
[root@mycentos bin]# ./npx -v

 

執行./npm -v會報錯如下:

/usr/bin/env: node: 沒有那個文件或目錄

此時需要配置環境變量即可,修改/etc/profile,行尾追加如下命令:

[root@mycentos ~]# vim /etc/profile

export NODE_HOME=/opt/nodejs/node-v8.9.4-linux-x64/
export PATH=$PATH:$NODE_HOME/bin
export NODE_PATH=$NODE_HOME/lib/node_modules

#執行命令生效:

[root@mycentos ~]# source /etc/profile

3、安裝elasticsearch-head

進入到elasticsearch-head主目錄執行:

[elastic@mycentos elasticsearch-head-master]$   npm install

 

安裝過程中出現錯誤:

Please report this full log at https://github.com/Medium/phantomjs

npm ERR! Darwin 15.0.0

npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"

npm ERR! node v4.4.3

npm ERR! npm  v3.10.9

npm ERR! code ELIFECYCLE

npm ERR! phantomjs-prebuilt@2.1.14 install: `node install.js`

npm ERR! Exit status 1

npm ERR!

npm ERR! Failed at the phantomjs-prebuilt@2.1.14 install script 'node install.js

 

解決方案如下:

#忽略腳本繼續進行安裝
npm install phantomjs-prebuilt@2.1.14 --ignore-scripts

 

最終安裝成功!成功后當前目錄多了一個node_modules文件夾。

4、配置

       (1)配置Head主目錄下的Gruntfile.js,默認文件中是沒有hostname屬性的,我們需要手動添加:

connect: {
          server: {
                   options: {
                        port: 9100,
                        base: '.',
                        keepalive: true,
                        hostname: '*'
                    }
          }
  }

 

(2)配置elasticsearch 的啟動配置文件:

為什么需要修改配置文件:

head插件連接elasticsearch需要注意的點:

因為head插件是一個獨立進程,啟動后是一個獨立的服務器外加端口,比如我的虛擬機ip地址:http://192.168.0.111:9100/

而elasticsearch啟動后也是一個獨立的進程,ip地址:http://192.168.0.111:9200/

這樣兩個獨立進程,雖然服務器ip地址相同,但是端口不同,此時會發生跨域的情況。。

於是官方給出這樣一段話,我們在對elasticsearch啟動的時候追加兩個配置文件屬性即可防止跨域。

 

#在文件末尾添加即可

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

 

5、啟動Head插件

#切回到head的主目錄下,執行如下命令

[elastic@mycentos elasticsearch-head-master]$ npm run start

 

然后在瀏覽中打開:http://localhost:9100

安裝完畢!


免責聲明!

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



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