喬叔的 Elastic Stack 專業教育訓練
  • 喬叔的 Elastic Stack 專業教育訓練
  • 🧑關於喬叔 (Joe Wu)
  • Elastic 課程公開班
    • 🎯Elasticsearch 基礎實務班
      • 💯學員課後回饋
    • 🆕Elasticsearch 進階運維班
      • 💯學員課後回饋
    • Elasticsearch 進階開發班
    • Elastic Stack 基礎實務班
    • Elastic Observability 基礎實務班
    • 📩課程許願池
  • 技術分享
    • 📗喬叔帶你上手 Elastic Stack
      • 前言
      • Elastic Cloud 如何建立 Deployment
        • ES Node 的種類
        • 配置的選擇
      • Index 建立前你該知道的
        • ES Index 如何被建立
        • ES 的超前佈署 - Dynamic Mapping
        • ES 的超前佈署 - Index Template
        • ES Index 的別名 (Alias)
        • 管理你的 Index - Kibana Index
      • 管理 Index 的 Best Practices
        • Shard 的數量與 Rollover & Shrink API
        • 三溫暖架構 - Hot Warm Cold Architecture
        • Index Lifecycle Management (ILM)
        • Rollup
        • Transform
        • Snapshot Lifecycle Management (SLM)
        • 總結
      • Elastic Cloud 比免費版還多的功能
        • Elastic Stack 的方案比較與銷售方式
        • Centralized Beats Management
        • Centralized Pipeline Management
        • Watcher
        • Elasticsearch Token Service
        • Multi-stack monitoring & Automatic stack issue alerts
      • 向 App Search 學習怎麼用 Elasticsearch
        • 揭開 App Search 的面紗
        • Engine 的 Index Settings 篇
        • Engine 的 Mapping 篇
        • Engine 的 Search 基礎剖析篇
        • Engine 的 Search 進階剖析篇
      • Elasticsearch 的優化技巧
        • Indexing 索引效能優化
        • Searching 搜尋效能優化
        • Index 的儲存空間最佳化
        • Shard 的最佳化管理
      • 完賽心得
    • 📘喬叔帶你上手 Elastic Stack - 探索與實踐 Observability 系列
      • 前言 & 淺談 Observability
      • Elastic 的 Observability 解決方案
      • Uptime - 掌握系統的生命徵象
        • 我們要觀測的生命徵象是什麼?
        • 使用 Heartbeat 收集系統生命徵象數據
        • 透過 Kibana 觀看心電圖及設定警報
        • 使用合成監控 (Synthetics Monitor) 從使用者情境驗證服務的運作狀態
      • Metrics - 觀察系統的健康指標
        • Metrics 與 Metricbeat 的基本介紹
        • 使用 Metricbeat 掌握 Elastic Stack 的健康狀態
        • 使用 Metricbeat 掌握 Infrastructure 的健康狀態 Host 篇
        • 使用 Metricbeat 掌握 Infrastructure 的健康狀態 Docker 篇
        • 使用 Metricbeat 掌握 Infrastructure 的健康狀態 Kubernetes 篇
        • 使用 Metricbeat 掌握 Infrastructure 的健康狀態 AWS 篇
      • Logs - 挖掘系統內部發生的狀況
        • Logs 與 Filebeat 的基本介紹
        • 使用 Filebeat 應該要了解的設計細節與原理
        • 透過 Filebeat 收集 Elastic Stack 中各種服務的細節資訊
        • 透過 Filebeat 收集 Infrastructure 中各種服務的細節資訊
      • Traces - 觀察應用程式的效能瓶頸
        • Elastic APM 基本介紹
        • 使用 APM-Integratoin-Testing 建立 Elastic APM 的模擬環境
        • 如何在 Kibana 使用 APM UI
        • 使用 APM Server 來收集 APM 數據
        • 透過 APM Agents 收集並傳送後端服務運作的記錄
        • 透過真實使用者監控 (RUM, Real User Monitoring) 來改善使用者體驗
      • 建立結構化的 Log
        • Elastic Common Schema 結構化 Log 的規範
        • Elasticsearch Ingest Pipeline 資料 Index 前的轉換好幫手
          • 基本介紹
          • 各種常用的 Processor
          • Enrich 資料與例外處理
      • 有效的使用 Observability 的資料
        • 透過 Machine Learning 發現異常的問題
        • 使用 Kibana Alerts 主動通知異常狀況
        • 資料的生命週期管理
        • 使用 Elastic Observability 追縱及觀察問題的心得
      • 完賽心得
    • 😀Elasticsearch 技術分享小品
      • 🤖Elastic 與 AI
        • Elasticsearch Inference API 讓我們直接在 ES 裡運用 OpenAI Completion API
    • 🎥線上分享
      • 喬叔 Elasticsearch Index 管理與效能優化技巧
      • Elastic Certification 認證經驗分享
    • 🛠️workshop
      • 如何在 Elasticsearch 實現敏捷的資料建模與管理 @ DevOpsDays 2023
        • 工作坊實作內容
      • Elastic Observability 實作體驗坊 @ DevOpsDays 2022
        • 行前準備
        • 工作坊實作內容
      • 當 Elasticsearch 搜尋引擎遇上 AI @ HelloWordDevConference 2024
        • 投影片
        • Elasticsearch 環境準備
        • Google Colab 環境準備
        • 工作坊操作說明
        • ElasticSearch Relevance Engine (ESRE)
    • ⬆️Elastic Stack 版本升級記錄
      • 🔍Elasticsearch
  • 其他專業服務
    • 👩‍🎓企業包班 | 企業內訓
    • 👨‍💼顧問服務
    • 🈺專案合作
    • 🧩Elastic 授權代理
  • 相關連結
    • Facebook 粉絲頁
