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
相关推荐
广目软件10 小时前
HA分布式架构采集节点变更操作手册20261029
运维·服务器·ansible·zabbix·prometheus
tianyuanwo5 天前
Prometheus 服务部署指南:从架构原理到生产级落地
架构·prometheus
看浪的路人7 天前
第8讲:记忆系统的监控与运维——Prometheus 指标、Grafana 面板与告警体系
运维·grafana·prometheus
爬也要爬着前进9 天前
Prometheus通过Nginx-vts-exporter模块监控nginx服务
运维·nginx·prometheus
Crayon Lin9 天前
Prometheus
prometheus
川石课堂软件测试11 天前
JMeter异步接口测试实战
数据库·python·jmeter·mysql·kubernetes·测试用例·prometheus
lbb 小魔仙14 天前
Redis运行状态总靠手动查?我用redis_exporter+Prometheus把指标、告警和远程抓取全接起来了
redis·bootstrap·prometheus
程序员-Benothing14 天前
Linux系统监控工具全家桶:sar、dstat、glances、Prometheus
linux·运维·prometheus
wzq11_66615 天前
Prometheus监控——云原生与非云原生监控
云原生·prometheus
东风微鸣15 天前
把 Tailscale 接进 Prometheus 监控
java·数据库·prometheus