深入浅出

深入浅出

    正在检查是否收录...

前言

书接上文,目前环境已经做好了水平拆分,是这个样子的

prometheus_6_1

本文使用thanos对这些prometheus进行数据汇聚,并且详细讨论一下thanos

环境准备

组件 版本
操作系统 Ubuntu 22.04.4 LTS
docker 24.0.7
thanos 0.36.1

thanos概述

thanos主要有4个组件

  • receive:独立部署,提供了数据写入的api,prometheus通过这个api把数据推送到receive的对象存储
  • sidecar:与prometheus部署在一起,成为prometheus的sidecar,负责把prometheus本地的数据上传至对象存储当中
  • query:独立部署,是一个兼容了prometheus的查询组件,汇总了来自不同来源的查询结果,并且可以从Sidecar和Store中读取数据
  • store:独立部署,提供了对象数据存储功能,并且提供相关的api,query通过该api查询历史数据

thanos有两种工作模式,receive与sidecar

receive模式

Receive 是一个可以接收来自 Prometheus 远程写入的数据的组件,主要用于高可用的集群环境中。它能够处理来自多个 Prometheus 实例的写入请求

prometheus_6_2

1. 部署thanos receive

▶ mkdir -p data && chmod 777 data ▶ docker run -d --net=host \ --name thanos-receive \ -v "./data:/data" \ registry.cn-beijing.aliyuncs.com/wilsonchai/thanos:0.36.1 \ receive \ --grpc-address 0.0.0.0:10907 \ --http-address 0.0.0.0:10909 \ --receive.replication-factor 1 \ --label "receive_cluster=\"wilson-test\"" \ --remote-write.address 0.0.0.0:10908 

2. 改造prometheus

分别对3个prometheus进行改造,分别修改其configmap

  • 负责采集k8s监控数据
... scrape_configs: ... remote_write: - url: "http://10.22.11.156:10908/api/v1/receive" write_relabel_configs: - action: replace source_labels: [] target_label: from replacement: "prometheus-k8s" 
  • 负责采集node监控数据
... scrape_configs: ... remote_write: - url: "http://10.22.11.156:10908/api/v1/receive" write_relabel_configs: - action: replace source_labels: [] target_label: from replacement: "prometheus-node" 
  • 负责采集pushgateway监控数据
... scrape_configs: ... remote_write: - url: "http://10.22.11.156:10908/api/v1/receive" write_relabel_configs: - action: replace source_labels: [] target_label: from replacement: "prometheus-pushgateway" 

3. 部署thanos query

docker run -d --net=host \ --name thanos-query \ registry.cn-beijing.aliyuncs.com/wilsonchai/thanos:0.36.1 \ query \ --http-address "0.0.0.0:39090" \ --grpc-address "0.0.0.0:39091" \ --store "127.0.0.1:10907" 

登录thanos-query提供的web界面http://127.0.0.1:39090/,可以看到3个prometheus节点的数据都已汇聚,并且已经标注了来源,from标签

4. 部署对象存储 minio

目前我们的数据还是存储在receive的本地磁盘上的,为了长期保留数据,将其推送至自建的对象存储当中

prometheus_6_3

创建minio

docker run -d --name minio --net host \ -e "MINIO_ACCESS_KEY=minioadmin" \ -e "MINIO_SECRET_KEY=minioadmin" \ -v ./data:/data \ -v ./config:/root/.minio \ registry.cn-beijing.aliyuncs.com/wilsonchai/minio:RELEASE.2024-10-13T13-34-11Z \ server /data --console-address ":9000" -address ":9090" 

通过用户名密码登录web页面http://127.0.0.1:9000/,然后创建bucket,再创建access key

回到thanos,创建bucket.yml文件

type: S3 config: bucket: "wilson-test" endpoint: "127.0.0.1:9090" access_key: "zzUrkBzyqcCDXySsMLlS" secret_key: "nWCcztESnxnUZIKSKsELGEFdg6l6fjzhtqkARJB8" insecure: true 

最后重建thanos receive

docker run -d --net=host \ --name thanos-receive \ -v ./bucket.yml:/etc/thanos/bucket.yml \ -v "./data:/data" \ registry.cn-beijing.aliyuncs.com/wilsonchai/thanos:0.36.1 \ receive \ --grpc-address 0.0.0.0:10907 \ --http-address 0.0.0.0:10909 \ --objstore.config-file=/etc/thanos/bucket.yml \ --tsdb.retention=2d \ --label "receive_cluster=\"wilson-test\"" \ --remote-write.address 0.0.0.0:10908 

默认情况下每个2小时,thanos就会往对象存储当中推送数据,这个时间可以调整,只需要调整以下参数即可

 --tsdb.min-block-duration=10m \ --tsdb.max-block-duration=10m \ 

检查minio的控制台,检查是否成功上传

prometheus_6_4

5. 部署thanos-store,直接读取对象存储

store gateway就是简单的去读取对象存储当中的数据,通过 api暴露给thanos-query,thanos-query调用store api然后获取数据,这样就可以直接读取对象存储的数据了

prometheus_6_6

部署store

docker run -d --net=host \ --name thanos-store \ -v "./data-store:/data" \ -v ./bucket.yml:/etc/thanos/bucket.yml \ registry.cn-beijing.aliyuncs.com/wilsonchai/thanos:0.36.1 \ store \ --objstore.config-file "/etc/thanos/bucket.yml" 

这里的bucket.yaml,还是沿用了上面的bucket.yaml,指向同样的对象存储

调整thanos-query的配置,新增thanos-store的地址

docker run -d --net=host \ --name thanos-query \ registry.cn-beijing.aliyuncs.com/wilsonchai/thanos:0.36.1 \ query \ --http-address "0.0.0.0:39090" \ --grpc-address "0.0.0.0:39091" \ --store "127.0.0.1:10907" \ --store "127.0.0.1:10901" 

127.0.0.1:10901就是新增的store的grpc地址,添加完毕后,检查thanos-query的web页面

prometheus_6_5

thanos-query的数据源来自两个地方,一个是receive,一个是store,并且thanos-query有自动去重的功能,真牛皮!

6. 小结

  • 以上就是receive模式的基本使用方法,在receive模式中,使用了receive、query、store等组件,并且展示了它们之间如何协调合作
  • 上述演示的对象存储,是自建的minio,在实际工作中,可以使用云厂商的对象存储相互配合,易于管理

联系我

  • 联系我,做深入的交流

至此,本文结束
在下才疏学浅,有撒汤漏水的,请各位不吝赐教...

本文来自博客园,作者:it排球君,转载请注明原文链接:https://www.cnblogs.com/MrVolleyball/p/18996229

本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文连接,否则保留追究法律责任的权利。
  • 本文作者:WAP站长网
  • 本文链接: https://wapzz.net/post-27005.html
  • 版权声明:本博客所有文章除特别声明外,均默认采用 CC BY-NC-SA 4.0 许可协议。
本站部分内容来源于网络转载,仅供学习交流使用。如涉及版权问题,请及时联系我们,我们将第一时间处理。
文章很赞!支持一下吧 还没有人为TA充电
为TA充电
还没有人为TA充电
0
0
  • 支付宝打赏
    支付宝扫一扫
  • 微信打赏
    微信扫一扫
感谢支持
文章很赞!支持一下吧
关于作者
2.8W+
9
1
2
WAP站长官方

AI仙侠玄幻剧:用离谱和技术给你们一点震撼

上一篇

微信视频号:开展直播团播低俗内容专项治理行动

下一篇
评论区
内容为空

这一切,似未曾拥有

  • 复制图片
按住ctrl可打开默认菜单