如何使用 ISM 來管理 Amazon OpenSearch Service 儲存空間不足的情況?
我的 Amazon OpenSearch Service 叢集儲存空間不足。我想使用索引狀態管理 (ISM) 來管理儲存空間。
簡短說明
若要解決儲存空間不足的問題,請使用 ISM 來定義自訂管理政策並執行變換操作,例如自動刪除舊索引。變換操作會在現有索引符合指定條件時,將目標切換到新索引。ISM 會在每個狀態評估索引建立的日期和時間,以決定何時啟動相關動作。
將政策附加到索引後,索引會開始初始化,然後依序轉換至不同狀態,直到變換操作完成。如需有關變換操作的更多資訊,請參閱 Open Distro 網站上的變換。
解決方法
設定變換索引
若要在 OpenSearch Dashboards 建立索引模式,請完成以下步驟:
- 打開 OpenSearch Service console (OpenSearch Service 主控台)。
- 存取 OpenSearch Dashboards。
**注意:**您可以在 OpenSearch Service 主控台的網域摘要中找到 OpenSearch Dashboards 的連結。 - 選擇 Management (管理)。
- 選擇 Index Patterns (索引模式),然後選擇 Create index pattern (建立索引模式)。
- 建立索引與別名,其索引格式需符合 ^.*-\d+$ 索引模式。
重要:為避免錯誤,請確保正確設定您的變換別名。
如需更多資訊,請參閱 OpenSearch 網站上的索引模式。
當您在 ISM 政策中加入變換操作時,您也必須加入變換別名。如需詳細資訊,請參閱為什麼 ISM 政策中的變換索引動作會在 OpenSearch Service 中一直失敗?
以下範例會建立 test-index-000001 並填入多個文件。由於範例使用目標變換至的新索引,因此索引格式必須符合該索引的模式:
PUT test-index-000001/_doc/1 { "user": "testuser", "post_date": "2020-05-08T14:12:12", "message": "ISM testing" }
以下範例會建立指向新索引的 test-index 別名:
POST /_aliases{ "actions": [ { "add": { "index": "test-index-000001", "alias": "test-index" } } ] }
建立 ISM 政策
在 OpenSearch Dashboards 中,為 變換操作建立 ISM 政策。
範例政策
變換至暖狀態:
{ "policy": { "policy_id": "Roll_over_policy", "description": "A test policy. DO NOT USE FOR PRODUCTION!", "schema_version": 1, "error_notification": null, "default_state": "hot", "states": [ { "name": "hot", "actions": [ { "rollover": { "min_size": "10mb" } } ], "transitions": [ { "state_name": "warm" } ] }, { "name": "warm", "actions": [ { "replica_count": { "number_of_replicas": 2 } } ], "transitions": [] } ] } }
上述 ISM 政策定義了熱和暖狀態。預設情況下,您的索引會處於熱狀態。當索引大小達到 10 MB 且 ISM 變換至新索引時,索引會變換為暖狀態。在暖狀態下,您可以對索引執行不同的動作。例如,您可以將複本數量更改為二,或執行 force_merge 操作。
幾天後變換以刪除索引:
{ "policy": { "policy_id": "Roll_over_policy", "description": "A test policy. DO NOT USE FOR PRODUCTION!", "schema_version": 1, "error_notification": null, "default_state": "hot", "states": [ { "name": "hot", "actions": [ { "rollover": { "min_size": "10mb" } } ], "transitions": [ { "state_name": "delete", "conditions": { "min_index_age": "30d" } } ] }, { "name": "delete", "actions": [ { "delete": {} } ], "transitions": [] } ] } }
上述 ISM 政策定義了熱和刪除狀態。預設情況下,索引處於熱狀態。當索引達到 10 MB 時,ISM 會變換至新索引。然後,30 天後索引會轉換到刪除狀態,且 ISM 會刪除該索引。
如需更多政策範例,請參閱政策範例。
將政策附加到索引
請完成下列步驟:
- 打開 OpenSearch Service console (OpenSearch Service 主控台)。
- 使用 OpenSearch Service 主控台網域摘要中的連結存取 OpenSearch Dashboards。
- 選擇 Index Management (索引管理) 索引標籤。
- 選取您要附加 ISM 政策的索引,例如 test-index-000001。
**注意:**您可以在 Policy Managed Indices (政策管理索引) 下找到您的索引。 - 選擇 Apply policy (套用政策)。
- (選用) 如果您的政策指定需要別名的動作,請提供別名,然後選擇 Apply (套用)。
您也可以使用以下 API 附加 ISM 政策:
POST _plugins/_ism/add/index_name { "policy_id": "policy_name"}
**注意:**將 index_name 替換為您的索引名稱,將 policy_name 替換為您的政策名稱。
如需更多資訊,請參閱 OpenSearch 網站上的新增政策。
更新現有索引的政策
OpenSearch 中的 ISM 政策使用版本控制。當您更新政策時,新建立的索引會自動參考該政策的最新版本。但是,更新前建立的索引仍會參考先前版本。若要將更新的政策套用到現有索引,您必須先從索引中移除舊政策,然後重新套用更新版本。
若要將 ISM 政策重新套用到現有索引,請完成以下步驟:
- 打開 OpenSearch Service console (OpenSearch Service 主控台)。
- 使用 OpenSearch Service 主控台網域摘要中的連結存取 OpenSearch Dashboards。
- 選擇 Index Management (索引管理) 索引標籤。
- 在 Policy Managed Indices (政策管理索引) 區段中,選擇 Change Policy (變更政策)。
- 選取您要套用變更的索引,例如 test-index-000001。
- 選擇索引的目前狀態。
- 在 Choose New Policy (選擇新政策) 區段中,選擇 Update policy name (更新政策名稱)。
- (選用) 若要在更新政策後將索引切換至其他狀態,請選擇 Switch indices to the following state after the policy takes effect (政策生效後將索引切換到以下狀態)。然後,從下拉式清單中選擇狀態。
您也可以使用以下 API 更新 ISM 政策:
POST _plugins/_ism/change_policy/indexname { "policy_id": "policy_1"}
**注意:**將 index_name 替換為您的索引名稱,並將 policy_1 替換為您的政策名稱。
如需更多資訊,請參閱 OpenSearch 網站上的更新管理索引政策。
新增範本以將政策套用至多個索引
若要將政策套用至符合索引模式的多個索引,請建立並使用 ISM 範本。
使用以下 API 呼叫來建立政策:
PUT _plugins/_ism/policies/test_policy
政策範例:
{ "policy": { "description": "A test policy. DO NOT USE FOR PRODUCTION!", "last_updated_time": 1642027350875, "schema_version": 1, "error_notification": null, "default_state": "hot", "states": [ { "name": "hot", "actions": [ { "rollover":{ "min_size": "10mb" } } ], "transitions":[ { "state_name": "warm" } ] }, { "name": "warm", "actions": [ { "replica_count":{ "number_of_replicas": 2 } } ], "transitions": [] } ], "ism_template":{ "index_patterns":[ "test*" ], "priority": 100 } } }
使用以下範例 API 呼叫來確認 test_policy 範本已套用到新建立的索引:
GET _plugins/_ism/explain/test-index-000002
預期輸出:
{ "test-index-000002": { "index.plugins.index_state_management.policy_id": "test_policy", "index.opendistro.index_state_management.policy_id": "test_policy", "index": "test-index-000002", "index_uuid": "CZrQ-RzRS8SmiWIuyqFmVg", "policy_id": "test_policy", "enabled": true }, "total_managed_indices": 1 }
如需更多資訊,請參閱 OpenSearch 網站上的說明索引。
**注意:**索引也會出現在 OpenSearch Dashboards Index Management (索引管理) 索引標籤的 Managed Indices (管理索引) 區段。
檢查您的 ISM 政策狀態
對於變換操作,索引在變換完成、變換到暖狀態,並更新複本數量後即為完成。
如果您使用 ISM 政策且索引未正確遷移,請檢查 ISM 的狀態。
若要檢查索引的遷移狀態,請使用以下 API:
GET _ultrawarm/migration/index_name/_status
**注意:**將 index_name 替換為您要檢查狀態的索引名稱。
若要取得所有索引的遷移狀態,請使用以下 API:
GET _ultrawarm/migration/_status?
**注意:**若要將資料從熱儲存移至暖或冷儲存,請在設定 ISM 政策之前先在網域上啟用暖和冷儲存。ISM 政策還必須明確包含 migration (遷移) 動作,以在儲存階層之間轉換索引。若未包含 migration (遷移) 動作,則僅會變更政策狀態名稱。索引將繼續保留在熱儲存中。
設定暖儲存遷移動作:
{ "name": "warm", "actions": [{ "warm_migration": {}, "retry": { "count": 5, "delay": "1h" }
設定冷儲存遷移動作:
{ "name": "cold", "actions": [{ "cold_migration": { "timestamp_field": "<your timestamp field>" } }
- 語言
- 中文 (繁體)

相關內容
已提問 1 年前
已提問 1 年前