prometheus联邦集群配置

一、简介

对于大部分监控规模而言,我们只需要在每一个数据中心安装一个Prometheus Server实例,就可以在各个数据中心处理上千规模的集群。同时将Prometheus Server部署到不同的数据中心可以避免网络配置的复杂性。

在每个数据中心部署单独的Prometheus Server,用于采集当前数据中心监控数据。并由一个中心的Prometheus Server负责聚合多个数据中心的监控数据。这一特性在Promthues中称为联邦集群。

联邦集群的核心在于每一个Prometheus Server都包含一个用于获取当前实例中监控样本的接口/federate。对于中心Prometheus Server而言,无论是从其他的Prometheus实例还是Exporter实例中获取数据实际上并没有任何差异。

集群部署架构

911490-20240924144456377-1208190196

三、部署prometheus联邦集群并抓取对应节点数据

1.中心及联邦prometheus节点部署prometheus

在 100.131 100.132 100.133三台服务器上安装prometheus,二进制部署,部署步骤略,可参考:https://www.cnblogs.com/panwenbin-logs/p/18370049 ,各节点版本保持一致

2.被采集节点安装node-exporter

在 10.134 100.135 2台服务器上二进制部署node-exporter,部署步骤略,参考:参考:https://www.cnblogs.com/panwenbin-logs/p/18370049

3.配置prometheus联邦节点采集数据

1
2
3
4
5
6
7
8
9
10
11
12
#联邦节点1
scrape_configs:
- job_name: "prod-app01"
static_configs:
- targets: ["192.168.100.134:9100"]


#联邦节点2
scrape_configs:
- job_name: "prod-app02"
static_configs:
- targets: ["192.168.100.135:9100"]

是否抓取数据正常

911490-20240924153314462-2046999070

4.配置中心prometheus server 抓取联邦节点prometheus

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#在100.131上操作
vim prometheus.yml
- job_name: 'prometheus-federate-100.132'
scrape_interval: 10s
honor_labels: true
metrics_path: '/federate'
params:
'match[]':
- '{job="prometheus"}' # {job="prometheus"} → 匹配 up(因为它的 job 标签是 "prometheus")
- '{__name__=~"job:.*"}' # {__name__=\~"job:.*"} → 匹配 job:api_requests
- '{__name__=~"node.*"}' # {__name__=\~"node.*"} → 匹配 node_cpu_seconds_total
static_configs:
- targets:
- '192.168.100.132:9090' #下面的也可以不写,把133写在此处也是可以的

- job_name: 'prometheus-federate-100.133'
scrape_interval: 10s
honor_labels: true
metrics_path: '/federate'
params:
'match[]':
- '{job="prometheus"}'
- '{__name__=~"job:.*"}'
- '{__name__=~"node.*"}'
static_configs:
- targets:
- '192.168.100.133:9090'

# 重启Prometheus
systemctl restart prometheus

web端验证

grafana图标验证

911490-20240924155321767-653618831

可以看到数据可以正常抓取及展示 

参考文档:https://prometheus.io/docs/prometheus/latest/federation/

本文转自 https://www.cnblogs.com/panwenbin-logs/p/18429140,如有侵权,请联系删除。


prometheus联邦集群配置
https://blog.t-ao.cn/2025/06/10/prometheus联邦集群配置/
作者
TAO
发布于
2025年6月10日
许可协议