Elasticsearch節點,集羣,分片及副本

elasticsearch其實就是一個分佈式系統,須要知足分佈式系統具有的高可用性和可擴展性html

分佈式系統的可用性與擴展性

  • 高可用性
    • 服務可用性-容許有節點中止服務
    • 數據可用性-部分節點丟失,不會丟失數據
  • 可擴展性
    • 請求量提高/數據的不斷增加(將數據分佈到全部節點上)

分佈式特性

  • elasticsearch的分佈式架構好處
    • 存儲的水平擴容
    • 提升系統的可用性,部分節中止服務,整個集羣的服務不受影響
  • ElasticSearch的分佈式架構
    • 不一樣的集羣經過不一樣的名字來區分,默認名字」elasticsearch「
    • 經過配置文件修改,或者在命令行中 -E cluster.name=geektime進行設定
    • 一個集羣能夠用多個節點

節點

  • 是一個elasticsearch的實例
    • 本質上是一個java進程
    • 一臺機器上能夠運行多個elasticsearch進程,可是生產環境通常建議一臺機器上運行一個elasticsearch實例
  • 每個節點都有名字,經過配置文件配置,或者啓動時候 -E node.name=node1 指定
  • 每個節點在啓動以後,會分配一個UID,保存在data目錄下

不一樣的節點承擔了不一樣的角色java

Master-eligible nodes和Master Node

  • 每一個節點啓動後,默認就是一個Master eligible節點
    • 能夠設置node.master:false禁止
  • Master-eligible節點能夠參加選主流程,成爲master節點
  • 當第一個節點啓動時候,它會將本身選舉成Master節點
  • 每一個節點上保存了集羣的狀態,只有master節點才能修改集羣的狀態信息
    • 集羣狀態(Cluster State),維護了一個集羣中,必要的信息
      • 全部的節點信息
      • 全部的索引和其相關的Mapping與Setting信息
      • 分片的路由信息
    • 任意節點都能修改信息會致使數據的不一致性

Data Node & Coordinate Node

  • Data Node
    • 能夠保存數據的節點,叫作Data Node,負責保存分片數據。在數據擴展上起到了相當重要的做用
  • Coordinate Node
    • 負責接受Client的請求,將請求分發到合適的節點,最終將結果聚集到一塊兒
    • 每一個節點默認起到了Coordinate Node的職責

其餘的節點類型

  • Hot & Warm Node
    • 不一樣硬件配置的Data Node,用來實現Hot & Warm架構,下降集羣部署的成本
  • Machine Learning Node
    • 負責跑機器學習的 Job,用來作異常檢測
  • Tribe Node
    • 5.3開始使用Cross Cluster Search ,Tribe Node鏈接到不一樣的Elasticsearch集羣,而且支持將這些集羣當成一個單獨的集羣處理

配置節點類型

  • 開發環境中一個節點能夠承擔多種角色
  • 生產環境配置單一角色:更好性能,單一角色
節點類型 配置參數 默認值
master eligible node.master true
data node.data true
ingest node.ingest true
coordinating only 每一個節點默認都是coordinate節點。設置其餘類型爲false
machine learning node.ml true(需設置 enable x-pack)

分片(Primary Shard & Replica Shard)

  • 主分片,用以解決數據水平擴展的問題。經過主分片,能夠將數據分佈到集羣內的全部節點之上node

    • 一個分片是一個運行的 Lucene 的實例
    • 主分片數在索引建立時指定,後續不容許修改,除非 經過Reindex方式進行
  • 副本,用以解決數據高可用的問題,分片是主分片的拷貝git

    • 副本分片數,能夠動態調整
    • 增長副本數,還能夠在必定程度上提升服務的可用性(讀取的吞吐)
  • 一個三節點的集羣中,blogs索引的分片分佈狀況github

一個主分片分散到三個節點上,每一個節點存在一個副本分片json

分片的設定

  • 對於生成環境分片的設定,須要提早作好容量規劃
    • 分片數設置太小
      • 致使後續沒法增長節點實現水平擴展
      • 單個分片的數據量太大,致使數據從新分配耗時
    • 分片數設置過大,7.0開始,默認主分片設置爲1,解決了over-sharding的問題
      • 影響搜索結果的相關性打分,影響統計結果的準確性
      • 單個節點上過多的分片,會致使資源浪費,同時也會影響性能

查看集羣的健康情況

GET _cluster/healthbash

{
  "cluster_name" : "elasticsearch",
  "status" : "yellow",
  "timed_out" : false,
  "number_of_nodes" : 1,
  "number_of_data_nodes" : 1,
  "active_primary_shards" : 6,
  "active_shards" : 6,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 1,
  "delayed_unassigned_shards" : 0,
  "number_of_pending_tasks" : 0,
  "number_of_in_flight_fetch" : 0,
  "task_max_waiting_in_queue_millis" : 0,
  "active_shards_percent_as_number" : 85.71428571428571
}
複製代碼
  • Green-主分片與副本都正常分配
  • Yellow-主分片所有正常分配,副本分片未能正常分配
  • Red-有主分片未能分配
    • 例如,當服務器的磁盤容量超過85%時,去建立一個新的索引

安裝cerebro

  • 建議經過github先下載文件(下載地址:github.com/lmenezes/ce…),而後進行安裝服務器

    tar zxvf cerebro-0.8.4.tgz
    cd cerebro-0.8.4
    複製代碼
  • 啓動架構

    bin/cerebroapp

  • 訪問網址:http://ip:9000

集羣中目前只有一個工做節點

操做示例

get _cat/nodes?v
GET /_nodes/es7_01,es7_02
GET /_cat/nodes?v
GET /_cat/nodes?v&h=id,ip,port,v,m


GET _cluster/health
GET _cluster/health?level=shards
GET /_cluster/health/kibana_sample_data_ecommerce,kibana_sample_data_flights
GET /_cluster/health/kibana_sample_data_flights?level=shards

#### cluster state
The cluster state API allows access to metadata representing the state of the whole cluster. This includes information such as
GET /_cluster/state

#cluster get settings
GET /_cluster/settings
GET /_cluster/settings?include_defaults=true

GET _cat/shards
GET _cat/shards?h=index,shard,prirep,state,unassigned.reason

複製代碼

相關閱讀

相關文章
相關標籤/搜索