Elasticsearch6.4安裝

下載地址:https://www.elastic.co/cn/downloads 假設系統安裝好了對應的jdk,且jdk的版本要高於8。下面是具體的安裝步驟。

  • 解壓下載的安裝包,命令如下:
tar -xzvf elasticsearch-6.4.3.tar.gz
  • 增加一個新用戶和用戶組:因爲elasticsearch有遠程執行腳本的功能所以容易中木馬病毒,不允許用root用戶啓動,賦權限,用一般的用戶啓動。命令如下:
groupadd elasticsearch
useradd elasticsearch -g elasticsearch
chown -R elasticsearch:elasticsearch /home/ivan/elasticsearch-6.4.3/
  • 修改config目錄下的elasticsearch.yml文件,具體的配置如下:
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
#集羣的名稱
#
cluster.name: ivan_test
#
# ------------------------------------ Node ------------------------------------
#
# 節點的名稱
#
node.name: package4
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
#配置你存數據的目錄
#
path.data: /home/ivan/elasticsearch-6.4.3/data
#
# 配置你存日誌的目錄
#
path.logs: /home/ivan/elasticsearch-6.4.3/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup: 這兩個配置用於解決下面的問題,否則會報錯
#
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#需要配置成本面的ip,否則外部無法訪問
#
network.host: 對應機器的ip
#
# Set a custom port for HTTP:
#
#http.port: 9200
http.cors.enabled: true
http.cors.allow-origin: "*"
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes: 
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
  • 通過bin目錄下的elasticsearch啓動應用

安裝期間踩的坑

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

  • 解決辦法: 切換回root用戶並通過vim /etc/security/limits.conf 命令修改系統的配置文件
#增加如下兩行
* hard nofile 65536
* soft nofile 65536

注:ubuntu下需要通過ulimit -n 65536 命令 2: max number of threads [1024] for user [elasticsearch] is too low, increase to at least [4096]

  • 解決辦法: 切換回root用戶並通過vim /etc/security/limits.d/90-nproc.conf 修改文件,增加如下行:
*          soft    nproc     4096

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

  • 解決辦法: 切換回root用戶並通過vim /etc/sysctl.conf 修改文件,添加下面配置:
vm.max_map_count=655360

並執行命令:sysctl -p 4: system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk

  • 解決辦法: 修改elasticsearch.yml文件裏的配置,增加如下兩個配置:
bootstrap.memory_lock: false
bootstrap.system_call_filter: false

5:the minimum required Java version is 8; your Java version from [/usr/local/java/jdk7/jre] does not meet this requirement。

  • 解決辦法,當linux機器裏安裝了多個jdk時, 而啓動報這人錯,說明沒應用path下的jdk,可以通過修改config目錄下的elasticsearch-env文件,指定用那個jdk啓動
export JAVA_HOME=/usr/local/java/jdk1.8.0_121
export PATH=${JAVA_HOME}/bin:$PATH

6:正常啓動後,通過遠程機器無法訪問,

  • 解決辦法:首先通過curl確認本地是可以訪問的,修改elasticsearch.yml文件裏的配置,增加如下兩個配置:
http.cors.enabled: true
http.cors.allow-origin: "*"

如果還沒辦法訪問, 注意系統的防火牆,可能通過如下命令關閉:

service iptables stop

集羣安裝

ES是去中心化,字面上理解就是無中心節點,這是對於集羣外部來說的,因爲從外部來看ES集羣,在邏輯上是個整體,你與任何一個節點的通信和與整個ES集羣通信是等價的。但在ES集羣內部有如下三種角色:

  • master node:主要用於元數據(metadata)的處理,管理集羣狀態,包括管理分片的狀態和副本的狀態,以及節點的發現和刪除、分片分配等。
  • data node:節點上保存了數據分片。它負責數據相關操作,比如分片的 CRUD,以及搜索和整合操作。
  • client node: 節點起到路由請求的作用,實際上可以看做負載均衡器。 根據每臺機器的角色,修改下面四個配置,其中node.master與node.data的值根據實際情況進行修改。discovery.zen.ping.unicast.hosts:用於配置集羣裏的ip.
node.master: true 
node.data: true
discovery.zen.ping.unicast.hosts: ["IP1", "IP2", "IP3"]
discovery.zen.minimum_master_nodes: 1 #用來配置主節點的最小值
遇到的問題

1:failed to send join request to master

  • 解決辦法:集羣安裝過程難免會相互拷文件,在copy文件的時候, 需要把data目錄下的文件刪除了。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章