Centos 6.X下Elasticsearch安裝教程

1. Elasticsearch簡介

  ElasticSearch是一個基於Lucene的搜索服務器。它提供了一個分佈式多用戶能力的全文搜索引擎,基於RESTful web接口。Elasticsearch是用Java開發的,並做爲Apache許可條款下的開放源碼發佈,是當前流行的企業級搜索引擎。設計用於雲計算中,可以達到實時搜索,穩定,可靠,快速,安裝使用方便。java

  咱們創建一個網站或應用程序,並要添加搜索功能,可是想要完成搜索工做的建立是很是困難的。咱們但願搜索解決方案要運行速度快,咱們但願能有一個零配置和一個徹底免費的搜索模式,咱們但願可以簡單地使用JSON經過HTTP來索引數據,咱們但願咱們的搜索服務器始終可用,咱們但願可以從一臺開始並擴展到數百臺,咱們要實時搜索,咱們要簡單的多租戶,咱們但願創建一個雲的解決方案。所以咱們利用Elasticsearch來解決全部這些問題以及可能出現的更多其它問題。   web

2. Elasticsearch安裝

首先,去官網下載Centos專用安裝包,下載地址:點我bootstrap

下載上圖紅框中的文件,下載完成後上傳到centos服務器,而後解壓文件:centos

tar -zxvf elasticsearch-5.5.2.tar.gz
複製代碼

注意:安裝ElasticSearch前必須先安裝JAVA的JDK。安全

而後,將解壓後的文件拷貝到本身想要放置的目錄,個人是放置到/usr/local目錄下面,操做代碼:bash

cd /usr/local
mv ~/elasticsearch-6.3.2 elasticsearch
複製代碼

3. 啓動ElasticSearch

進入ElasticSearch的bin文件加,直接啓動:服務器

./elasticsearch
複製代碼

哐當,出現錯誤,沒法啓動curl

[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:140) ~[elasticsearch-6.3.2.jar:6.3.2]
        at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) ~[elasticsearch-6.3.2.jar:6.3.2]
        at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.3.2.jar:6.3.2]
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.3.2.jar:6.3.2]
        at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.3.2.jar:6.3.2]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.3.2.jar:6.3.2]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86) ~[elasticsearch-6.3.2.jar:6.3.2]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
        at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:104) ~[elasticsearch-6.3.2.jar:6.3.2]
        at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:171) ~[elasticsearch-6.3.2.jar:6.3.2]
        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:326) ~[elasticsearch-6.3.2.jar:6.3.2]
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-6.3.2.jar:6.3.2]
複製代碼

出現這個問題是因爲不能使用root用戶啓動,必須新建用戶才能夠。這麼作主要目的仍是爲了安全性的考慮,可是在Centos 7上是不會有這個問題的elasticsearch

添加用戶組、用戶,設置密碼:tcp

groupadd es
useradd es -g es
passwd es
複製代碼

設置文件夾屬性:

chown -R es:es elasticsearch
複製代碼

設置好帳戶後,切換登陸到剛剛設置的帳戶,而後在啓動:

cd /usr/local/elasticsearch/bin/
./elasticsearch
複製代碼

若是出現如下信息,說明啓動成功

驗證是否真正的成功: 打開另一個窗口,而後輸入以下命令:

curl http://127.0.0.1:9200
複製代碼

返回結果

恭喜,安裝成功!

默認狀況下,Elastic 只容許本機訪問,若是須要遠程訪問,能夠修改 Elastic 安裝目錄的config/elasticsearch.yml文件,去掉network.host的註釋,將它的值改爲0.0.0.0,而後從新啓動 Elastic

network.host: 0.0.0.0
複製代碼

上面代碼中,設成0.0.0.0讓任何人均可以訪問。線上服務不要這樣設置,要設成具體的 IP。

同時須要開放9200端口號:

/sbin/iptables -I INPUT -p tcp --dport 9200 -j ACCEPT
複製代碼

4. 常見錯誤

錯誤1: 若是這時報錯"max virtual memory areas vm.maxmapcount [65530] is too low",要運行下面的命令:
sudo sysctl -w vm.max_map_count=262144
複製代碼
錯誤2:若是報以下錯誤
ERROR: [3] bootstrap checks failed
[1]: max file descriptors [65535] 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]: system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
複製代碼

切換到root用戶,編輯limits.conf

vi /etc/security/limits.conf 
複製代碼

並添加相似以下內容

* soft nofile 65536

* hard nofile 131072

* soft nproc 2048

* hard nproc 4096
複製代碼

編輯90-nproc.conf文件

vi /etc/security/limits.d/90-nproc.conf 
複製代碼

修改內容

#* soft nproc 1024

#修改成

* soft nproc 2048
複製代碼
錯誤3. 錯誤信息
ERROR: [1] bootstrap checks failed
[1]: 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.2.0默認bootstrap.system_call_filter爲true進行檢測,因此致使檢測失敗,失敗後直接致使ES不能啓動。

解決辦法:在elasticsearch.yml中配置bootstrap.system_call_filter爲false,注意要在Memory下面

bootstrap.memory_lock: false
bootstrap.system_call_filter: false
複製代碼

修改完配置後,最好退出從新登陸一下,否則可能配置無效。

相關文章
相關標籤/搜索