--- title: ES 儲存排除特定節點 tags: Elasticsearch description: View the slide with "Slide Mode". --- # ES 儲存排除特定節點 <!-- Put the link to this slide here so people can follow --> ## Outline 1. 設定 2. 測試 3. 使用心得 ## 設定 ### [Cluster-level shard allocation filtering](#https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-cluster.html#cluster-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. <font color=red>查看 shard 分佈</font> ``` GET /_cat/shards ``` > [name=昱齊]狀態有分p,r(primary、replica)、STARTED跟UNASSIGNED ## 使用心得 1. 使用cluster.routing.allocation.exclude 1. 用_name 沒用,要用_ip >[name=昱齊]如果用_name,但是當replica超過node數量,還是會強制使用該node >[name=昱齊]但一般replica預設1,至少有三個節點且僅排除一個節點的情況下,使用`_name`是沒問題的 2. 假設我有三個node,我指定了replica=3,理論上要有4份資料,但是當要指定被排除的 node時,shard的狀態會變 UNASSIGNED >[name=昱齊]但這個也合理,shard不能放在同個es node底下,所以沒地方指定就會這樣 3. 狀態會是黃色的,但其實他是有replica,只是不完整 2. 其他做法:設定容量 cluster.routing.allocation.disk.watermark.low cluster.routing.allocation.disk.watermark.high
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up