ElasticSearch 7.8.1叢集搭建

陳彥斌發表於2020-08-13

通往叢集的大門

叢集由什麼用?

高可用

  高可用(High Availability)是分散式系統架構設計中必須考慮的因素之一,它通常是指,通過設計減少系統不能提供服務的時間。如果系統每執行100個時間單位,會有1個時間單位無法提供服務,我們說系統的可用性是99%。

負載均衡

  將流量均衡的分佈在不同的節點上,每個節點都可以處理一部分負載,並且可以在節點之間動態分配負載,以實現平衡。

高效能

  將流量分發到不同機器,充分利用多機器多CPU,從序列計算到平行計算提供系統效能。

ES叢集的基本核心概念

Cluster叢集

  一個ElasticSearch叢集由一個或多個節點(Node)組成,每個叢集都有一個共同的叢集名稱作為標識。

Node節點

  一個ElasticSearch例項即一個Node,一臺機器可以有多個例項,正常使用下每個例項應該會部署在不同機器上。ElasticSearch的配置檔案中可以通過node.master、node.data來設定節點型別。

  node.master:表示節點是否具有稱為主節點的資格

    true代表的是有資格競選主節點

    false代表的是沒有資格競選主節點

  node.data:表示節點是否儲存資料

Node節點組合

主節點+資料節點(master+data)

    節點即有稱為主節點的資格,又儲存資料

node.master: true
node.data: true

資料節點(data)

  節點沒有成為主節點的資格,不參與選舉,只會儲存資料

node.master: false
node.data: true

客戶端節點(client)

  不會成為主節點,也不會儲存資料,主要是針對海量請求的時候,可以進行負載均衡

node.master: false
node.data: false

分片

  每個索引有一個或多個分片,每個分片儲存不同的資料。分片可分為主分片(primary shard)和複製分片(replica shard),複製分片是主分片的拷貝。預設每個主分片有一個複製分片,一個索引的複製分片的數量可以動態地調整,複製分片匆匆不與它的主分片在同一個節點上。

搭建ES叢集

搭建步驟

  • 拷貝ES7.8.1安裝包3份,分別命名es-a,es-b,es-c
  • 分別修改elasticsearch.yml檔案
  • 分別啟動a、b、c三個節點
  • 開啟瀏覽器輸入:ip:port/_cat/health?v,如果返回的nodt.total是3,代表叢集搭建成功

配置檔案

#叢集名稱,三臺叢集,要配置相同的叢集名稱!!!
cluster.name: my-application
#節點名稱
node.name: node-1 #是不是有資格主節點
node.master: true
#是否儲存資料
node.data: true
#最⼤叢集節點數
node.max_local_storage_nodes: 3 #⽹關地址
network.host: 0.0.0.0
#端⼝
http.port: 9200
#內部節點之間溝通端⼝
transport.tcp.port: 9300
#es7.x 之後新增的配置,寫⼊候選主節點的裝置地址,在開啟服務後可以被選為主節點
discovery.seed_hosts: ["localhost:9300","localhost:9400","localhost:9500"]
#es7.x 之後新增的配置,初始化⼀個新的叢集時需要此配置來選舉master
cluster.initial_master_nodes: ["node-1", "node-2","node-3"] #資料和儲存路徑
path.data: /Users/louis.chen/Documents/study/search/storage/a/data
path.logs: /Users/louis.chen/Documents/study/search/storage/a/logs

注意

  因為我是一臺伺服器上,搞了3搞ES啟動埠號不同,拷貝了3份es,具體還要跟實際情況相應調整

真實配置-a

