Elasticsearch 簡(jiǎn)介
Elasticsearch
是最近兩年異軍突起的一個(gè)兼有搜索引擎和NoSQL
數(shù)據(jù)庫(kù)功能的開(kāi)源系統(tǒng),基于Java/Lucene
構(gòu)建。最近研究了一下,感覺(jué)Elasticsearch
的架構(gòu)以及其開(kāi)源的生態(tài)構(gòu)建都有許多可借鑒之處,所以整理成文章分享下。本文的代碼以及架構(gòu)分析主要基于 Elasticsearch 2.X
最新穩(wěn)定版。
?Elasticsearch
看名字就能大概了解下它是一個(gè)彈性的搜索引擎。首先彈性隱含的意思是分布式,單機(jī)系統(tǒng)是沒(méi)法彈起來(lái)的,然后加上靈活的伸縮機(jī)制,就是這里的 Elastic
包含的意思。它的搜索存儲(chǔ)功能主要是 Lucene
提供的,Lucene
相當(dāng)于其存儲(chǔ)引擎,它在之上封裝了索引,查詢,以及分布式相關(guān)的接口。
安裝Elasticsearch
tar zxvf elasticsearch-5.2.0.tar.gz
mv elasticsearch-5.2.0 /usr/local/elasticsearch
cd config
vim jvm.options #修改配置
-Xms4g
-Xmx4g
##-Xms2g
##-Xmx2g
cd bin
./elasticsearch #./elasticsearch -d 后端啟動(dòng)
Elasticsearch的坑
- root賬號(hào)運(yùn)行,會(huì)出現(xiàn)以下錯(cuò)誤:
can not run elasticsearch as root
#解決:創(chuàng)建elsearch用戶組及elsearch用戶
useradd elsearch
passwd
chown -R elsearch /usr/local/elasticsearch
- error2
ERROR: bootstrap checks failed
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
system call filters failed to install
#解決:
方法一:sysctl -w vm.max_map_count=262144
方法二:vim /etc/sysctl.conf 添加vm.max_map_count = 262144
#測(cè)試
sysctl -p
sysctl -a | grep
- error3
ERROR: bootstrap checks failed
system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
解決方案:
在elasticsearch.yml中配置bootstrap.system_call_filter為false,注意要在Memory下面:
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
4.error4
max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
解決方案:
修改/etc/security/limits.conf文件,添加或修改如下行:
hard nofile 65536
soft nofile 65536
5.error
maybe these locations are not writable or multiple nodes were started without increasing
#信息:當(dāng)前服務(wù)已啟動(dòng),解決辦法
netstat -anp|grep 9200
kill -9 進(jìn)程id
Elasticsearch 插件
-
Elasticsearch-head是elasticsearch的一個(gè)集群管理工具>直接裝在本地即可
#首先在elasticsearch.yml配置文件中加入一下內(nèi)容,然后重啟服務(wù)。
http.cors.enabled: true
http.cors.allow-origin: "*"
git clone https://github.com/mobz/elasticsearch-head
cd elasticsearch-head
npm install -g grunt-cli #裝grunt之前確保裝有node
npm install
grunt server#此處要配置grunt的環(huán)境變量或者·/usr/local/nodejs/bin/grunt server·
http://localhost:9100/