1. 程式人生 > >ubuntu安裝elasticsearch及head外掛

ubuntu安裝elasticsearch及head外掛

1.安裝elasticsearch,參考http://www.cnblogs.com/hanyinglong/p/5409003.html就可以了

簡單描述下:

mkdir -p /usr/local/kencery/elasticsearch
groupadd elasticsearch
useradd -d /usr/local/kencery/elasticsearch -g elasticsearch -p elasticsearch elasticsearch

然後將tar包解壓到elasticsearch目錄下就可以了,我下載的版本是elasticsearch-6.2.4.tar.gz

啟動時直接在bin目錄下執行:./elasticsearch

有兩個問題注意下,一是不要用root使用者執行,二是有可能會遇到錯誤:

[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

參考https://blog.csdn.net/jiankunking/article/details/65448030修改下/etc/sysctl.conf,記得改下elasticsearch.yml中的network.host以及埠配置,重啟後就可以訪問了:http://192.168.141.13:9200/

name    "4tlNeHN
" cluster_name "elasticsearch" cluster_uuid "BYwLfhswS8O2y-WYXAKUsA" version number "6.2.4" build_hash "ccec39f" build_date "2018-04-12T20:37:28.497551Z" build_snapshot false lucene_version "7.2.1" minimum_wire_compatibility_version "5.6.0" minimum_index_compatibility_version
"5.0.0" tagline "You Know, for Search"

2.安裝elasticsearch-head,這裡敲下黑板,真的很麻煩,如果不瞭解,花費大半天時間也是很正常的,這裡就直接說下最後成功的辦法

2.1 elasticsearch 5.x之後不支援直接plugin安裝head外掛,而是將head作為一個獨立的服務安裝的,首先需要安裝依賴的node,npm,grunt,參考https://blog.csdn.net/hard_boy/article/details/79565068,我是以root執行的,稍微有點不同:

apt-get install npm
apt-get install nodejs-legacy
npm install -g grunt
npm install -g grunt-cli

下載elasticsearch-head,我解壓到目錄/usr/local/kencery/elasticsearch-head,將目錄使用者改為elasticsearch

2.2 然後修改配置

2.2.1 修改head的連線地址 elasticsearch-head/_site/app.js

this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200";  

將localhost改為自己的ip

2.2.2 修改伺服器的監聽地址elasticsearch-head/Gruntfile.js

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

options中新增 hostname: '*'

2.2.3 修改elasticseach的配置檔案elasticsearch.yml, 修改對應的ip以及跨域的設定,新增:

http.cors.enabled: true 

http.cors.allow-origin: "*"  

2.3 在elasticsearch-head下執行: grunt server

2.3.1 但是會出現錯誤提示(當時命令敲的npm start,應該是一樣的):

[email protected]:/usr/local/kencery/elasticsearch-head# npm start

> elasticsearch-head@0.0.0 start /usr/local/kencery/elasticsearch-head
> grunt server

grunt-cli: The grunt command line interface (v1.2.0)

Fatal error: Unable to find local grunt.

If you're seeing this message, grunt hasn't been installed locally to
your project. For more information about installing and configuring grunt,
please see the Getting Started guide:

http://gruntjs.com/getting-started

npm ERR! Linux 4.4.0-62-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "start"
npm ERR! node v4.2.6
npm ERR! npm  v3.5.2
npm ERR! code ELIFECYCLE
npm ERR! elasticsearch-head@0.0.0 start: `grunt server`
npm ERR! Exit status 99
npm ERR! 
npm ERR! Failed at the elasticsearch-head@0.0.0 start script 'grunt server'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the elasticsearch-head package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     grunt server
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs elasticsearch-head
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls elasticsearch-head
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /usr/local/kencery/elasticsearch-head/npm-debug.log

看提示大概有提到版本不是最新的問題,所以就抱著試一試的心態去升級npm以及node

參考https://www.cnblogs.com/ae6623/p/6242423.html

npm cache clean -f
npm install -g n
n stable
npm install [email protected] -g

再檢視下版本,會看到

[email protected]:~$ node -v
v10.4.0
[email protected]:~$ npm -v
6.1.0

2.3.2 但是執行grunt server依然報錯:

grunt hasn't been installed locally to your project

參考https://segmentfault.com/q/1010000004172559/a-1020000004193932,執行:

npm install grunt --save-dev

2.3.3 再次執行,依然報錯:

[email protected]:/usr/local/kencery/elasticsearch-head$ grunt server
>> Local Npm module "grunt-contrib-clean" not found. Is it installed?
>> Local Npm module "grunt-contrib-concat" not found. Is it installed?
>> Local Npm module "grunt-contrib-watch" not found. Is it installed?
>> Local Npm module "grunt-contrib-connect" not found. Is it installed?
>> Local Npm module "grunt-contrib-copy" not found. Is it installed?
>> Local Npm module "grunt-contrib-jasmine" not found. Is it installed?
Warning: Task "connect:server" not found. Use --force to continue.

然後我乾脆把有關grunt的都裝了一遍最新的:

npm install [email protected]
npm install grunt-[email protected]
npm install grunt-contrib-[email protected]
npm install grunt-contrib-[email protected]
npm install grunt-contrib-[email protected]
npm install grunt-contrib-[email protected]
npm install grunt-contrib-[email protected]
npm install grunt-contrib-[email protected]
npm install [email protected]

2.3.4 最後grunt server終於可以啟動了:

[email protected]:/usr/local/kencery/elasticsearch-head$ grunt server
(node:1527) ExperimentalWarning: The http2 module is an experimental API.
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100

可以看到elasticsearch服務的埠是9200,head外掛服務的埠是9100,我們訪問head然後head再訪問的elasticsearch。

可以新建索引試一下:

狀態yellow還是有一些問題,並不影響使用,對於ES也只是剛接觸,並沒多少了解,後續使用過程中遇到問題再作紀錄。

 

參考文章:

1.http://www.cnblogs.com/hanyinglong/p/5409003.html

2.https://blog.csdn.net/jiankunking/article/details/65448030

3.https://blog.csdn.net/hard_boy/article/details/79565068

4.https://www.cnblogs.com/ae6623/p/6242423.html

5.https://segmentfault.com/q/1010000004172559/a-1020000004193932