Linux環境下安裝Elasticsearch
(因爲Elasticsearch需要jdk1.8或更高的版本纔可以運行)
提前下載tar.gz相關文件,下載地址:
https://www.elastic.co/downloads/elasticsearch
這裏下載的是elasticsearch-5.5.2.tar.gz
進入Linux相關目錄
解壓下載好的tar.gz文件到這個目錄
Linux通過登錄root用戶(Elasticsearch不允許通過root啓動,所以要新增一個用戶),添加一個用戶elk(自定義即可)
執行:useradd luck
設置密碼:passwd luck
root用戶下,執行以下命令:
chown -R elk elasticsearch-5.5.2 和 chgrp -R elk elasticsearch-5.5.2
接下來,編輯elasticsearch/config/elasticsearch.yml
在文件的末尾新增如下幾行:
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
network.host: 192.168.25.128
http.cors.enabled: true
http.cors.allow-origin: "*"
還是root用戶下,最後按步驟執行以下幾步:
第一步:
vim /etc/security/limits.conf
末尾添加如下內容:
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
第二步:
vim /etc/security/limits.d/90-nproc.conf
修改如下內容:
* soft nproc 1024
#修改爲
* soft nproc 2048
第三步:
vim /etc/sysctl.conf
末尾添加下面配置:
vm.max_map_count=655360
並執行命令:
sysctl -p
最後,退出root用戶登錄,使用elk用戶登錄,去到/usr/local/elasticsearch-5.5.2/bin
目錄下,執行"./elasticsearch"啓動elasticsearch
通過本機訪問:curl 192.168.25.128:9200/127.0.0.1:9200
通過局域網訪問:192.168.25.128:9200
如果按照上面的操作,下面的可以不用看注意:
幾乎每一次裝都會遇到的坑,這些坑只有5.x.x版本有,2.x.x版本的幾乎沒有遇到過:
1、機器內剩餘內存較少,會啓動失敗,並且有類似如下報錯:
```
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x000000008a660000, 1973026816, 0) failed; error='Cannot allocate memory' (errno=12)
這是因爲es的jvm參數-Xmx和-Xms默認都爲2G
修改config下的jvm.option文件
# vim elasticsearch/elasticsearch-5.5.1/config/jvm.opstions
將
-Xms2g
-Xmx2g
改爲
-Xms1g
-Xmx1g
或更小
-Xms512M
-Xmx512M
再次啓動即可
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...
問題原因:因爲Centos6不支持SecComp,而ES5.x.x默認bootstrap.system_call_filter爲true進行檢測,所以導致檢測失敗,失敗後直接導致ES不能啓動。詳見 :https://github.com/elastic/elasticsearch/issues/22899
解決方法:在elasticsearch.yml中配置bootstrap.system_call_filter爲false,注意要在Memory下面:
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
ERROR: bootstrap checks failed
max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
max number of threads [1024] for user [lishang] likely too low, increase to at least [2048]
解決方法:切換到root用戶,編輯limits.conf 添加類似如下內容
#vim /etc/security/limits.conf
添加如下內容:
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
max number of threads [1024] for user [lish] likely too low, increase to at least [2048]
解決方法:切換到root用戶,進入limits.d目錄下修改配置文件。
#vim /etc/security/limits.d/90-nproc.conf
修改如下內容:
* soft nproc 1024
修改爲
* soft nproc 2048
-
max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
解決方法:切換到root用戶修改配置sysctl.conf
#vim /etc/sysctl.conf
添加下面配置:
vm.max_map_count=655360
並執行命令:
#sysctl -p
然後,再啓動elasticsearch,即可啓動成功。
問題五:max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
解決:修改切換到root用戶修改配置limits.conf 添加下面兩行
命令:vi /etc/security/limits.conf
* hard nofile 65536
* soft nofile 65536
切換到es的用戶。