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
相关推荐
invicinble15 小时前
关于搭建运维监控系统(Prometheus+Grafana)
运维·grafana·prometheus
梵得儿SHI3 天前
(第二篇)Spring AI 架构设计与优化:可观察性体系,打造全链路可视化的 AI 运维方案
人工智能·微服务·grafana·prometheus·监控·可观察性·spring ai
川石课堂软件测试4 天前
AI如何赋能软件测试行业的发展
人工智能·python·功能测试·网络协议·单元测试·测试用例·prometheus
脏脏a4 天前
监控面板全绿但用户说网站打不开?Prometheus+Blackbox从外部验证服务真实可用性
数据库·prometheus
.柒宇.5 天前
prometheus-入门与安装
运维·服务器·prometheus·监控
川石课堂软件测试7 天前
技术分享|JMeter接口与性能测试实战
数据库·功能测试·测试工具·jmeter·单元测试·postman·prometheus
是店小二呀7 天前
Prometheus监控盲区:Pushgateway如何收拢离线任务指标
prometheus
xmlhcxr8 天前
基于 HAProxy+Keepalived 构建高可用 ZrLog 博客系统及监控平台实现(Prometheus + Grafana)
架构·grafana·prometheus
川石课堂软件测试8 天前
软件测试:典型面试题库
数据库·python·功能测试·mysql·单元测试·grafana·prometheus
何中应10 天前
Promehteus如何指定数据路径
运维·prometheus·监控