prometheus 密码认证之base认证

prometheus 密码认证之base认证

docker部署prometheus

一、生成加密哈希

安装加密工具

yum install -y httpd-tools

自定义密码

htpasswd -nBC 12 '' | tr -d ':\n'
然后输入密码,会出现一串加密字符串

我这里直接用工具生成

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传在这里插入图片描述

二、创建web-config.yml配置文件

basic_auth_users:
    admin: $2a$10$z58JxPndLBwFHVwTUPieGe.4ccpeaAjNeh5pth0cmylX03ECUsOoG

三、重新启动容器

version: '3'
services:
    container_name: node-exporter
    restart: unless-stopped
    hostname: node-exporter
    privileged: true
    ports:
      - "9100:9100"
    networks:
      - "prometheus"
    volumes:
      - "/opt/prometheus/node-exporter/proc:/host/proc:ro"
      - "/opt/prometheus/node-exporter/sys:/host/sys:ro"
      - "/opt/prometheus/node-exporter:/rootfs:ro"
      - "/etc/localtime:/etc/localtime"
  prom:
    image: prom/prometheus:v2.42.0
    container_name: prometheus
    restart: unless-stopped
    hostname: prometheus
    privileged: true
    ports:
      - "9090:9090"
    networks:
      - "prometheus"
    volumes:
      - "/opt/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml"
      - "/etc/localtime:/etc/localtime"
      - "/opt/prometheus/web-config.yml:/etc/prometheus/web-config.yml"
    command: 
      --web.enable-lifecycle #热加载
      --config.file=/etc/prometheus/prometheus.yml # 指定配置文件
      --web.config.file=/etc/prometheus/web-config.yml
networks:
  prometheus:
    driver: bridge

/opt/prometheus/prometheus.yml 本地prometheus的配置文件

/opt/prometheus/web-config.yml 本地prometheus的密码配置文件

注意:检查web-config.yml的语法

promtool check web-config web-config.yml

在这里插入图片描述

四、访问测试

没有用户名密码

curl --head --request GET http://localhost:9090/graph

在这里插入图片描述

有用户名密码

curl -u admin:123456 --request GET http://localhost:9090/metrics

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值