ElasticSearch教程——安裝
阿新 • • 發佈:2018-12-09
基礎環境
1.系統版本:Centos 7.4
2.jdk版本:java version "1.8.0_181"(該版本的elasticsearch必須使用jdk8及以上版本)
一.下載
二.解壓並安裝
(1)將下載的檔案放在伺服器如下目錄:/usr/elasticsearch/
(2)解壓
tar -zxvf elasticsearch-6.4.0.tar.gz
(3)建立日誌資料夾
# mkdir -p /data/logs/elasticsearch
# mkdir -p /data/elasticsearch/{data,work,plugins,scripts}
(4)建立一個非root使用者
ElasticSearch有個比較特殊的地方就是不能用root許可權來執行,所以我們這邊需要新建一個使用者以及賦予對應許可權。
a.新建一個elsearch使用者組
groupadd elsearch
b.新建使用者elsearch,並讓他加入elsearch組
useradd elsearch -g elsearch -p elsearch
c.賦予新使用者對elasticsearch-6.4.0和/data/*的操作許可權
chown -R elsearch:elsearch elasticsearch-6.4.0
chown -R elsearch:elsearch /data/*
d.切換使用者
su elsearch
(5)修改配置檔案(暫時可以不修改)
因為上面準備獨立出日誌等相關資料了,所以這邊需要修改配置檔案,新增如下配置:
path.data: /data/elasticsearch/data
path.logs: /data/logs/elasticsearch
path.plugins: /data/elasticsearch/plugins
path.scripts: /data/elasticsearch/scripts
也可以通過如下配置來修改埠:
http.port: 9200
(6)啟動任務
cd /usr/elasticsearch/elasticsearch-6.4.0/bin/ sh elasticsearch
(7)驗證是否執行
下面兩者需同時滿足
a. 輸入如下指令碼,有對應服務出現
ps -ef|grep elasticsearch
b.輸入http//:ip:9200出現下圖所示
{
"name" : "F6U_sFR",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "dTfp6ypnTQW-45WbwqSGTQ",
"version" : {
"number" : "6.4.0",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "595516e",
"build_date" : "2018-08-17T23:18:47.308994Z",
"build_snapshot" : false,
"lucene_version" : "7.4.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
三.可能異常
1.
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:140) ~[elasticsearch-6.4.0.jar:6.4.0]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) ~[elasticsearch-6.4.0.jar:6.4.0]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.4.0.jar:6.4.0]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.4.0.jar:6.4.0]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.4.0.jar:6.4.0]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.4.0.jar:6.4.0]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86) ~[elasticsearch-6.4.0.jar:6.4.0]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:104) ~[elasticsearch-6.4.0.jar:6.4.0]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:171) ~[elasticsearch-6.4.0.jar:6.4.0]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:326) ~[elasticsearch-6.4.0.jar:6.4.0]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-6.4.0.jar:6.4.0]
... 6 more
解決方案:按照上面所述,新增使用者,不要用root使用者啟動服務即可
2.
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解決方案:
a.切換到root使用者,修改sysctl.conf配置檔案
vi /etc/sysctl.conf
b.新增如下配置檔案
vm.max_map_count=655360
c.執行如下指令碼後,重啟elasticsearch即可
sysctl -p