prometheus联邦模式部署
1. 结构图如下:

2. 实验地址规划
| ip | 角色 | 主机名 |
|---|---|---|
| 192.168.25.250 | prometheus主节点 | prometheus-master |
| 192.168.25.251 | A机房监控汇聚 | prometheus01 |
| 192.168.25.252 | B机房监控汇聚 | prometheus02 |
| 192.168.25.253 | A机房服务器 | prometheus01-01 |
| 192.168.25.197 | B机房服务器 | prometheus02-01 |
3. 部署联邦模式
3.1. 先完成服务器监控汇聚

A B 机房服务器安装node-export插件
docker run -d \
--net="host" \
--pid="host" \
-v "/:/host:ro,rslave" \
prom/node-exporter:latest \
--path.rootfs=/host
prometheus01和prometheus01搭建:
配置文件修改:
prometheus01:
prometheus.yml:
global:
alerting:
alertmanagers:
- static_configs:
- targets:
rule_files:
scrape_configs:
# 监控自己 job的名称都需要带有prometheus后面需要匹配
- job_name: "prometheus-01"
static_configs:
- targets: ["localhost:9090"]
labels:
app: "prometheus"
# 监控prometheus01-01服务器
- job_name: "prometheus-node"
static_configs:
- targets:
- 192.168.25.253:9100
prometheus02:
prometheus.yml:
global:
alerting:
alertmanagers:
- static_configs:
- targets:
rule_files:
scrape_configs:
# 监控自己 job的名称都需要带有prometheus后面需要匹配
- job_name: "prometheus-02"
static_configs:
- targets: ["localhost:9090"]
labels:
app: "prometheus"
# 监控prometheus02-01服务器
- job_name: "prometheus-node"
static_configs:
- targets:
- 192.168.25.197:9100
两台都启动Prometheus:
docker run -d --net host -v ./prometheus.yml:/etc/prometheus/prometheus.yml:ro prom/prometheus
确保都能监控到自己和所属节点:

3.2 prometheus主节点部署
prometheus.yml:
global:
scrape_interval: 15s
evaluation_interval: 15s
alerting:
alertmanagers:
- static_configs:
- targets:
rule_files:
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
labels:
app: "prometheus"
- job_name: 'prometheus-01'
scrape_interval: 10s
honor_labels: true
metrics_path: '/federate'
params:
'match[]':
- '{job="prometheus"}'
- '{__name__=~"job:.*"}'
- '{__name__=~"node.*"}'
static_configs:
- targets: ["192.168.25.251:9090"]
- job_name: 'prometheus-02'
scrape_interval: 10s
honor_labels: true
metrics_path: '/federate'
params:
'match[]':
- '{job="prometheus"}'
- '{__name__=~"job:.*"}'
- '{__name__=~"node.*"}'
static_configs:
- targets: ["192.168.25.252:9090"]
启动:
docker run -d --net host -v ./prometheus.yml:/etc/prometheus/prometheus.yml:ro prom/prometheus
docker run -d --name=grafana -p 3000:3000 grafana/grafana

联邦服务器已经监控上了,需要访问grafana才能看到具体监控的服务器。

添加prometheus-master数据源后,能看到prometheus02-01和prometheus01-01 服务器。
8248

被折叠的 条评论
为什么被折叠?



