VictoriaMetrics vmauth 使用
前边有简单说明过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