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
相关推荐
鬼先生_sir5 小时前
Spring Cloud 微服务监控实战:SkyWalking + Prometheus+Grafana 全栈解决方案
运维·spring cloud·grafana·prometheus·skywalking
zs宝来了2 天前
Prometheus 监控体系原理:Pull 模式与 TSDB 时序数据库
prometheus·时序数据库·监控·tsdb·pull模式
何中应3 天前
Alertmanager设置邮件通知
运维·自动化·prometheus
安审若无3 天前
运维监控及可视化工具Prometheus和grafana
运维·grafana·prometheus
却话巴山夜雨时i3 天前
互联网大厂Java面试实录:从Spring Boot到Kafka的场景应用深度解析
spring boot·kafka·prometheus·微服务架构·java面试·技术解析·互联网大厂
却话巴山夜雨时i4 天前
Java面试实录:从Spring Boot到Kafka的技术探讨
spring boot·微服务·kafka·grafana·prometheus·java面试
川石课堂软件测试7 天前
涨薪技术|Prometheus使用Recoding Rules优化性能
功能测试·测试工具·jmeter·mysql·面试·单元测试·prometheus
yunson_Liu7 天前
prometheus添加es监控模块
elasticsearch·prometheus
杜子不疼.8 天前
Prometheus Pushgateway:批量离线任务指标监控实践
prometheus
我还为发觉9 天前
Linux 监控可视化|Prometheus+Node Exporter 一键部署教程
linux·运维·prometheus