elasticsearch5安裝


環境:

centos7

es 5.4.3

 

es安裝

一.下載

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.4.3.zip

解壓。

 

二.配置

 

cd config

vi elasticsearch.yml

修改配置項

 

cluster.name 可不配置

node.name 如果是單機版可不配置,如果是集群,則不同節點node.name應該不同

path.data 數據存儲目錄

path.logs 日志目錄

network.host 節點IP

http.port 節點端口

discovery.zen.ping.unicast.hosts: ["192.168.145.129"]  如果是集群,將當前節點以外的所有節點的IP加入此配置項

discovery.zen.minimum_master_nodes 配置當前集群中最少的主節點數,如果是單機版,此節為1,不然啟動報錯,如果是集群,最好配置多個,具體個數酌情考慮

 

三.啟動

 

由於ElasticSearch可以接收用戶輸入的腳本並且執行,為了系統安全考慮,不能以root用戶啟動。

所以先建立一個用戶。

adduser es

passwd es

同時將elasticsearch-5.4.3文件夾的權限賦給es用戶

chown -R username 目錄

切換到es用戶

su es

 啟動命令

./bin/elasticsearch

 

這個時候往往會報錯

ERROR: [2] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

解決方法

vim /etc/security/limits.conf

...
elasticsearch/當前用戶名 hard nofile 65536 # 針對 max file descriptors
elasticsearch/當前用戶名 soft nproc 2048 # 針對 max number of threads

 

vim /etc/sysctl.conf
...
vm.max_map_count=262144 # 針對 max virtual memory areas

 

重啟服務器。再次執行./elasticsearch,訪問http://192.168.145.133:9200/看到以下內容啟動成功。

 下面配置各種插件。

head插件

一.安裝node.js

因為elasticsearch的head插件是個js項目,所以需要安裝node.js。

 

選擇一個node.js版本

# 4.x版本
curl --silent --location https://rpm.nodesource.com/setup_4.x | bash -
# 5.x版本
curl --silent --location https://rpm.nodesource.com/setup_5.x | bash -

然后執行

yum install -y nodejs

二.安裝git

yum install git

三.下載

  • git clone git://github.com/mobz/elasticsearch-head.git
  • cd elasticsearch-head
  • npm install
  • npm run start

 

訪問http://192.168.145.133:9100/

看到以下頁面

head連接成功,但顯示連接es未成功。

 

vi _site/app.js

修改 http://localhost:9200中的連接地址與端口

 

然后修改elasticsearch.yml配置文件,加入

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

 

中文分詞插件IK

一.下載

wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v5.4.3/elasticsearch-analysis-ik-5.4.3.zip

 解壓到elasticsearch集群的插件目錄下

unzip elasticsearch-analysis-ik-5.4.3.zip -d  elasticsearch-5.4.3/plugins/ik/

重啟elasticsearch。

 

二.驗證IK

首先創建一個索引

 

 在這個索引上對“我愛你中國”進行分詞

http://192.168.145.133:9200/test/_analyze?analyzer=ik_smart&text=%E6%88%91%E7%88%B1%E4%BD%A0%E4%B8%AD%E5%9B%BD

 分詞成功

{"tokens":[{"token":"我愛你","start_offset":0,"end_offset":3,"type":"CN_WORD","position":0},{"token":"中國","start_offset":3,"end_offset":5,"type":"CN_WORD","position":1}]}

 

sql插件

head插件當然非常強大,但是查詢太麻煩。使用sql插件可以直接使用sql語句查詢,學習成本大大降低。

 

一.下載

https://github.com/NLPchina/elasticsearch-sql/releases/download/5.4.1.0/es-sql-site-standalone.zip

 解壓

 

二.執行

npm install express --save

三.配置

在es集群的elasticsearch.yml的文件里加入

http.cors.allow-headers: "X-Requested-With, Content-Type, Content-Length,Authorization"

 四.下載包

將elasticsearch-sql所需要的jar包下載到elasticsearch的插件目錄下

/elasticsearch-plugin install https://github.com/NLPchina/elasticsearch-sql/releases/download/5.4.3.0/elasticsearch-sql-5.4.3.0.zip

五.啟動

node node-server.js

 

訪問http://192.168.145.133:8080/,在界面中填入連接的elasticsearch地址,就可以使用sql查詢了。

它將查詢結果和聚合結果剝離了,比如,只返回聚合結果,沒有查詢結果。並且having也沒有實現。所以,有一定的局限性。

 


免責聲明!

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



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