01 準(zhǔn)備工作及下載
1)創(chuàng)建一個(gè)es專門的用戶(必須)里覆,因?yàn)閑s不能用root用戶啟動(dòng)
useradd es -m
passwd <input es>
mkdir -p /usr/local/es/
chown -R es /usr/local/es/
2)切換到es用戶下莱睁,下載安裝包
su es
cd /usr/local/es
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.0.0.zip
unzip elasticsearch-6.0.0.zip
cd elasticsearch-6.0.0/
ls
bin config data lib LICENSE.txt logs modules nohup.out NOTICE.txt plugins README.textile
3)修改配置文件
cd config/
vim elasticsearch.yml
cluster.name: choxsu-es
#path.data: /path/to/data # 默認(rèn)即可
#path.logs: /path/to/logs # 默認(rèn)即可
network.host: 0.0.0.0
http.port: 9200
4)修改jvm內(nèi)存大小
vim config/jvm.options
-Xms256m
-Xmx256m
02 解決啟動(dòng)時(shí)報(bào)錯(cuò)
1) 啟動(dòng)命令
這里注意啦,這里是后臺(tái)啟動(dòng)霎箍,要發(fā)現(xiàn)錯(cuò)誤的話,去logs目錄下查看。
nohup ./bin/elasticsearch &
2)查看錯(cuò)誤信息
注意:ElasticSearch6.0.0必須jdk1.8以上支持稠项;所以請(qǐng)記得在/etc/profile文件中配置jdk環(huán)境變量
export JAVA_HOME=/opt/java/jdk1.8.0_161
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH
直接查看nohup輸出信息
tail -f nohup.out
或者查看日志輸出查看錯(cuò)誤信息
tail -f logs/choxsu-es.log
核心錯(cuò)誤信息
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2]: max number of threads [1024] for user [es] is too low, increase to at least [4096]
[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[4]: system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
3)解決辦法
1)max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
原因:無(wú)法創(chuàng)建本地文件問題,用戶最大可創(chuàng)建文件數(shù)太小
解決方案:切換到root用戶,編輯limits.conf配置文件鲜结, 添加類似如下內(nèi)容:
vi /etc/security/limits.conf
添加如下內(nèi)容:
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
備注:* 代表Linux所有用戶名稱(比如 hadoop)
需要保存展运、退出、重新登錄才可生效精刷。
2)max number of threads [1024] for user [es] likely too low, increase to at least [4096]
原因:無(wú)法創(chuàng)建本地線程問題,用戶最大可創(chuàng)建線程數(shù)太小
解決方案:切換到root用戶拗胜,進(jìn)入limits.d目錄下,修改90-nproc.conf 配置文件怒允。
vi /etc/security/limits.d/90-nproc.conf
找到如下內(nèi)容:
* soft nproc 1024
#修改為
* soft nproc 4096
3)max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
原因:最大虛擬內(nèi)存太小
root用戶執(zhí)行命令:
[root@localhost ~]# sysctl -w vm.max_map_count=262144
4)system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
原因:Centos6不支持SecComp埂软,而ES5.4.1默認(rèn)bootstrap.system_call_filter為true進(jìn)行檢測(cè),所以導(dǎo)致檢測(cè)失敗纫事,失敗后直接導(dǎo)致ES不能啟動(dòng)勘畔。
詳見 :https://github.com/elastic/elasticsearch/issues/22899
解決方法:在elasticsearch.yml中新增配置bootstrap.system_call_filter,設(shè)為false丽惶,注意要在Memory下面:
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
以上問題解決后炫七,es啟動(dòng)成功了,但又遇到了新的問題蚊夫,本地機(jī)器無(wú)法訪問虛擬機(jī)的服務(wù)诉字,兩個(gè)原因:
1)9200被限制為本機(jī)訪問,需要在es的配置文件elasticsearch.yml中新增配置:
network.bind_host:0.0.0.0
2)關(guān)閉虛擬機(jī)防火墻
解決了這個(gè)兩個(gè)問題后,本地能夠順利訪問虛擬機(jī)的ES服務(wù)了壤圃。
注意陵霉,以上虛擬內(nèi)存的更改,每次重啟系統(tǒng)之后都要重新設(shè)置
ysctl -w vm.max_map_count=262144
4)解決完了之后伍绳,再次啟動(dòng)服務(wù)(先殺后啟)
ps -ef|grep elasticsearch|grep bootstrap |awk '{print $2}' |xargs kill -9
nohup ./bin/elasticsearch &
03 訪問es
1)使用curl測(cè)試踊挠,因?yàn)槭褂玫氖窃品?wù)器部署
curl http://localhost:9200/?pretty
得到的內(nèi)容
{
"name" : "Nd1M7rH",
"cluster_name" : "choxsu-es",
"cluster_uuid" : "593zK7LuTZOvfcdgt09ZXQ",
"version" : {
"number" : "6.0.0",
"build_hash" : "8f0685b",
"build_date" : "2017-11-10T18:41:22.859Z",
"build_snapshot" : false,
"lucene_version" : "7.0.1",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
04 使用原生方式創(chuàng)建索引
使用 Xput創(chuàng)建索引
curl -XPUT 'http://localhost:9200/twitter/doc/1?pretty' -H 'Content-Type: application/json' -d '
{
"user": "kimchy",
"post_date": "2009-11-15T13:12:00",
"message": "Trying out Elasticsearch, so far so good?"
}'
curl -XPUT 'http://localhost:9200/twitter/doc/2?pretty' -H 'Content-Type: application/json' -d '
{
"user": "kimchy",
"post_date": "2009-11-15T13:12:00",
"message": "Trying out Elasticsearch, so far so good?"
}'
curl -XPUT 'http://localhost:9200/twitter/doc/3?pretty' -H 'Content-Type: application/json' -d '
{
"user": "kimchy",
"post_date": "2009-11-15T13:12:00",
"message": "Trying out Elasticsearch, so far so good?"
}'
查詢數(shù)據(jù)
curl -XGET 'http://localhost:9200/twitter/doc/1?pretty=true'
curl -XGET 'http://localhost:9200/twitter/doc/2?pretty=true'
curl -XGET 'http://localhost:9200/twitter/doc/3?pretty=true'
搜索數(shù)據(jù)
通過字進(jìn)行查詢:q=user:kimchy
curl -XGET 'http://localhost:9200/twitter/_search?q=user:kimchy&pretty=true'
curl -XGET 'http://localhost:9200/twitter/_search?q=user:kimchy&pretty=true'
通過JSON的方式進(jìn)行查詢
curl -XGET 'http://localhost:9200/twitter/_search?pretty=true' -H 'Content-Type: application/json' -d '
{
"query" : {
"match_all" : {}
}
}'
通過JSON的方式查詢,查詢的時(shí)候指定區(qū)間
curl -XGET 'http://localhost:9200/twitter/_search?pretty=true' -H 'Content-Type: application/json' -d '
{
"query" : {
"range" : {
"post_date" : { "from" : "2009-11-15T13:00:00", "to" : "2009-11-15T14:00:00" }
}
}
}'
那教程就到這里