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
相关推荐
玉&心1 天前
在grafana中引入prometheus的数据监控
grafana·prometheus
Dovis(誓平步青云)1 天前
从Redis指标采集到异常告警:redis_exporter + Prometheus 完整实战
服务器·数据库·人工智能·redis·架构·prometheus·vibe coding
吉甫作诵3 天前
Prometheus 安装配置:Consul 自动发现与 Thanos Sidecar 持久化
prometheus·consul
溜达的大象3 天前
Prometheus怎么监控没有公网IP的服务器?Node Exporter远程采集实战
服务器·tcp/ip·prometheus
Livia要学习8 天前
Prometheus架构解析
prometheus
云烟成雨TD9 天前
Micrometer 系列【63】统一观测:基于 Spring Boot 的生产级演示案例 | 基于 OTLP 集成 Prometheus + Jaeger
spring boot·云原生·prometheus
江南风月12 天前
如何使用WGCLOUD实现智能运维
运维·zabbix·运维开发·prometheus
凤山老林14 天前
可观测性落地:Spring Boot 3.x + Actuator + Prometheus + Grafana 监控体系搭建
spring boot·grafana·prometheus
企鹅郁金香16 天前
部署搭建 Prometheus 和 Grafana教程
eureka·grafana·prometheus
云边有个稻草人16 天前
Ubuntu部署Prometheus与Alertmanager:服务接入和远程监控
数据库·ubuntu·prometheus