Prometheus启用认证——筑梦之路

Prometheus于2.24版本(包括2.24)之后提供Basic Auth功能进行加密访问,在浏览器登录UI的时候需要输入用户密码,访问Prometheus api的时候也需要加上用户密码。

bash 复制代码
查看版本

prometheus --version

# python脚本生成加密串


import bcrypt

def genPass():
    password = input("请输入密码: ")
    hashed = bcrypt.hashpw(password.encode("utf-8"), bcrypt.gensalt())
    print(hashed.decode())

if __name__ == "__main__":
    genPass()

# 添加配置

# set basic auth
basic_auth_users:
  admin: $2b$12$eBDOMdrUnLuzzp7cRy7Kp.0lhQcYi7gy2dSH2xexotT2lMX1n9aly

# 校验配置

./promtool check web-config web-config.yml 


# prometheus.yml配置修改

# my global config
global:
  scrape_interval: 15s
  evaluation_interval: 15s

alerting:
  alertmanagers:
    - static_configs:
        - targets:

rule_files:

scrape_configs:
  - job_name: "prometheus"
    basic_auth:
      username: admin
      password: 123456
    static_configs:
      - targets: ["localhost:9090"]
        labels:
          app: "prometheus"
  - job_name: "node_wlinux01"
    static_configs:
      - targets: ["192.168.139.131:9100"]
        labels:
          app: "node_wlinux01"



# 启动脚本参考


[Unit]
Description=prometheus service
After=network.target
[Service]
User=prometheus
ExecStart=/usr/bin/prometheus --config.file=/opt/prometheus/prometheus.yml \
          --storage.tsdb.path=/var/lib/prometheus \
          --web.config.file=/opt/prometheus/web-config.yml
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -QUIT $MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
相关推荐
龙腾-虎跃4 小时前
Docker 一键启动服务合集:Redis、MySQL、Kafka、MinIO、Prometheus 等(网盘转存防失效)
redis·mysql·docker·kafka·prometheus·小龙虾·miniio
Duang007_1 天前
生产可观测性:从“系统慢“到“根因“的完整链路(Go / TypeScript)
后端·python·golang·typescript·prometheus
JWASX1 天前
go 学习 - prometheus 指标学习
学习·golang·prometheus
JWASX1 天前
go 学习 - prometheus 指标协程池监控
学习·golang·prometheus
爱琴孩3 天前
记一次Prometheus的WAL异常,导致服务器磁盘占用过高
prometheus·wal
Cheney Pan4 天前
第12篇 Prometheus 高可用与长期存储
prometheus
飞鸟真人4 天前
应用性能监测(APM)之 (五)Prometheus与OpenMetrics协议
prometheus·apm·open telemetry·openmetrics
Cheney Pan4 天前
第13篇 监控安全与权限治理
安全·prometheus
蓝胖的四次元口袋6 天前
Prometheus+Grafana知识梳理(2)
grafana·prometheus
Cheney Pan7 天前
第8篇 关键指标分析方法:RED/USE 与黄金信号
prometheus