Powered by GitBook
On this page
  • 前言
  • 進入此章節的先備知識
  • 此章節的重點學習
  • Index Lifecycle Management (ILM)
  • Index Lifecycle Management 主要的 4 個階段
  • Index Lifecycle Management 中可以用的 Action 有哪些
  • 每個階段可以進行的 Action 有哪些
  • 透過 Kibana 來設定 Index Lifecycle Policies
  • Hot phase
  • Warm Phase
  • Cold Phase
  • Delete Phase
  • Index Lifecycle Policy 與 Index 之間的關係
  • 如何檢視 Index Lifecycle Policy 執行的狀況
  • 參考資料
  1. 技術分享
  2. 喬叔帶你上手 Elastic Stack
  3. 管理 Index 的 Best Practices

Index Lifecycle Management (ILM)

前言

先前我們介紹過了 Index, Shard, Segment Files, Hot-Warm-Cold Architecture,知道在不同的時期要有效率的使用 Index 可以進行什麼樣的配置,接下來要介紹的是全面的 Index Lifecycle 的機制,就會使用到之前介紹的各種機制,來進行 Index 生命週期的管理。

進入此章節的先備知識

  • Elasticsearch Index, Shard, Segment File 的基本認識。

  • Index Template 的基本認識。

  • Rollover 與 Shrink 的機制。

  • Hot-Warm-Cold Architecture。

此章節的重點學習

  • Index Lifecycle Management (ILM) 的使用方式。

  • 如何在 Elastic Cloud 中的 Kibana 來設定 ILM。

  • ILM 設定中背後的原理。


Index Lifecycle Management (ILM)

Index Lifecycle Management 顧名思意,就是用來管理 Index 的生命週期,而在 Elasticsearch Index 生命週期主要定義有四個段。

Index Lifecycle Management 主要的 4 個階段

  • Hot: 最新的資料,通常是用來放最新的資料。 可以寫入、可以查詢

  • Warm: 資料進來後,不再寫入時,但還是會常常的查用,通常會放在這個階段。 不能寫入、可以查詢

  • Cold: 資料已放蠻久的,不常使用到,但還是希望需要用到時能馬上就能用,但願意接受速度較慢一些,就會放在這個階段。 不能寫入、可以查詢(但較慢)

  • Delete: 資源總是有限,空間也是有限,時間久了總是有些舊資料應該要從 Elasticsearch 中刪掉。

上圖可以解釋當資料隨著時間變化,會不斷產新的 Index,並且隨著時間變化 (流水號數字愈大的是愈新的,數字愈小是時間愈久),會逐漸移到下一個階段中。

在 ILM 中,你可以建立一個 Policy 來指定想要設定哪些階段、以及每個階段要進行的 Action (動作) 是什麼,而在 ILM 中可以執行的動作有以下這些。

Index Lifecycle Management 中可以用的 Action 有哪些

  • Rollover: 當原 index 達到 一定的大小、資料筆數、資料存放一定時間 時,自動建立新的 Index 來放新進來的資料,不會讓某 Index 一直無限的增長下去。這個動作可以針對 Index Alias 或 Data Stream 進行設定。

  • Shrink: 將多個 Shard 的 Index 轉成較少 Shard 數量的 Index。

  • Force merge: 將一個 Shard 中的 Segment Files 進行合併,可以釋放出被刪掉的文件在原先 read-only 的 Segment File 所佔用的空間,也能加快查詢的速度。

  • Freeze: 將很少使用的 Index,以盡量不使用到 heap size 的方式來存放,

  • Delete: 刪掉 Index。

  • Set Priority: 指定 Index 的處理優先權,也就是當 node 重新啟動的時候,較高優先權的 Index 會先被 recover 而優先回到可被使用的狀態。

  • Unfollow: 將 Cross Cluster Replication 機制中,會 follow 的 Index 給取消 follow。在 Rollover, Shrink 處理時會自動執行這個 Action。

  • Wait for snapshot: 等到 Snapshot 完成後才能刪除 index。

