prometheus增加访问认证

官网地址:

HTTPS and authentication | Prometheus

https://prometheus.io/docs/prometheus/3.0/configuration/configuration/#http_config

结合之前的看   alertManager部署安装、告警规则配置详解及告警消息推送_alertmanager 安装-CSDN博客 

version: '3.8'

services:
  prometheus:
    image: bitnami/prometheus:3.0.0
    container_name: prometheus
    hostname: prometheus
    ports:
      - "9090:9090" # Prometheus Web UI 端口
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml
      - ./prometheus-data:/prometheus
      - ./rules:/rules
      - ./webconfig.yml:/etc/prometheus/web.yml # 添加此行挂载 web 配置
      - ./tls:/etc/prometheus/tls    #使用https方式
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--web.external-url=http://192.168.118.20:9090/'   #这种方法可以走nginx
      - '--web.enable-lifecycle'
      - '--storage.tsdb.retention.time=90d'
      - "--storage.tsdb.path=/prometheus"
      - "--web.enable-admin-api"
      - "--web.config.file=/etc/prometheus/web.yml" # 添加此行引用 web 配置
    restart: always

创建webconfig.yaml

 tls_server_config:
     cert_file: /etc/prometheus/tls/server.crt
     key_file: /etc/prometheus/tls/server.key
basic_auth_users:
    admin: '$2a$10$IeiTxu.y6Hd9lCAwExctAeXc1Zf.gRVYoFgwZ.dkOWY3IO77sodoS'  # 自动生成的真实哈希

 basic_auth_users的密码加密方式  使用

方式一:linux自己生成

htpasswd -nBC 10 admin 

方式二: 使用在线 Bcrypt Generator - Online Hash Generator and Checker

使用https方式  增加 证书  简单样例  放到tls下

# Step 1: 生成自签名证书和私钥
openssl req -x509 -newkey rsa:2048 \
  -keyout server.key -out server.crt \
  -days 365 \
  -nodes \
  -subj "/C=CN/ST=Beijing/L=Beijing/O=Example/CN=localhost"

java端如何调用: 在请求头中 增加Authorization  可以;客户端访问使用base64

promAuth = Base64.getEncoder().encodeToString((promUserName + ":" +promPwd).getBytes(StandardCharsets.UTF_8));
request.header("Authorization", "Basic " + promAuth);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值