Thanos 是监控一个基于 Prometheus 实现的监控方案,其主要设计目的系统是解决原生 Prometheus 上的痛点 ,并且做进一步的实战提升 ,主要的部署特性有 :全局查询
,高可用,监控动态拓展
,系统长期存储。实战 下图是部署 Thanos 官方的架构图: Thanos是源码库一组组件,可以组合成一个具有无限存储容量的高可用指标系统,Thanos 主要由如下几个特定功能的组件组成 : 对于发送报警的流程如下所示
: Thanos 相比起原生的源码下载 Prometheus 具有以下的一些优势
: 一般来说, 我们将存储分为文件存储, 块存储和对象存储. 在了解了Thanos的架构和组件服务之后
,下面将进行实战配置安装 。准备4台虚拟机,配置如下
: --storage.tsdb.min-block-duratinotallow=5m--storage.tsdb.max-block-duratinotallow=5m 默认为2h, 修改为5分钟, sidecar向store写入数据,方便查看效果. vim /usr/lib/systemd/system/node_exporter.service Thanos 只需要两个组件就可以简单形成一个集群,query和sidecar用来抽象数据层,query 来查询抽象出来的数据层,提供查询的接口, 根据Thanos架构图,不考虑高可用的情况下除了sidecar组件外,query,store,Compactor组件只需部署一份 node1执行 这里我们采用分布式存储,在四台服务器上进行安装. 注意: data目录不可以和root目录在同一磁盘
,需要另外添加磁盘。错误信息 :ispart of root disk, will not be used (*errors.errorString) 这里指定了4台minio的地址,通过统一的minio.pw和启动文件 ,可以让4台minio做到数据互通
。minio会依次启动,顺序为参数的先后顺序 在node1 配置nginx vim /etc/nginx/conf.d/minio.conf 在 node3, node4 ,sidecar的system文件添加 在 node1 query 的system文件添加store的grpc地址 为了展示对象存储的效果,我们把node3和node4, sidecar的地址删除,只查询store的地址,这样我们就可以在grafana看到下图, 可以看到提供的信息并不是实时的,而是store写入对象存储的数据, 这只是为了测试store的可用性,实际环境中,数据的写入默认为2h一次,不符合监控实时性的要求. node1执行: compact的作用是定期把历史数据存入对象存储,其实他就像是一个cronjob, 如果发现满足了条件,就会对对象存储中的数据进行整理 创建配置文件 vim /etc/consul/server.json 创建守护进程 vim /etc/systemd/system/consul-server.service 浏览器访问 8500端口,提示需要登录 使用 consul acl bootstrap 记录SecretID 作为token 把token添加到配置文件 vim /etc/consul/server.json github 地址: https://github.com/starsliao/ConsulManager 添加镜像仓库 yum-``config``-manager--add-repo**https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 使用docker-compose来部署ConsulManager consul_token
:consul的登录token(上文获取的,SecretID) consul_url
:consul的URL(http开头,/v1要保留) admin_passwd
:登录ConsulManager Web的admin密码 启动:docker-compose pull && docker-compose up -d 访问
:http://{ IP}:1026,使用配置的ConsulManager admin密码登录 安装完成后,在平台新增监控主机的信息 添加完成后,查看consul; 配置prometheus读取consul信息; 将之前配置好的内容删除,添加生成的配置信息; 查看query, grafana,显示注册完成; 在本文中 ,我们详细探讨了Thanos监控系统的部署过程,包括系统架构介绍、各个组件的配置和完整的部署案例。Thanos为Prometheus提供了强大的监控解决方案 ,具备全局查询、高可用性、动态扩展和长期存储等特性。借助Thanos ,我们能够高效管理大规模监控数据,并通过丰富的组件和集成功能,构建一个强大而可靠的监控生态系统。我们希望本文能为那些寻求提升监控系统性能和扩展性的用户提供有价值的指导。随着技术的不断进步
,Thanos将持续发展,我们期待它在未来带来更多创新与可能性 。
图片Thanos组件
读取指标的流程
首先客户端通过 query API 向 query 发起查询,query 将请求转换成 StoreAPI 发送到其他的 query、sidecar、rule 和 store 上。sidecar 接收到来自于 query 发起的查询请求后将其转换成 query API 请求
,发送给其绑定的 Prometheus,由Prometheus 从本地读取数据并响应,返回短期的免费模板本地采集和评估数据 。rule 接收到来自于 query 发起的查询请求后直接从本地读取数据并响应,返回短期的本地评估数据。store 接收到来自于 query 发起的查询请求后首先从对象存储桶中遍历数据块的 meta.json,根据其中记录的时间范围和标签先进行一次过滤。接下来从对象存储桶中读取数据块的 index 和 chunks 进行查询,部分查询频率较高的index 会被缓存下来,下次查询使用到时可以直接读取
。最终返回长期的建站模板历史采集和评估指标。特性(优势)
对象存储
部署案例

