Ceph PG 不一致问题排查与修复
- **集群信息:**
- **问题现象:**
-
-
- [第一步:查看 PG 健康状态](#第一步:查看 PG 健康状态)
- 第二步:尝试修复但无效
- [第三步:深度分析 PG 状态](#第三步:深度分析 PG 状态)
- 第四步:查找具体不一致对象
- [第五步:检查 OSD.401 硬件状态](#第五步:检查 OSD.401 硬件状态)
- [EC 8+2 数据恢复原理](#EC 8+2 数据恢复原理)
- 修复方案
-
- [方案 1:深度清理 + 修复(推荐)](#方案 1:深度清理 + 修复(推荐))
-
- [检查是否有并发的 scrub 限制](#检查是否有并发的 scrub 限制)
-
- [查看当前正在 scrub 的 PG 数量](#查看当前正在 scrub 的 PG 数量)
集群信息:
- Ceph 版本:14.2.22 (Nautilus)
- 集群规模:610 个 OSD,7 个 MON
- 存储池:EC 8+2 纠删码池
- 数据量:3.7 PiB (994.58M 对象)
问题现象:
bash
# ceph -s
cluster:
health: HEALTH_ERR
1 scrub errors
Possible data damage: 1 pg inconsistent
services:
osd: 610 osds: 609 up (since 8d), 609 in (since 8d)
- 集群出现 1 个 PG 不一致错误,状态为
active+clean+inconsistent。
第一步:查看 PG 健康状态
bash
# ceph health detail
HEALTH_ERR 1 scrub errors; Possible data damage: 1 pg inconsistent
OSD_SCRUB_ERRORS 1 scrub errors
PG_DAMAGED Possible data damage: 1 pg inconsistent
pg 2.2f9 is active+clean+inconsistent, acting [460,16,275,554,213,142,401,352,527,92]
关键信息:
- 问题 PG:
2.2f9 - 涉及 OSD:[460,16,275,554,213,142,401,352,527,92]
- 主 OSD:460
第二步:尝试修复但无效
bash
# ceph pg repair 2.2f9
instructing pg 2.2f9s0 on osd.460 to repair
# 再次检查,状态未改变
# ceph health detail
HEALTH_ERR 1 scrub errors; Possible data damage: 1 pg inconsistent
pg 2.2f9 is active+clean+inconsistent, acting [460,16,275,554,213,142,401,352,527,92]
问题分析:
修复命令执行后,PG 状态没有显示 repairing,说明修复命令可能没有真正执行或立即失败。
第三步:深度分析 PG 状态
bash
# ceph pg 2.2f9 query | jq '.' > 2.2f9.txt
清理错误统计:
json
"num_scrub_errors": 1,
"num_shallow_scrub_errors": 0,
"num_deep_scrub_errors": 1,
"num_objects_repaired": 0
修复状态:
json
"scrubber.active": false,
"scrubber.state": "INACTIVE"
第四步:查找具体不一致对象
bash
# rados list-inconsistent-obj 2.2f9 --format=json-pretty
核心发现:
只有 1 个对象 不一致:100000328f4.00001917
json
{
"osd": 401,
"primary": false,
"shard": 6,
"errors": [
"read_error"
],
"size": 524288
}
分片状态:
| OSD | Shard | 状态 | 大小 | 错误 |
|---|---|---|---|---|
| 460 | 0 (主) | ✅ 正常 | 512 KB | 无 |
| 16 | 1 | ✅ 正常 | 512 KB | 无 |
| 275 | 2 | ✅ 正常 | 512 KB | 无 |
| 554 | 3 | ✅ 正常 | 512 KB | 无 |
| 213 | 4 | ✅ 正常 | 512 KB | 无 |
| 142 | 5 | ✅ 正常 | 512 KB | 无 |
| 401 | 6 | ❌ read_error | 512 KB | 无法读取 |
| 352 | 7 | ✅ 正常 | 512 KB | 无 |
| 527 | 8 | ✅ 正常 | 512 KB | 无 |
| 92 | 9 | ✅ 正常 | 512 KB | 无 |
问题定位:
- OSD.401 的 shard 6 出现
read_error - 其他 9 个分片全部正常
- EC 8+2 配置下,丢失 1 个分片数据仍可完整恢复
第五步:检查 OSD.401 硬件状态
bash
# ceph osd metadata osd.401
OSD 信息:
- 主机:ceph126
- 数据盘:16TB HDD
- DB/WAL:53GB NVMe SSD
- 存储引擎:BlueStore
bash
# smartctl -a /dev/sdak
SMART 检测结果(全部正常):
- ✅ Reallocated_Sector_Ct: 0
- ✅ Current_Pending_Sector: 0
- ✅ Offline_Uncorrectable: 0
- ✅ UDMA_CRC_Error_Count: 0
- ✅ 整体健康状态: PASSED
EC 8+2 数据恢复原理
纠删码 8+2 配置:
- 8 个数据分片 (shards 0-7)
- 2 个校验分片 (shards 8-9)
- 容错能力: 最多可丢失 2 个分片
当前情况:
- 丢失 1 个分片 (shard 6)
- 有 9 个健康分片
- 数据可以完整恢复 ✅
修复方案
方案 1:深度清理 + 修复(推荐)
适用场景: 轻微的对象损坏
bash
# 1. 触发深度清理
ceph pg deep-scrub 2.2f9
# 2. 等待 2-3 分钟
sleep 180
# 3. 触发修复
ceph pg repair 2.2f9
# 4. 观察状态
watch -n 10 'ceph health detail'
检查是否有并发的 scrub 限制
查看当前正在 scrub 的 PG 数量
- Scrub 队列已满,Repair 命令被排队。
bash
ceph pg dump pgs | grep scrubbing | wc -l
bash
ceph config dump | grep -E "osd_scrub|osd_max_scrubs|osd_scrub_auto_repair"