靈異現象:永遠刪不掉的 85 個 Error
在維運 Kibana 時,我們常看到 Reporting 功能產生大量的 .reporting-2023-xx-xx 索引。
當你想透過 ILM 自動清除它們時,卻發現它們全部卡在 “Lifecycle error”。
你嘗試手動刪除:
DELETE .reporting-2023-02-26
系統回傳:
403 Forbidden: 即使你是 elastic (superuser),你也沒有權限刪除系統索引。
這就是讓人崩潰的地方:我明明是用最大權限的帳號,為什麼不能刪?
根因分析:Restricted Indices (受限索引)
從 Elasticsearch 7.x 後期開始,為了防止管理者「手殘」誤刪重要的系統狀態(如 .security, .kibana, .tasks),官方引入了 Restricted Indices 機制。
這些以 . 開頭的系統索引,預設是 「隱形且鎖定」 的。
即便你的角色擁有 indices: [*] 和 privileges: [all],這個 * 通配符 並不包含 受限索引。
這就是為什麼你的 ILM 會報錯:
- ILM Policy 試圖執行 Delete Action。
- ILM 使用的 Service Account 雖然權限很高,但預設也被擋在 Restricted Wall 之外。
- 操作被拒絕 (403),ILM 進入 Error 狀態,並無限重試。
解法:上帝模式開關 allow_restricted_indices
你找到的這段 JSON,關鍵只有一行:
"allow_restricted_indices": true
POST /_security/role/System_Index_Cleaner
{
"indices": [
{
"names": [ ".reporting-*" ], // 指定你要動刀的系統索引
"privileges": [ "all" ],
"allow_restricted_indices": true // <--- 這就是解鎖鑰匙
}
]
}