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的错误。

相关推荐
jiayong239 分钟前
知识库概念与核心价值01
java·人工智能·spring·知识库
皮皮林55122 分钟前
告别 OOM:EasyExcel 百万数据导出最佳实践(附开箱即用增强工具类)
java
kylezhao201923 分钟前
C# 语言基础(变量、数据类型、流程控制、面向对象编程)
开发语言·计算机视觉·c#·visionpro
咯哦哦哦哦29 分钟前
WSL + ubantu22.04 + 远程桌面闪退+黑屏闪退解决
linux·开发语言
fantasy5_536 分钟前
Linux 动态进度条实战:从零掌握开发工具与核心原理
linux·运维·服务器
翩若惊鸿_44 分钟前
【无标题】
开发语言·c#
weixin_462446231 小时前
exo + tinygrad:Linux 节点设备能力自动探测(NVIDIA / AMD / CPU 安全兜底)
linux·运维·python·安全
..过云雨1 小时前
17-2.【Linux系统编程】线程同步详解 - 条件变量的理解及应用
linux·c++·人工智能·后端
Da Da 泓1 小时前
多线程(七)【线程池】
java·开发语言·线程池·多线程
莫逸风1 小时前
【局域网服务方案】:无需找运营商,低成本拥有高性能服务器
运维·服务器