深色模式
Thanos 长期存储
Prometheus 本地只存短期数据,Thanos 给它加上“无限历史 + 跨集群查询”的能力。
适用环境
- 已部署 Prometheus(开启
--web.enable-admin-api) - 有对象存储(S3 / 兼容 S3 均可)
bash
# 确认 admin API 已开启(Sidecar 需要)
curl -s http://localhost:9090/api/v1/status/flags | grep admin-api1
2
2
操作步骤
1. 准备对象存储配置
yaml
# thanos-bucket.yml
type: S3
config:
bucket: thanos-data
endpoint: s3.example.com
access_key: <AK>
secret_key: <SK>1
2
3
4
5
6
7
2
3
4
5
6
7
2. 部署 Thanos Sidecar(与 Prometheus 同机)
bash
thanos sidecar \
--prometheus.url=http://localhost:9090 \
--objstore.config-file=thanos-bucket.yml \
--http-address=0.0.0.0:10902 \
--grpc-address=0.0.0.0:109011
2
3
4
5
2
3
4
5
3. 部署 Thanos Query 做全局查询
bash
thanos query \
--http-address=0.0.0.0:10903 \
--store=localhost:109011
2
3
2
3
4. Grafana 接入 Query 端口 10903 即可查长期数据。
验证
bash
# 查看 Sidecar 上报的 StoreAPI
curl -s http://localhost:10903/api/v1/stores | head -c 3001
2
2
在 Thanos Query UI 选长时间范围(如 90 天)应能查到历史。
常见坑
必须开 admin-api 与 lifecycle
Sidecar 依赖 --web.enable-admin-api,否则无法读取 TSDB 块上传。
对象存储密钥别明文提交
secret_key 等同账号密码,用环境变量或密钥管理注入,勿入库。