提到thanos,一般会介绍prometheus监控系统,它能够实时查询数百万个指标数据,并提供一套强大的查询语言,用户可以通过该语言从这些指标数据中提取有用的信息,但是大规模prometheus集群会存在一些问题,thanos就是为了解决这些问题而存在:
thanos是由一系列组件构成,通过thanos可以实现一个高可用的指标系统,并且拥有无限的数据存储能力,可以和现有的prometheus集群无缝集成,单实例prometheus依然高效,只有在对现有prometheus实例进行扩展时,才建议使用thanos,thanos让prometheus更易用,使用thanos能完成以下功能:
一个二进制文件提供所有组件功能:
$ thanos sidecar
$ thanos query
$ thanos store
$ thanos compact
1 高可用 (sidecar + query)
通过thanos sidecar与每个prometheus实例一起运行,可以运行多个prometheus实例,共同形成一个集群,借助query组件提供统一的指标数据查询入口,且确保服务的高可用。
2 全局视图(query)
query组件提供统一的指标数据查询入口,通过聚合所有集群的query,可以同时查询多个prometheus实例的指标数据,并且可以将重复的指标数据去重。
3 数据存储(sidecar + store)
thanos sidecar不断将指标数据备份到云存储,然后通过store组件查询存储的数据,store类似在集群中存在一个prometheus实例,但是该prometheus实例的指标数据都是来自sidecar上传的云存储。
1 将thanos sidecar添加到prometheus服务端
2 部署多个querier副本获取数据查询和浏览功能
3 创建云存储,配置sidecar将数据备份到云端对象存储系统
4 部署store gateway以便访问备份的指标数据
5 部署compacter,实现数据的压缩和降准采样以提升长期数据查询的响应能力
这里介绍以docker方式安装thanos,先安装2个prometheus集群,分别是eu1和us1,在us1中运行2个prometheus实例,prometheus配置如下:
prometheus实例0配置prometheus0_eu1.yml
global:
scrape_interval: 15s
evaluation_interval: 15s
external_labels:
cluster: eu1
replica: 0
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['127.0.0.1:9090']
- job_name: 'sidecar'
static_configs:
- targets: ['127.0.0.1:19090']
prometheus实例0配置prometheus0_us1.yml:
global:
scrape_interval: 15s
evaluation_interval: 15s
external_labels:
cluster: us1
replica: 0
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['127.0.0.1:9091','127.0.0.1:9092']
- job_name: 'sidecar'
static_configs:
- targets: ['127.0.0.1:19091','127.0.0.1:19092']
prometheus实例1配置prometheus1_us1.yml:
global:
scrape_interval: 15s
evaluation_interval: 15s
external_labels:
cluster: us1
replica: 1
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['127.0.0.1:9091','127.0.0.1:9092']
- job_name: 'sidecar'
static_configs:
- targets: ['127.0.0.1:19091','127.0.0.1:19092']
创建prometheus集群和thanos:
mkdir -p prometheus0_eu1_data prometheus0_us1_data prometheus1_us1_data
docker run -d --net=host --rm \
-v $(pwd)/prometheus0_eu1.yml:/etc/prometheus/prometheus.yml \
-v $(pwd)/prometheus0_eu1_data:/prometheus \
-u root \
--name prometheus-0-eu1 \
quay.io/thanos/prometheus:v2.12.0-rc.0-rr-streaming \
--config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path=/prometheus \
--web.listen-address=:9090 \
--web.enable-lifecycle \
--web.enable-admin-api && echo "Prometheus EU1 started!"
docker run -d --net=host --rm \
-v $(pwd)/prometheus0_us1.yml:/etc/prometheus/prometheus.yml \
-v $(pwd)/prometheus0_us1_data:/prometheus \
-u root \
--name prometheus-0-us1 \
quay.io/thanos/prometheus:v2.12.0-rc.0-rr-streaming \
--config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path=/prometheus \
--web.listen-address=:9091 \
--web.enable-lifecycle \
--web.enable-admin-api && echo "Prometheus 0 US1 started!"
docker run -d --net=host --rm \
-v $(pwd)/prometheus1_us1.yml:/etc/prometheus/prometheus.yml \
-v $(pwd)/prometheus1_us1_data:/prometheus \
-u root \
--name prometheus-1-us1 \
quay.io/thanos/prometheus:v2.12.0-rc.0-rr-streaming \
--config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path=/prometheus \
--web.listen-address=:9092 \
--web.enable-lifecycle \
--web.enable-admin-api && echo "Prometheus 1 US1 started!"
docker run -d --net=host --rm \
-v $(pwd)/prometheus0_eu1.yml:/etc/prometheus/prometheus.yml \
--name prometheus-0-sidecar-eu1 \
-u root \
quay.io/thanos/thanos:v0.7.0 \
sidecar \
--http-address 0.0.0.0:19090 \
--grpc-address 0.0.0.0:19190 \
--reloader.config-file /etc/prometheus/prometheus.yml \
--prometheus.url http://127.0.0.1:9090 && echo "Started sidecar for Prometheus 0 EU1"
docker run -d --net=host --rm \
-v $(pwd)/prometheus0_us1.yml:/etc/prometheus/prometheus.yml \
--name prometheus-0-sidecar-us1 \
-u root \
quay.io/thanos/thanos:v0.7.0 \
sidecar \
--http-address 0.0.0.0:19091 \
--grpc-address 0.0.0.0:19191 \
--reloader.config-file /etc/prometheus/prometheus.yml \
--prometheus.url http://127.0.0.1:9091 && echo "Started sidecar for Prometheus 0 US1"
docker run -d --net=host --rm \
-v $(pwd)/prometheus1_us1.yml:/etc/prometheus/prometheus.yml \
--name prometheus-1-sidecar-us1 \
-u root \
quay.io/thanos/thanos:v0.7.0 \
sidecar \
--http-address 0.0.0.0:19092 \
--grpc-address 0.0.0.0:19192 \
--reloader.config-file /etc/prometheus/prometheus.yml \
--prometheus.url http://127.0.0.1:9092 && echo "Started sidecar for Prometheus 1 US1"
docker run -d --net=host --rm \
--name querier \
quay.io/thanos/thanos:v0.7.0 \
query \
--http-address 0.0.0.0:29090 \
--query.replica-label replica \
--store 127.0.0.1:19190 \
--store 127.0.0.1:19191 \
--store 127.0.0.1:19192 && echo "Started Thanos Querier"
prometheus访问入口如下:
thanos访问入口如下:
ref:
LEo at 00:12