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

相关推荐
bug总结几秒前
新学一个JavaScript 的 classList API
开发语言·javascript·ecmascript
小猫猫猫◍˃ᵕ˂◍几秒前
备忘录模式:快速恢复原始数据
android·java·备忘录模式
Nicole Potter7 分钟前
请说明C#中的List是如何扩容的?
开发语言·面试·c#
liuyuzhongcc9 分钟前
List 接口中的 sort 和 forEach 方法
java·数据结构·python·list
五月茶13 分钟前
Spring MVC
java·spring·mvc
sjsjsbbsbsn22 分钟前
Spring Boot定时任务原理
java·spring boot·后端
yqcoder23 分钟前
Express + MongoDB 实现在筛选时间段中用户名的模糊查询
java·前端·javascript
bugtraq202137 分钟前
XiaoMi Mi5(gemini) 刷入Ubuntu Touch 16.04——安卓手机刷入Linux
linux·运维·ubuntu
xmweisi43 分钟前
【华为】报文统计的技术NetStream
运维·服务器·网络·华为认证
十八朵郁金香1 小时前
通俗易懂的DOM1级标准介绍
开发语言·前端·javascript