部署Promethues
复制node3, node4 执行 useradd -s /sbin/nologin prometheus mkdir -p /app/src cd /app/src wget https://github.com/prometheus/prometheus/releases/download/v2.36.1/prometheus-2.36.1.linux-amd64.tar.gz tar -xvf prometheus-2.36.1.linux-amd64.tar.gz cd prometheus-2.36.1.linux-amd64 mv prometheus promtool /usr/local/sbin mkdir /var/lib/prometheus mv consoles console_libraries /var/lib/prometheus/ mkdir /etc/prometheus mv prometheus.yml /etc/prometheus/ chown -R prometheus:prometheus /usr/local/sbin/prometheus /usr/local/sbin/promtool /etc/prometheus/ /app/prometheus/ /var/lib/prometheus1.2.3.4.5.6.7.8.9.10.11.12.13. 修改配置文件 复制vim /etc/prometheus/prometheus.yml # 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). external_labels: replica: A # 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 its 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: ["localhost:9090"] - job_name: "node_exporter" static_configs: - targets: ["192.168.100.30:9100","192.168.100.40:9100","192.168.100.50:9100","192.168.100.60:9100"]1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42. system文件 复制vim /etc/systemd/system/prometheus.service [Unit] Descriptinotallow=prometheus Documentatinotallow=https://prometheus.io/ After=network.target [Service] Type=simple User=prometheus ExecStartPre=/usr/local/sbin/promtool check config /etc/prometheus/prometheus.yml ExecStart=/usr/local/sbin/prometheus \ --config.file=/etc/prometheus/prometheus.yml \ --web.listen-address=0.0.0.0:9090 \ --web.enable-lifecycle \ --web.enable-admin-api \ --web.console.templates=/var/lib/prometheus/console \ --web.console.libraries=/var/lib/prometheus/console_libraries \ --storage.tsdb.path=/app/prometheus/ \ --storage.tsdb.min-block-duratinotallow=5m \ --storage.tsdb.max-block-duratinotallow=5m \ --storage.tsdb.retention.time=30d \ --log.level=info ExecReload=/bin/curl -X POST http://127.0.0.1:9090/-/reload TimeoutStopSec=20s Restart=always LimitNOFILE=20480000 [Install] WantedBy=multi-user.target1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27. Node_exporter 安装
复制node1, node2, node3, node4 执行 cd /app/src wget https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz tar -xvf node_exporter-1.3.1.linux-amd64.tar.gz cd node_exporter-1.3.1.linux-amd64 mv node_exporter /usr/local/sbin/1.2.3.4.5.6. 创建system文件部署 Thanos
部署MinIO
复制node1,node2,node3,node4执行1. Minio存储架构单主机,单硬盘模式: Minio只在一台服务器上搭建服务
,且数据都存在单块磁盘上,该模式存在单点风险单主机,多硬盘模式: Minio在一台服务器上搭建服务,但数据分散在多块(大于4块)磁盘上,提供了数据上的安全保障 (类似于容器模式)多主机,多硬盘模式(分布式): 该模式是Minio服务最常用的架构 ,通过共享一个access_key和secret_key,在多台(2-32)服务器上搭建服务,且数据分散在多块(大于4块,无上限)磁盘上,提供了较为强大的数据冗余机制准备工作Thanos Store
复制node1执行 mkdir -p /app/thanos/store1.2. systemd文件vim /etc/systemd/system/thanos-store.service 复制[Unit] Descriptinotallow=thanos-store Documentatinotallow=https://thanos.io/ After=network.target [Service] Type=simple ExecStart=/usr/local/sbin/thanos store \ --data-dir=/app/thanos/store \ --objstore.config-file=/etc/thanos/thanos-minio.yml \ --http-address=0.0.0.0:10905 \ --grpc-address=0.0.0.0:10906 \ --chunk-pool-size=8GB \ --max-time=30d ExecReload=/bin/kill -HUP TimeoutStopSec=20s Restart=always LimitNOFILE=20480000 [Install] WantedBy=multi-user.targe1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19. 配置对象存储配置文件vim /etc/thanos/thanos-minio.yml 复制type: S3 config: bucket: "thanos" endpoint: "192.168.100.30:9000" access_key: "root" secret_key: "Password" insecure: true signature_version2: false http_config: idle_conn_timeout: 5m response_header_timeout: 10m insecure_skip_verify: true systemctl start thanos-store1.2.3.4.5.6.7.8.9.10.11.12.13. 
Thanos compact
Prometheus自动注册
部署Consul node2
图片
图片
图片
图片
图片
图片