Try   HackMD

ES 儲存排除特定節點

Outline

  1. 設定
  2. 測試
  3. 使用心得

設定

Cluster-level shard allocation filtering

PUT _cluster/settings
{
  "transient" : {
    "cluster.routing.allocation.exclude._ip" : "10.0.0.1"
  }
}
  • transient 可以改成 persistent
  • 可以選 _ip, _name

取得節點名稱、ip、id

GET /_cat/nodes?v
GET "/_cat/nodes?v&h=name,ip,id"

清除叢集設定

PUT /_cluster/settings
{
  "transient" : {
    "cluster.routing.allocation.exclude._ip" : null,
    "cluster.routing.allocation.exclude._name" : null

  }
}

測試

1. 建立 index

PUT /test-name-replica1

2. 設定replica 數量

PUT /test-name-replica1/_settings
{
  "index" : {
    "number_of_replicas" : 1
  }
}

3. 寫入資料

4. 查看 shard 分佈

GET /_cat/shards

昱齊狀態有分p,r(primary、replica)、STARTED跟UNASSIGNED

使用心得

  1. 使用cluster.routing.allocation.exclude
    1. 用_name 沒用,要用_ip

    昱齊如果用_name,但是當replica超過node數量,還是會強制使用該node
    昱齊但一般replica預設1,至少有三個節點且僅排除一個節點的情況下,使用_name是沒問題的

    1. 假設我有三個node,我指定了replica=3,理論上要有4份資料,但是當要指定被排除的 node時,shard的狀態會變 UNASSIGNED

    昱齊但這個也合理,shard不能放在同個es node底下,所以沒地方指定就會這樣

    1. 狀態會是黃色的,但其實他是有replica,只是不完整
  2. 其他做法:設定容量
    cluster.routing.allocation.disk.watermark.low
    cluster.routing.allocation.disk.watermark.high