CentOS7安裝Elasticsearch5.5.3

1、準備

安裝Java環境,elasticsearch推薦安裝java1.8.0_131或更高的版本,安裝教程CentOS7安裝JDK1.8html

2、安裝

CentOS下能夠選擇.tar.gzrpm方式安裝Elasticsearch,但因爲生產環境不能訪問外網,所以採用.tar.gz的方式安裝。java

下載安裝包

經過瀏覽器下載對用版本的安裝包,下載地址:https://www.elastic.co/downloads/past-releasesjson

若是安裝服務器能夠鏈接外網,也能夠輸入命令直接下載bootstrap

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.3.tar.gz

解壓及安裝

tar -xzf elasticsearch-5.5.3.tar.gz

運行

cd elasticsearch-5.5.3/
./bin/elasticsearch

./bin/elasticsearch -d後臺運行瀏覽器

添加用戶

若是啓動會出現can not run elasticsearch as root的錯誤,是因爲出於安全考慮,Elasticsearch不容許以root用戶啓動,所以須要添加用於運行Elasticsearch的用戶。安全

adduser xxx                             #添加用戶:xxx
passwd ********                         #給xxx用戶設置密碼
chown -R xxx /opt/elasticsearch-5.5.3   #爲xxx添加權限

而後再執行elasticsearch命令則可正常啓動Elasticsearchbash

驗證

curl http://localhost:9200

驗證結果:服務器

{
  "name" : "Cp8oag6",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "AT69_T_DTp-1qgIJlatQqA",
  "version" : {
    "number" : "5.5.3",
    "build_hash" : "f27399d",
    "build_date" : "2016-03-30T09:51:41.449Z",
    "build_snapshot" : false,
    "lucene_version" : "6.5.1"
  },
  "tagline" : "You Know, for Search"
}

配置

Elasticsearch的配置文件在[安裝目錄]/config/文件夾下curl

elasticsearch.yml

開啓外網訪問

network.host: 0.0.0.0

鎖定物理內存

避免交換,提升性能,如下來源官網:jvm

bootstrap.memory_lock: true

jvm.options

修改JVM堆大小設置

-Xms16g
-Xmx16g

對於內存設置官方提供了一些建議,如:

  • XmsXmx設置成相等的,避免每次垃圾回收完成後JVM從新分配內存;

  • Xmx的大小不要超過物理內存的50%等

詳細請參考官方文檔:heap-size

錯誤

max file descriptors過小

max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]

切換root用戶,編輯/etc/security/limits.conf,按照要求改成65536便可,修改後結果:

* soft nofile 65536
* hard nofile 65536

從新登陸後生效

max_map_count過小

max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

切換root用戶,編輯/etc/sysctl.conf,在最後一行增長如下配置:

vm.max_map_count = 262114

需重啓後生效

內存鎖定失敗

memory locking requested for elasticsearch process but memory is not locked

當設置bootstrap.memory_lock: true時,若是沒有鎖定內存,會報該錯誤
需切換回root用戶,編輯/etc/security/limits.conf,增長如下配置:

* soft memlock unlimited
* hard memlock unlimited

一樣從新登陸後生效

相關文章
相關標籤/搜索