簡介
網上有各種ES版本的安裝步驟和問題解決方案,但是在安裝過程中還是遇到了許多問題,那麼今天來整理一份詳細的安裝過程以及碰到的問題和心得;有什麼不對的和問題希望大家留言一起討論。
- jdk至少需要在1.8.0_73以上版本。
- linux的內核版本需要在2.6以上(我用的是centos7.x)
一、下載elasticsearch
cd /usr/localwget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.7.tar.gz
下載成功日誌輸出
--2018-10-31 10:36:28--
https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.7.tar.gz
Resolving artifacts.elastic.co... 54.235.82.130, 184.72.242.47, 54.235.171.120, ...
Connecting to artifacts.elastic.co|54.235.82.130|:443... connected.
HTTP request sent, awaiting response... 200 OKLength: 33789994 (32M) [binary/octet-stream]
Saving to: “elasticsearch-5.6.7.tar.gz”100%[==========================================================>] 33,789,994 7.51M/s in 4.7s 2018-10-31 10:36:35 (6.83 MB/s) - “elasticsearch-5.6.7.tar.gz” saved [33789994/33789994]
二、解壓安裝
解壓命令
tar -zxvf elasticsearch-5.6.7.tar.gz
解壓成功日誌輸出
[root@iZuf6fj49j7lt0ckj85qurZ ~]# tar -zxvf elasticsearch-5.6.7.tar.gzelasticsearch-5.6.7/
elasticsearch-5.6.7/lib/
elasticsearch-5.6.7/lib/elasticsearch-5.6.7.jar
elasticsearch-5.6.7/lib/lucene-core-6.6.1.jar
elasticsearch-5.6.7/lib/lucene-analyzers-common-6.6.1.jar
elasticsearch-5.6.7/lib/lucene-backward-codecs-6.6.1.jar
省略..................
elasticsearch-5.6.7/modules/percolator/plugin-descriptor.properties
elasticsearch-5.6.7/modules/percolator/percolator-5.6.7.jar
elasticsearch-5.6.7/modules/aggs-matrix-stats/
elasticsearch-5.6.7/modules/aggs-matrix-stats/plugin-descriptor.properties
elasticsearch-5.6.7/modules/aggs-matrix-stats/aggs-matrix-stats-5.6.7.jar
elasticsearch-5.6.7/plugins/
修改文件夾(方便尋找)
mv elasticsearch-5.6.7 elasticsearch
三、配置文件
1、配置文件說明
jvm.options 虛擬機參數配置文件
配置heap內存一樣
elasticsearch.yml 主配置文件
cluster.name 集群名稱,同一個網段自動加入
node.name 節點名稱
http.port http端口
默認情況下,Elastic 只允許本機訪問,如果需要遠程訪問,可以修改 Elastic 安裝目錄的config/elasticsearch.yml文件,去掉network.host的註釋,將它的值改成0.0.0.0,然後重新啟動 Elastic。
2、進入配置文件目錄
在memory下添加如下
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
退出保存後執行如下命令:
sysctl -p
3、修改如下文件
vi /etc/security/limits.conf
在文件末尾添加如下代碼
# testes為登錄服務器的用戶名testes soft nofile 65536
testes hard nofile 65536
testes soft nproc 4096
testes hard nproc 4096
4、創建testes 用戶(root用戶不能啟動elasticsearch)
useradd testes
passwd 你的密碼
按提示輸入兩次密碼:你的密碼
cd /root
sudo chown -R python elasticsearch
sudo chgrp -R python elasticsearch
6、切換用戶
su - python
四、啟動elasticsearch
1:控制檯啟動(ctrl+c 後停止):
./bin/elasticsearch
2:控制檯啟動:
./bin/elasticsearch -d
五、訪問elasticsearch
http://101.132.243.207:9200/
結果
{
"name" : "6u6hh_l",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "Be7Td91uSt67xmPljJ8vhg",
"version" : {
"number" : "5.6.7",
"build_hash" : "4669214",
"build_date" : "2018-01-25T21:14:50.776Z",
"build_snapshot" : false,
"lucene_version" : "6.6.1"
},
"tagline" : "You Know, for Search"
}
六、踩坑
1、root 權限下啟動elasticsearch 錯誤
錯誤信息
[root@iZuf6fj49j7lt0ckj85qurZ elasticsearch]# ./bin/elasticsearch
[2018-10-31T16:06:43,042][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:123) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:70) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:134) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) ~[elasticsearch-5.6.7.jar:5.6.7]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:106) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:195) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:342) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:132) ~[elasticsearch-5.6.7.jar:5.6.7]
... 6 more
由於ElasticSearch可以接收用戶的腳本並執行,處於安全性考慮,建議創建一個單獨的用戶來運行ElasticSearch。當然,可以通過配置來實現root用戶啟動。
修改bin目錄elasticsearch.in.sh文件中追加(不過不建議):
JAVA_OPTS="$JAVA_OPTS -Des.insecure.allow.root=true"
2、max virutal memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
原因:主要是因為ES使用的虛擬內存大小跟linux默認的大小不一樣,默認的太小,需要配置更大一點
解決辦法:
1、切換到root用戶修改配置sysctl.conf
vi /etc/sysctl.conf
添加下面配置:
vm.max_map_count=655360
並執行命令:
sysctl -p
然後,重新啟動elasticsearch,即可啟動成功。
3、外網訪問失敗
修改配置elasticsearch.yml
network.host: 0.0.0.0
# Set the bind address to a specific IP (IPv4 or IPv6):
##network.host: 192.168.0.1
network.host: 0.0.0.0#
# Set a custom port for HTTP:
##http.port: 9200
4、unknown setting [vm.max_map_count] please check that any required plugins a
報錯信息
java.lang.IllegalArgumentException: unknown setting [vm.max_map_count] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
at org.elasticsearch.common.settings.AbstractScopedSettings.validate(AbstractScopedSettings.java:293) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.common.settings.AbstractScopedSettings.validate(AbstractScopedSettings.java:256) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.common.settings.SettingsModule.
at org.elasticsearch.node.Node.
at org.elasticsearch.node.Node.
at org.elasticsearch.bootstrap.Bootstrap$5.
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:233) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:342) [elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:132) [elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:123) [elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:70) [elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:134) [elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.cli.Command.main(Command.java:90) [elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91) [elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) [elasticsearch-5.6.7.jar:5.6.7]
[2018-10-31T15:23:15,809][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.IllegalArgumentException: unknown setting [vm.max_map_count] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-5.6.7.jar:
省略。。。。。
原因:在elasticsearch.yml 文件配置了 vm.max_map_count=262144
閱讀更多 IT實戰聯盟 的文章