系统学习
演练学习路径:35 个 lab 的难度排序、4 周基础计划与复盘方法
→
从 Prometheus 迁移到 VictoriaMetrics
适用场景
Prometheus 本地存储容量有限、查询变慢或需要长期保留。VictoriaMetrics 兼容 PromQL 和 Remote Write,存储效率高,适合替换单机 Prometheus 或作为长期存储。
前置条件
- 现有 Prometheus 配置和告警规则。
- 对象存储或大容量本地磁盘。
- 明确迁移方式:双写、远程写或历史数据导入。
- Grafana 数据源和告警链路。
步骤
- 部署 VictoriaMetrics:
helm repo add vm https://victoriametrics.github.io/helm-charts/
helm install vm vm/victoria-metrics-single \
--namespace monitoring \
--set server.retentionPeriod=12
kubectl -n monitoring get pods
- 配置 Prometheus remote write:
remote_write:
- url: http://vm-victoria-metrics-single-server:8428/api/v1/write
- 或使用 vmagent 替代 Prometheus 采集:
helm install vmagent vm/victoria-metrics-agent \
--namespace monitoring \
--set remoteWrite.url=http://vm-victoria-metrics-single-server:8428/api/v1/write
- 导入历史数据(可选):
vmctl prometheus --prometheus-url=http://prometheus:9090 \
--start=2026-09-01T00:00:00Z \
--end=2026-10-01T00:00:00Z
- 迁移告警规则:
vmalert -rule=/etc/prometheus/rules/*.yml \
-datasource.url=http://vm:8428 \
-notifier.url=http://alertmanager:9093
- Grafana 数据源改为 VictoriaMetrics:
http://vm-victoria-metrics-single-server:8428
验证
- Remote Write 成功,指标可查询。
- Grafana 看板与旧 Prometheus 一致。
- 告警规则能触发并发送。
- 历史数据可查询。
- 保留周期和磁盘容量符合预期。
回滚
- 保留旧 Prometheus 和 PVC。
- Grafana 保留旧数据源,切换失败时改回。
- 双写期间不要删除旧数据。
- 回滚后确认告警没有重复发送。
常见坑
- PromQL 兼容性高但并非 100%,复杂查询要逐条验证。
- Remote Write 标签冲突,序列重复。
- 历史数据导入时间范围大,耗时和磁盘占用高。
- vmalert 的规则语法与 Prometheus 有细微差异。
- Grafana 数据源类型选错,查询报错。
- 保留周期设置过短,历史数据被删除。
- 单机 VictoriaMetrics 没有副本,故障后数据丢失。
- 告警去重和静默配置没有迁移。
相关命令
vmctl — 历史数据导入
vmalert — 告警规则
vmagent — 指标采集
- promtool — 校验 Prometheus 规则
- kubectl — 查看组件
参考链接
读完自测
合上页面,先回答,再展开对照。
- VictoriaMetrics 对 PromQL 的兼容程度如何?
- 保留周期设置过短会有什么后果?
- 单机 VictoriaMetrics 有什么可用性风险?
答案
- 兼容性高但并非 100%,复杂查询要逐条验证。
- 历史数据会被删除。
- 没有副本,故障后数据会丢失。