Promethues的Agent 模式代理转发的实施教程

目录

一、为什么需要代理转发?

[二、Prometheus Agent模式的实施步骤](#二、Prometheus Agent模式的实施步骤)

1、升级Prometheus的版本

2、配置B服务器的配置文件

3、启动代理点B服务器的Prometheus

4、接收端C服务器的Prometheus的安装同步骤1

5、启动接收端C服务器的Prometheus

6、验证是否能够正确接收到代理点B服务器写入的指标值


一、为什么需要代理转发?

为什么需要一个中间代理呢?这样加一层不是脱裤子放屁,多此一举吗?正常情况来说是多此一举。但是,在有些场景就是不得不加这一层。比如现在有A、B、C三台服务器。A和B服务器网络是互通的,B和C是网络互通的,A和C网络不互通。但是,此时promethues服务端是装在C服务器的,代理端agent是安装在A服务器的。这个时候因为A和C网络是不通的,所以安装在C服务器的代理端agent就无法将采集的指标数据推送到C服务器上的Prometheus服务端。

这个时候,也就是需要使用promethues的agent模式。在中间服务器,也就是经常说的DMZ区服务器(DMZ区是网络安全架构中的一个重要概念,它起到了隔离内外部网络的作用。),这里也就是B服务器上再安装一个Prometheus,让A服务器的agent将采集的指标数据推送到B服务器的Prometheus上。然后,B服务器的Prometheus再将接收的指标数据远程写入到C服务器的Prometheus。

注意:Agent 模式是针对特定使用场景的,标准模式的 Promethues Server 更稳定、更易维护,仍是缺省建议。

二、Prometheus Agent模式的实施步骤

1、升级Prometheus的版本

需要确定promethues的版本是否在2.19.2以上,因为Prometheus在2.19.2以上才支持 Agent 模
式。
如果不满足版本要求,则需要重新安装,安装步骤如下(之前版本直接停掉即可,重新启动新安装的版本,配置文件使用之前版本即可)

1.1 下载安装包
wget https://github.com/prometheus/prometheus/releases/download/v2.36.0/prometheus-
2.36.0.linux-amd64.tar.gz
1.2 解压安装
tar -zvxf prometheus-2.36.0.linux-amd64.tar.gz

2、配置B服务器的配置文件

在代理点的 prometheus.yml 配置文件中加入转发目标 Prometheus 地址以及需要拉取的 exporter 的
信息。

my global config

global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.

scrape_timeout is set to the global default (10s).

Alertmanager configuration

alerting:
alertmanagers:

  • static_configs:
  • targets:

- alertmanager:9093

Load rules once and periodically evaluate them according to the global 'evaluation_interval'.

rule_files:

- "first_rules.yml"

- "second_rules.yml"

A scrape configuration containing exactly one endpoint to scrape:

Here it's Prometheus itself.

scrape_configs:

The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.

  • job_name: "prometheus"

metrics_path defaults to '/metrics'

scheme defaults to 'http'.

static_configs:

  • targets: "10.200.5.78:19090"
    #需要拉取的exporter配置信息
  • job_name: 'nginx-process'
    static_configs:
  • targets: '172.18.1.246:9256'
    metric_relabel_configs:
  • source_labels: 'groupname'
    target_label: 'subCode'
    replacement: $1
    action: replace

#配置转发到哪台服务器的信息
remote_write:

Agent is able to run with a invalid remote-write URL, but, of course, will fail to push timeseries.

3、启动代理点B服务器的Prometheus
复制代码
 nohup ./prometheus --config.file=prometheus.yml --web.listen-address=0.0.0.0:19090   &
4、接收端C服务器的Prometheus的安装同步骤1
5、启动接收端C服务器的Prometheus

在接收端Prometheus启动命令后加上 --web.enable-remote-write-receiver ,如下

复制代码
 nohup ./prometheus --config.file=prometheus.yml --web.listen-address=0.0.0.0:19090  --web.enable-remote-write-receiver  &
6、验证是否能够正确接收到代理点B服务器写入的指标值

浏览器打开http://10.3.6.8:19090/graph 在接收端Prometheus的管理端搜索代理点搜集的指标,看是否能够查询到,如果能查询到,便是采集成功,否则为失败。

如果,查询不到,可以在代理服务器去查询,如果也查询不到,就需要检查是不是代理服务器到export所在服务器的网络是不是不通,或者是不是在2步骤中配置写的有问题。

注意:代理服务器和目标服务器的时间要同步,不然会出现out of bounds的错误。

相关推荐
斯维赤几秒前
OCR到底是接入第三方API 还是自己封装?
java·ocr
kiracrimson2 分钟前
STL:List的使用和模拟实现
开发语言·c++·list
利威尔xu6 分钟前
Go IM 源码实战(11):token 只是个 HASH,多端互踢的顺序错了就踢错人
后端·微服务·面试·架构·golang
码智社17 分钟前
Redis 哨兵模式详解:从原理到生产实践
java·redis
救救孩子把26 分钟前
结构化输出为何“格式正确、答案错误”?JSON Schema 的能力边界
android·java·json·agent·agent服务
猿究院--Cu-Sn合金29 分钟前
Spring Boot + DeepSeek 求职 Agent 实践:工具注册、多轮调用与简历 JD 对比
数据库·人工智能·spring boot·后端·deepseek
程序员cxuan30 分钟前
别学 subagent 了,很可能要凉了。
后端·agent·ai编程
小咕聊编程36 分钟前
基于Django的个人摄影博客网站设计与开发
后端·python·django
北冥you鱼38 分钟前
Go 语言 GORM 使用 Preload:从关联查询到嵌套预加载的完整实践
开发语言·jvm·golang
无足鸟ICT40 分钟前
【RHCA+】影响Linux系统性能的因素
linux·运维·服务器