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

相关推荐
qmx_079 分钟前
HTB-Jerry(tomcat war文件、msfvenom)
java·web安全·网络安全·tomcat
小安运维日记10 分钟前
Linux云计算 |【第四阶段】NOSQL-DAY1
linux·运维·redis·sql·云计算·nosql
为风而战17 分钟前
IIS+Ngnix+Tomcat 部署网站 用IIS实现反向代理
java·tomcat
编程零零七1 小时前
Python数据分析工具(三):pymssql的用法
开发语言·前端·数据库·python·oracle·数据分析·pymssql
技术无疆2 小时前
快速开发与维护:探索 AndroidAnnotations
android·java·android studio·android-studio·androidx·代码注入
2401_858286112 小时前
52.【C语言】 字符函数和字符串函数(strcat函数)
c语言·开发语言
铁松溜达py2 小时前
编译器/工具链环境:GCC vs LLVM/Clang,MSVCRT vs UCRT
开发语言·网络
everyStudy2 小时前
JavaScript如何判断输入的是空格
开发语言·javascript·ecmascript
m0_741768854 小时前
使用docker的小例子
运维·docker·容器
C-SDN花园GGbond4 小时前
【探索数据结构与算法】插入排序:原理、实现与分析(图文详解)
c语言·开发语言·数据结构·排序算法