prometheus幾種高可用架構介紹及聯邦架構部署

問題背景:單個prometheus性能到達瓶頸問題、多個prometheus-server數據彙總問題等node


prometheus監控數據持久化
linux

首先你們都知道prometheus是自帶數據存儲功能的。
優勢是簡單易用,基本無需配置
缺點是:一、存在數據沒法長久保存(尤爲是頻繁變動的監控對象,監控對象變化,短期內監控數據也會隨之丟失,如k8s等)
二、基於本地存儲的話,Prometheus監控系統擴展比較難
以上缺點能夠配置遠程存儲解決,使用remote_write和remote_read這兩個接口,從第三方存儲服務中進行監控數據的讀寫



git

prometheus集羣方案
這裏有篇文章介紹了幾種prometheus的集羣架構,可參考: https://zhuanlan.zhihu.com/p/86763004
github


方案一:

多個prometheus監控相同的對象。意思就是一臺node在被兩臺或兩臺以上的prometheus同時監控
缺點:對於被監控端,可能會多出一倍或以上的查詢請求
優勢:只要有一臺prometheus還在運行,就不會影響監控
prometheus幾種高可用架構介紹及聯邦架構部署
方案二:
聯邦集羣,prometheus數據層層往上匯聚(相似金字塔結構)
優勢:數據彙總展現,prometheus-worker壓力較小,如合理規劃能夠分類監控,數據保留更靈活(參考https://zhuanlan.zhihu.com/p/86763004)
缺點:prometheus-primary壓力較大,可經過配置文件使不一樣的prometheus-primary收集不一樣類的監控數據(參考同上連接)
官網描述: https://prometheus.io/docs/prometheus/latest/federation/
prometheus幾種高可用架構介紹及聯邦架構部署
這裏進行方案二+遠端存儲(influxdb)的集羣架構實現

環境:

3臺centos7的服務器,關閉防火牆、selinux












數據庫

角色分配:
*.*.6.127    prometheus-primary+influxdb+grafana
*.*.6.138    prometheus-worker
*.*.6.225    prometheus-worker

操做:
一、安裝prometheus
下載安裝包: https://prometheus.io/download/
解壓、安裝、配置成爲系統服務(3臺都操做)
prometheus幾種高可用架構介紹及聯邦架構部署
二、安裝influxdb(6.127)
yum install便可,由於是作測試,使用默認的配置文件直接啓動





centos

create database "prometheus"
create retention policy "prometheus_retention" on "prometheus" duration 4w replication 1 default
show retention policies on prometheus

建立數據庫
prometheus幾種高可用架構介紹及聯邦架構部署
默認數據保留策略爲一週,能夠新建保留策略
prometheus幾種高可用架構介紹及聯邦架構部署
prometheus幾種高可用架構介紹及聯邦架構部署
獲取prometheus鏈接遠端存儲的一個插件
github地址: https://github.com/prometheus/prometheus/tree/master/documentation/examples/remote_storage/remote_storage_adapter
執行(此插件佔用9201端口。注意紅框內容,根據本身實際內容進行更改)






服務器

nohup ./remote_storage_adapter --influxdb-url=http://127.0.0.1:8086/ --influxdb.database="prometheus" --influxdb.retention-policy=prometheus_retention &

prometheus幾種高可用架構介紹及聯邦架構部署
三、修改prometheus-worker的prometheus.yml文件
prometheus幾種高可用架構介紹及聯邦架構部署
prometheus幾種高可用架構介紹及聯邦架構部署
systemctl直接啓動prometheus便可



架構


四、修改prometheus-primary的prometheus.yml文件
ide

聯邦集羣的核心就在於每個Prometheus Server都包含一個用於獲取當前實例中監控樣本的接口/federate,對於prometheus-primary來講,從federate獲取數據跟從exporter獲取數據沒什麼區別性能

prometheus幾種高可用架構介紹及聯邦架構部署

math[]:表示你想獲取prometheus-worker裏哪些job的數據,也可使用正則匹配
honor_labels:配置true能夠確保當採集到的監控指標衝突時,可以自動忽略衝突的監控數據。若是爲false時,prometheus會自動將衝突的標籤替換爲exported_的形式。還能夠添加標籤以區分不一樣的監控目標

systemctl啓動prometheus
網頁輸入ip:9090查看
prometheus幾種高可用架構介紹及聯邦架構部署
prometheus幾種高可用架構介紹及聯邦架構部署
prometheus幾種高可用架構介紹及聯邦架構部署

五、grafana展現

經過正常的dashboard導入或者自建圖表進行數據展現
prometheus幾種高可用架構介紹及聯邦架構部署
end...文章到這裏就結束了,prometheus更靈活的高可用架構還需看真實的環境和本身的實際需求,這裏就拋磚引玉,但願你們有更好的點子能夠分享出來

相關文章
相關標籤/搜索