前邊有簡單說明過vmauth相關的參數,以下是關於配置的使用說明,以下是一個簡單的demo 說明
環境准備
- docker-compose
version: "3"
services:
prometheus:
image: prom/prometheus
ports:
- 9090:9090
volumes:
- ./promdata:/prometheus
- ./prometheus.yml:/etc/prometheus/prometheus.yml
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
vmstorage:
image: victoriametrics/vmstorage
ports:
- 8482:8482
- 8400:8482
- 8401:8482
volumes:
- ./strgdata:/storage
command:
- '--storageDataPath=/storage'
vmauth:
image: victoriametrics/vmauth
volumes:
- "./config.yaml:/etc/victoriametrics/config.yaml"
command:
- '-auth.config=/etc/victoriametrics/config.yaml'
ports:
- 8427:8427
vminsert:
image: victoriametrics/vminsert
command:
- '--storageNode=vmstorage:8400'
ports:
- 8480:8480
vmselect:
image: victoriametrics/vmselect
command:
- '--storageNode=vmstorage:8401'
ports:
- 8481:8481
grafana:
image: grafana/grafana
ports:
- 3000:3000
- 配置說明
此處是比較重要的
vmauth 配置
注意vmauth內部使用的httputil.ReverseProxy,需要提供基於用戶id 的標示(使用nginx 的auth 指令更好點,靈活)所以id 必須唯一
同時需要提供讀以及寫的賬戶
users:
- username: "dalong-select-account-1"
password: "dalong"
url_prefix: "http://vmselect:8481/select/1/prometheus"
- username: "dalong-insert-account-1"
password: "dalong"
url_prefix: "http://vminsert:8480/insert/1/prometheus"
prometheus 配置(主要是remote_write 配置) 注意url 需要使用vmauth的同時添加basic auth 的信息
global:
scrape_interval: 1s
evaluation_interval: 1s
remote_write:
- url: "http://vmauth:8427"
basic_auth:
username: dalong-insert-account-1
password: dalong
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['prometheus:9090']
- job_name: 'vminsert'
static_configs:
- targets: ['vminsert:8480']
- job_name: 'vmselect'
static_configs:
- targets: ['vmselect:8481']
- job_name: 'vmstorage'
static_configs:
- targets: ['vmstorage:8482']
- 啟動
docker-compose up -d
使用
- grafana 配置
- 數據查詢效果
說明
基於vmauth的認證模式目前還是比較簡單的,主要是靜態配置,如果需要更靈活的擴展,可以基於nginx 配置使用
ngx_http_auth_request_module 或者openresty 也是不錯的選擇
參考資料
https://www.cnblogs.com/rongfengliang/p/12794210.html
https://github.com/VictoriaMetrics/VictoriaMetrics/wiki/vmauth
http://mdounin.ru/hg/ngx_http_auth_request_module/
https://github.com/openresty/lua-nginx-module#access_by_lua