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

相关推荐
双叶8362 分钟前
(51单片机)串口通讯(串口通讯教程)(串口接收发送教程)
c语言·开发语言·c++·单片机·嵌入式硬件·microsoft·51单片机
顾林海5 分钟前
深度解析LinkedHashSet工作原理
android·java·面试
创码小奇客10 分钟前
Java 对象变形记:BeanUtils 与 MapStruct 的高阶魔法实战
java·spring boot·trae
豆浆Whisky21 分钟前
深入剖析Go Channel:从底层原理到高阶避坑指南|Go语言进阶(5)
后端·go
申城异乡人22 分钟前
Spring RestTemplate使用方法总结
java
Pseudo…26 分钟前
linux shell编程规范与变量(一)
linux·运维·服务器
写bug写bug26 分钟前
Lua语言教程:从基础到进阶
后端·lua
normaling27 分钟前
XML配置文件
后端
Gold Steps.28 分钟前
基于Kubeadm实现K8S集群扩缩容指南
运维·容器·k8s
Z字小熊饼干爱吃保安39 分钟前
nginx介绍和几种安装方法
linux·运维·nginx·云计算