在 Graylog 中,索引管理是日誌數據組織與搜索效率的核心,而妥善的存儲優化則能避免磁碟迅速耗盡,提升系統穩定性。
Graylog 數據最終寫入 OpenSearch 的索引中,一個索引集對應一組邏輯索引。索引集能設定索引的前綴名稱、分片數、複製數、輪轉策略及保留策略。
一般而言,索引不宜無限制增大。索引輪轉(Rotation)會根據條件創建新索引,常見條件 (舊版 Graylog) 包括:
這樣既可控制單個索引大小,也方便日後刪除舊索引釋放資源。
在 Graylog 6 中,索引管理已發生重大改變。傳統的基於消息數量、索引大小等輪轉策略已被棄用,取而代之的是 Data Tiering(數據分層) 策略,這是目前推薦且預設的索引管理方式。
Data Tiering 將數據分為三個層級:Hot Tier(熱層)、Warm Tier(溫層)與 Archive(歸檔)。每個層級針對不同的存取頻率與成本需求:
此架構能根據數據生命週期自動管理存儲資源,既保持查詢效率又控制成本。
索引集還包含保留策略,決定舊索引如何處理:
通常選擇「刪除」來自動清理過舊的日誌,避免磁碟滿溢。
設定完成後,Graylog 會自動執行輪轉和保留管理。
使用 REST API 建立採用 Data Tiering 的索引集:
{
"title": "production-logs",
"index_prefix": "graylog_prod",
"shards": 4,
"replicas": 0,
"use_legacy_rotation": false,
"rotation_strategy_class": "org.graylog2.indexer.rotation.strategies.TimeBasedRotationStrategy",
"rotation_strategy": {
"type": "org.graylog2.indexer.rotation.strategies.TimeBasedRotationStrategyConfig",
"rotation_period": "P1D"
},
"retention_strategy_class": "org.graylog2.indexer.retention.strategies.DeletionRetentionStrategy",
"retention_strategy": {
"max_number_of_indices": 30
}
}
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Basic <base64-encoded-credentials>" \
-d @index_set.json \
https://<graylog-url>/api/system/indices/index_sets
其中 index_set.json 是包含索引集配置的 JSON 文件。
若具備 Enterprise 授權,可設定 Warm Tier 降低存儲成本:
通過 Graylog 的索引集機制及 OpenSearch 原生輪轉與保留策略機制能有效管理日誌索引大小和數量,達到存儲空間的優化與系統性能的平衡。