引言
ElasticSearch是一個基於Lucene的搜索引擎,它提供了一個基於RESTful web接口的分佈式多用戶的全文搜索引擎。ElasticSearch可以用來存儲需要檢索和統計的數據,它支持聚合、百分比、分段統計等,也可以用來存儲日誌,例如ELK(Elasticsearch+Logstash+Kibana)日誌分析系統。本文主要介紹Elasticsearch的單機部署以及如何解決部署過程中碰到的各種坑。
部署指南
- 首先進入Elasticsearch官方下載頁下載Elasticsearch安裝包,筆者下載的是6.4.2的linux版本
download elasticsearch
使用tar命令解壓並修改文件【
elasticsearch-6.4.2/config/elasticsearch.yml】,修改network這塊,將【network.host】修改為部署服務器的IP地址,【http.port】去掉前面的註釋【#】。
elasticsearch.yml
使用非root用戶運行如下命令
<code>elasticsearch-6.4.2/bin/elasticsearch -d/<code>
啟動成功運行命令【curl http://{IP}:9200】能看到如下輸出就證明啟動成功了:
<code>{"name"
:"TUJE35D"
,"cluster_name"
:"elasticsearch"
,"cluster_uuid"
:"-fsA4mjPTyOe0fF-bPvvmA"
,"version"
: {"number"
:"6.4.2"
,"build_flavor"
:"default"
,"build_type"
:"tar"
,"build_hash"
:"04711c2"
,"build_date"
:"2018-09-26T13:34:09.098244Z"
,"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"
}/<code>
填坑指南
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
can not run elasticsearch as root
這個錯誤是因為使用了root賬戶啟動Elasticsearch,換個非root賬戶啟動就可以了;
- Exception in thread "main" java.nio.file.AccessDeniedException: /usr/local/elasticsearch-6.4.2/config/jvm.options
AccessDeniedException
這是文件權限問題,啟動Elasticsearch的用戶沒有elasticsearch-6.4.2目錄的權限,運行如下命令修改文件夾權限
<code>chown
-R {啟動Elasticsearch的用戶}:{啟動Elasticsearch用戶所屬的用戶組} elasticsearch-6.4
.2
/<code>
max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
這是用戶最大可創建的文件數太小,只有4096,無法創建本地文件,需要增加到65536。切換到root用戶,編輯limits.conf配置文件
<code>vi
/etc/security/limits.conf/<code>
添加如下兩行,然後保存
<code>{啟動Elasticsearch的用戶}
soft
nofile
65536
{啟動Elasticsearch的用戶}
hard
nofile
65536
/<code>
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
這是因為設置的最大虛擬內存太小,切換到root用戶下,修改配置文件sysctl.conf
<code>vi
/etc/sysctl.conf/<code>
添加下面配置:
<code>vm.max_map_count
=262144
/<code>
並執行命令:
<code>sysctl
-p/<code>