--- title: "ISM 历史索引副本数配置" date: 2026-03-10 lastmod: 2026-03-10 description: "index_state_management.history.number_of_replicas 配置项用于控制 ISM 历史索引的副本数量。" tags: ["索引状态管理", "ISM", "历史记录", "副本配置"] summary: "配置项作用 # index_state_management.history.number_of_replicas 配置项用于控制索引状态管理(ISM)历史索引的副本数量。 历史索引用于存储 ISM 策略执行的记录,包括状态变更、操作日志等信息。副本数影响历史数据的可用性和存储开销。 配置项属性 # 配置路径: index_state_management.history.number_of_replicas 数据类型: Integer(整数) 默认值: 1 最小值: 0 是否可选: 是 作用域: NodeScope(节点级别) 动态更新: 是(支持动态更新) 配置项详解 # 工作机制 # 历史索引副本结构 主分片 (Primary) │ ├─── 副本 1 (Replica 1) ← number_of_replicas = 1 │ └─── 副本 2 (Replica 2) ← number_of_replicas = 2 数据写入流程: 1. 写入主分片 2. 同步到所有副本 3. 确认写入完成 查询读取流程: 1. 可以从主分片或任意副本读取 2. 提高查询可用性 副本数的影响 # 副本数对比 number_of_replicas = 0: ┌─────────┐ │ Primary │ ← 只有主分片 └─────────┘ 优点: 存储开销最小 缺点: 无数据冗余,节点故障时数据丢失 ❌ number_of_replicas = 1 (默认): ┌─────────┐ │ Primary │ └─────────┘ ↓ ┌─────────┐ │ Replica │ ← 1 个副本 └─────────┘ 优点: 数据冗余,可承受 1 个节点故障 ✅ 缺点: 存储开销双倍 number_of_replicas = 2: ┌─────────┐ │ Primary │ └─────────┘ ↓ ┌─────────┐ ┌─────────┐ │ Replica1│ │ Replica2│ ← 2 个副本 └─────────┘ └─────────┘ 优点: 可承受 2 个节点故障 ✅ 缺点: 存储开销三倍 配置建议 # 生产环境(默认) # index_state_management: history: number_of_replicas: 1 # 默认值 建议: 保持默认值 1。平衡可用性和存储开销。" --- ## 配置项作用 `index_state_management.history.number_of_replicas` 配置项用于控制**索引状态管理(ISM)历史索引的副本数量**。 历史索引用于存储 ISM 策略执行的记录,包括状态变更、操作日志等信息。副本数影响历史数据的可用性和存储开销。 ## 配置项属性 - **配置路径**: `index_state_management.history.number_of_replicas` - **数据类型**: `Integer`(整数) - **默认值**: `1` - **最小值**: `0` - **是否可选**: 是 - **作用域**: NodeScope(节点级别) - **动态更新**: 是(支持动态更新) ## 配置项详解 ## 工作机制 ``` 历史索引副本结构 主分片 (Primary) │ ├─── 副本 1 (Replica 1) ← number_of_replicas = 1 │ └─── 副本 2 (Replica 2) ← number_of_replicas = 2 数据写入流程: 1. 写入主分片 2. 同步到所有副本 3. 确认写入完成 查询读取流程: 1. 可以从主分片或任意副本读取 2. 提高查询可用性 ``` ## 副本数的影响 ``` 副本数对比 number_of_replicas = 0: ┌─────────┐ │ Primary │ ← 只有主分片 └─────────┘ 优点: 存储开销最小 缺点: 无数据冗余,节点故障时数据丢失 ❌ number_of_replicas = 1 (默认): ┌─────────┐ │ Primary │ └─────────┘ ↓ ┌─────────┐ │ Replica │ ← 1 个副本 └─────────┘ 优点: 数据冗余,可承受 1 个节点故障 ✅ 缺点: 存储开销双倍 number_of_replicas = 2: ┌─────────┐ │ Primary │ └─────────┘ ↓ ┌─────────┐ ┌─────────┐ │ Replica1│ │ Replica2│ ← 2 个副本 └─────────┘ └─────────┘ 优点: 可承受 2 个节点故障 ✅ 缺点: 存储开销三倍 ``` ## 配置建议 ## 生产环境(默认) ```yaml index_state_management: history: number_of_replicas: 1 # 默认值 ``` **建议**: 保持默认值 `1`。平衡可用性和存储开销。 ## 高可用环境 ```yaml index_state_management: history: number_of_replicas: 2 # 2 个副本 ``` **建议**: 设置为 `2`。需要更高可用性时使用。 ## 单节点集群 ```yaml index_state_management: history: number_of_replicas: 0 # 无副本 ``` **建议**: 设置为 `0`。单节点环境无法分配副本。 ## 测试环境 ```yaml index_state_management: history: number_of_replicas: 0 # 节省资源 ``` **建议**: 设置为 `0`。测试环境节省存储。 ## 代码示例 ## easysearch.yml 基础配置 ```yaml index_state_management: history: number_of_replicas: 1 ``` ## 完整历史配置 ```yaml index_state_management: history: enabled: true number_of_shards: 1 number_of_replicas: 1 max_docs: 2500000 max_age: 24h ``` ## 高可用配置 ```yaml index_state_management: history: number_of_shards: 1 number_of_replicas: 2 ``` ## 动态更新配置 ```json PUT /_cluster/settings { "transient": { "index_state_management.history.number_of_replicas": 2 } } ``` ## 相关配置 | 配置项 | 作用 | 默认值 | |--------|------|--------| | `index_state_management.history.enabled` | 是否启用历史记录 | true | | `index_state_management.history.number_of_shards` | 历史索引分片数 | 1 | | `index_state_management.history.number_of_replicas` | 历史索引副本数 | 1 | | `index_state_management.history.max_docs` | 历史索引最大文档数 | 2500000 | ## 存储开销计算 ``` 不同副本数的存储开销 假设单个历史索引 25GB number_of_replicas = 0: 总存储 = 25GB (主分片) number_of_replicas = 1: 总存储 = 25GB × (1 + 1) = 50GB number_of_replicas = 2: 总存储 = 25GB × (1 + 2) = 75GB 配合保留期 (30天,每天1个索引): replicas = 1: 50GB × 30 = 1.5TB replicas = 2: 75GB × 30 = 2.25TB ``` ## 使用场景 ## 推荐使用默认值的场景 - **标准生产**: 正常的可用性要求 - **中等规模**: 集群节点数量适中 - **平衡需求**: 平衡可用性和存储 ## 推荐增加副本数的场景 - **高可用要求**: 需要承受节点故障 - **关键业务**: 历史数据很重要 - **多节点集群**: 有足够节点分配副本 ## 推荐减少副本数的场景 - **单节点集群**: 无法分配副本 - **存储受限**: 存储空间紧张 - **测试环境**: 不需要数据冗余 ## 故障恢复能力 ``` 副本数与故障恢复 number_of_replicas = 0: 可承受故障节点数: 0 数据安全性: 低 ❌ number_of_replicas = 1: 可承受故障节点数: 1 数据安全性: 中等 ✅ number_of_replicas = 2: 可承受故障节点数: 2 数据安全性: 高 ✅ number_of_replicas = 3: 可承受故障节点数: 3 数据安全性: 很高 ✅ 注意事项: - 副本数需要集群有足够的节点 - 副本分配在不同节点上提供高可用性 ``` ## 配置变更影响 ``` 配置变更的影响范围 现有历史索引: - 配置变更不影响已创建的索引 - 只有新创建或滚动的索引使用新配置 新建历史索引: - 使用当前配置的副本数 - 在索引创建时确定 动态更新: - 配置立即生效 - 下次滚动操作使用新配置 ``` ## 注意事项 1. **默认值**: 默认值为 `1`,适合大多数场景。 2. **节点要求**: 设置副本数需要集群有足够的节点。 3. **存储开销**: 每个副本会占用额外的存储空间。 4. **生效时机**: 配置变更只对新创建或滚动的索引生效。 5. **写入性能**: 更多副本会增加写入延迟。 6. **查询性能**: 更多副本可以提高查询吞吐量。 7. **动态更新**: 支持动态更新,修改后立即生效。 8. **隐藏索引**: 历史索引是隐藏索引,不占用命名空间。 9. **与分片数配合**: 总的分片数 = (1 + 副本数) × 主分片数。 10. **监控建议**: 监控历史索引的健康状态和存储使用。