解决 Prometheus 报错 opening storage failed lock file 存储锁死修复
排查 Prometheus 启动崩溃提示 opening storage failed: lock /data/lock: resource temporarily unavailable,排查多实例竞争与清理锁标记。
问题现象
Prometheus Pod 或服务在重启后持续陷入 CrashLoopBackOff,容器日志抛出错误:
ts=2026-11-15T12:00:00.000Z caller=main.go:800 level=error
msg="Opening storage failed"
err="lock /prometheus/data/lock: resource temporarily unavailable"
触发根因
- 旧 Prometheus 容器进程尚未完全停止,新容器已挂载了同一个 PVC:Kubernetes 默认的 RollingUpdate 策略在 Deployment 下可能导致两个 Pod 同时运行并争抢同一个底层单读写存储盘(ReadWriteOnce);
- 物理服务器突然非正常断电,留在磁盘上的
/prometheus/data/lock文件未被正常清理。
解决步骤
1. 将部署负载类型调整为 StatefulSet
Prometheus 强烈建议使用 StatefulSet 并配置 Recreate 或有序启停,避免多实例并发挂载:
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: prometheus
spec:
replicas: 1
updateStrategy:
type: RollingUpdate
2. 确认无竞争进程后安全清理锁文件
在确保没有其它运行中的 Prometheus 进程访问该目录的前提下,删除该锁标记:
# 停止服务
sudo systemctl stop prometheus
# 删除锁文件
sudo rm -f /var/lib/prometheus/data/lock
# 重新启动
sudo systemctl start prometheus
验证确认
查看服务状态与控制台日志:
sudo systemctl status prometheus
日志打印 Server is ready to receive web requests,时序数据库正常装配。