# ======================== 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 -----------------------------------
#
# Use a descriptive name for your cluster:
#
# 叢集名稱
cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
# 叢集名稱
node.name: node-1
# 是不是有資格主節點
node.master: true
# 是否儲存資料
node.data: true
# 最大叢集節點數,因為3個叢集,所以配置3
node.max_local_storage_nodes: 3
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
# 資料儲存路徑
path.data: /var/soft/es7.8.1/elasticsearch-7.8.1/data
# 日誌儲存路徑
# Path to log files:
#
path.logs: /var/soft/es7.8.1/elasticsearch-7.8.1/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# 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):
# 閘道器地址
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
# 埠
http.port: 9200
# 內部節點之間溝通埠
transport.tcp.port: 9300
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
# es7.x之後新增的配置,寫入候選主節點的裝置地址,在開啟服務後可以被選為主節點
discovery.seed_hosts: ["127.0.0.1:9300", "127.0.0.1:9400", "127.0.0.1:9500"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
# es7.x之後新增的配置,初始化一個新的叢集時需要此配置來選舉master
cluster.initial_master_nodes: ["node-1", "node-2", "node-3"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Gateway -------------------------bootstrap.system_call_filter: false----------
#
# 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
bootstrap.system_call_filter: false
http.cors.allow-origin: "*"
http.cors.enabled: true
http.cors.allow-headers : X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization
http.cors.allow-credentials: true

真實配置-b

# ======================== 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 -----------------------------------
#
# Use a descriptive name for your cluster:
#
# 叢集名稱
cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
# 叢集名稱
node.name: node-2
# 是不是有資格主節點
node.master: true
# 是否儲存資料
node.data: true
# 最大叢集節點數,因為3個叢集,所以配置3
node.max_local_storage_nodes: 3
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
# 資料儲存路徑
path.data: /var/soft/es-b/data
# 日誌儲存路徑
# Path to log files:
#
path.logs: /var/soft/es-b/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# 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):
# 閘道器地址
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
# 埠
http.port: 9201
# 內部節點之間溝通埠
transport.tcp.port: 9400
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
# es7.x之後新增的配置,寫入候選主節點的裝置地址,在開啟服務後可以被選為主節點
discovery.seed_hosts: ["127.0.0.1:9300", "127.0.0.1:9400", "127.0.0.1:9500"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
# es7.x之後新增的配置,初始化一個新的叢集時需要此配置來選舉master
cluster.initial_master_nodes: ["node-1", "node-2", "node-3"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Gateway -------------------------bootstrap.system_call_filter: false----------
#
# 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
bootstrap.system_call_filter: false
http.cors.allow-origin: "*"
http.cors.enabled: true
http.cors.allow-headers : X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization
http.cors.allow-credentials: true

只修改了,2個埠、資料和日誌儲存路徑

真實配置-c

# ======================== 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 -----------------------------------
#
# Use a descriptive name for your cluster:
#
# 叢集名稱
cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
# 叢集名稱
node.name: node-3
# 是不是有資格主節點
node.master: true
# 是否儲存資料
node.data: true
# 最大叢集節點數,因為3個叢集,所以配置3
node.max_local_storage_nodes: 3
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
# 資料儲存路徑
path.data: /var/soft/es-c/data
# 日誌儲存路徑
# Path to log files:
#
path.logs: /var/soft/es-c/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# 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):
# 閘道器地址
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
# 埠
http.port: 9202
# 內部節點之間溝通埠
transport.tcp.port: 9500
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
# es7.x之後新增的配置,寫入候選主節點的裝置地址,在開啟服務後可以被選為主節點
discovery.seed_hosts: ["127.0.0.1:9300", "127.0.0.1:9400", "127.0.0.1:9500"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
# es7.x之後新增的配置,初始化一個新的叢集時需要此配置來選舉master
cluster.initial_master_nodes: ["node-1", "node-2", "node-3"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Gateway -------------------------bootstrap.system_call_filter: false----------
#
# 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
bootstrap.system_call_filter: false
http.cors.allow-origin: "*"
http.cors.enabled: true
http.cors.allow-headers : X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization
http.cors.allow-credentials: true

只修改了,2個埠、資料和日誌儲存路徑

踩坑錄(必看

坑一

 

坑二

  因為我是在一臺linux上搭建的叢集,然後用埠號9200、9201、9202區分開來的,es-b、es-c是拷貝es-a的,但是es-a的data目錄有資料,需要將es-b和es-c的data目錄清空,然後重啟es即可!!!

啟動

 

叢集搭建成功

配置kibana

開啟配置kibana.yml,新增elasticsearch.hosts: ["http://192.168.199.170:9200", "http://192.168.199.170:9201", "http://192.168.199.170:9202"]

 

然後重啟即可

 

相關文章