每個階段可以進行的 Action 有哪些

Index Lifecycle Management 的階段
此階段中可以執行的操作有什麼

Hot

Force merge, Rollover, Set priority, Unfollow

Warm

Allocate, Force merge, Read only, Set priority, Shrink, Unfollow

Cold

Allocate, Freeze, Set priority, Unfollow

Delete

Delete, Wait for snapshot

透過 Kibana 來設定 Index Lifecycle Policies

我們從 Kibana 左側選單底下的 Stack Management 進入後,可以看到以下的畫面,左邊有個 Index Lifecycle Policies 可以進入 ILM 的管理畫面。

點右上的 Create Policy 即可開始建立。

Hot phase

在這個 Hot phase 的設定中,主要包含了前面介紹的一些設定 Rollover, Index Priority,不過在 Kibana 的畫可上,並沒有讓你設定 Force merge,畢竟這操作並不是適合用在一般的 Hot phase。

Warm Phase

在 Warm Phase 中,可以指定當 Hot Phase 中的 Index 發生 Rollover 時,是否直接把 Index 移到 Warm Phase 的階段。

若要移的話,會需要指定什麼樣的 attribute 是屬於 Warm Phase。

若使用 Elastic Cloud,他只有兩種 attribute - data:hot 和 data:warm,這也是依照硬體規格來配置過的。

除此之外可以指定 Shrink, Force merge, Index priority 等設定。

Cold Phase

在 Code Phase 的階段,也如同 Warm Phase 一樣,可以指定當 Rollover 發生多久之後 (若沒有啟動 Rollover,則是以 Index 建立的時間來判斷),要把 Index 移到 Rollover,不過因為 Elastic Cloud 目前提供的配置中,沒針對 Cold Phase 規劃的硬體配置,因此還沒辦法直接選擇,相信不久的將來會推出的。

另外可以指定是否要啟動 Freeze,以及是否要指定 Index Priority。

Delete Phase

Delete Phase 的設定很簡單,就是要在 index rollover 發生多久之後 (若沒有啟動 Rollover,則是以 Index 建立的時間來判斷),要刪除這個 Index。

另外可以指定,刪除之讀是否確保這個 Index 已經有備份過,這個 Snapshot Policy 會在這系列文章的面後有所介紹。

Index Lifecycle Policy 與 Index 之間的關係

當我們 Index Lifecycle Policy 設定好之後,在主畫面的 Actions 可以看到有兩個設定。

  1. View indices linked to policy: 點下就會跳到 Index Management 的頁面,並且過濾出被這個 Indes Lifecycle Policy 所管理的 Indices 有哪些。

如何檢視 Index Lifecycle Policy 執行的狀況

當 Index Lifecycle Policy 建立起來之後,若想知道某個 Index, Data stream, Index Alias 所對應的 Index Lifecycle Policy 及執行的狀況、目前在哪個階段…等,可以透過 Explain lifecycle API 來查看:

GET my-index-000001/_ilm/explain

以下是這個 Explain API 回傳的結構:

{
  "indices": {
    "my-index-000001": {
      "index": "my-index-000001",
      "managed": true, 
      "policy": "my_policy", 
      "lifecycle_date_millis": 1538475653281, 
      "age": "15s", 
      "phase": "new",
      "phase_time_millis": 1538475653317, 
      "action": "complete",
      "action_time_millis": 1538475653317, 
      "step": "complete",
      "step_time_millis": 1538475653317 
    }
  }
}

若是有正在執行中的步驟,也都會有詳細的資訊回傳,若有錯誤發生,也都能看得到。

若有錯誤時,在排除完成後,也可以直接使用 Retry API 來進行重試。

POST /my-index-000001/_ilm/retry

參考資料

Previous三溫暖架構 - Hot Warm Cold ArchitectureNextRollup

Last updated 2 years ago

ilm four phases

Allocate: 指定 Index replica 的數量,以及指定 Index 可以被放在哪些 shards 的規則。()

kibana ilm
index lifecycle policy - hot
index lifecycle policy - warm
index lifecycle policy - cold
index lifecycle policy - delete
index lifecycle policy vs index

Add policy to index template: 這個可以指定要套用到哪個 Index Template,讓新的 Index 被建立時,自動套用這個管理機制。

建議可以上 看更多詳細的介紹。

📗
Index-level shard allocation filtering
官方文件 - Index Lifecycle Management Explain API
官方文件 - Index Lifecycle Management
官方文件 - Index-level shard allocation filtering
官方文件 - Index Lifecycle Management Explain API
这么简单的ES索引生命周期管理,不了解一下吗~
index lifecycle policy apply index template