系统学习 演练学习路径:35 个 lab 的难度排序、4 周基础计划与复盘方法

从 Prometheus 迁移到 VictoriaMetrics

适用场景

Prometheus 本地存储容量有限、查询变慢或需要长期保留。VictoriaMetrics 兼容 PromQL 和 Remote Write,存储效率高,适合替换单机 Prometheus 或作为长期存储。

前置条件

步骤

  1. 部署 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
  1. 配置 Prometheus remote write:
remote_write:
- url: http://vm-victoria-metrics-single-server:8428/api/v1/write
  1. 或使用 vmagent 替代 Prometheus 采集:
helm install vmagent vm/victoria-metrics-agent \
  --namespace monitoring \
  --set remoteWrite.url=http://vm-victoria-metrics-single-server:8428/api/v1/write
  1. 导入历史数据(可选):
vmctl prometheus --prometheus-url=http://prometheus:9090 \
  --start=2026-09-01T00:00:00Z \
  --end=2026-10-01T00:00:00Z
  1. 迁移告警规则:
vmalert -rule=/etc/prometheus/rules/*.yml \
  -datasource.url=http://vm:8428 \
  -notifier.url=http://alertmanager:9093
  1. Grafana 数据源改为 VictoriaMetrics:
http://vm-victoria-metrics-single-server:8428

验证

回滚

常见坑

相关命令

参考链接

读完自测

合上页面,先回答,再展开对照。

  1. VictoriaMetrics 对 PromQL 的兼容程度如何?
  2. 保留周期设置过短会有什么后果?
  3. 单机 VictoriaMetrics 有什么可用性风险?
答案
  1. 兼容性高但并非 100%,复杂查询要逐条验证。
  2. 历史数据会被删除。
  3. 没有副本,故障后数据会丢失。
微信小程序码:扫码打开命令速查小程序

小程序版

微信扫码,随时查命令