一文掌握Prometheus实现页面登录认证并集成grafana

一、接入方式

以保护Web站点的访问控制,如HTTP 服务器配置中实现安全的加密通信和身份验证,保护 Web 应用程序和用户数据的安全性。
1.1 加密密码

通过httpd-tools工具包来进行Web站点加密

复制代码
yum install -y httpd-tools

方式一:通过htpasswd生成加密密码

复制代码
htpasswd -nBC 12 '' | tr -d ':\n'

New password: # 这里输入密码

Re-type new password: # 再次输入密码

#根据输入的密码会生成如下加密

#生成的密码信息

方式二:使用下面的脚本生成密码

复制代码
yum install -y httpd-tools;

替换对应的password信息为你需要设置的密码

复制代码
UserAndPassword=`htpasswd -nBbC 12 user 'password'`;
Password=${UserAndPassword#*:};
echo ${Password}

1.2. 配置config.yml文件

复制代码
vim basic_auth.yaml

basic_auth_users:
  prometheus: $2y$12$mMnPuKlOQ97fdssDsQTMukAdssQrCN0vefs0CBLe/hi6

1.3. 启动参数添加

如果是docker启动的话,添加如下启动参数:

复制代码
--web.config.file=/etc/passwd/basic_auth.yaml

1.4. docker-compose启动

复制代码
docker network create skyeye

step1:编写docker-compose文件

复制代码
vim docker-compose.yml

version: '3.8'  # 使用 Docker Compose 文件的版本

services:
  prom:
    image: prom/prometheus:v2.44.0
    container_name: prom
    restart: always
    ports:
      - "9090:9090"
    security_opt:
      - seccomp=unconfined
    networks:
      - skyeye
    volumes:
      - /data/skyeye/config/prometheus.yml:/etc/prometheus/prometheus.yml
      - /data/skyeye/config/basic_auth.yml:/etc/prometheus/basic_auth.yml
      - /data/skyeye/data:/data
    command:
      - "--config.file=/etc/prometheus/prometheus.yml"
      - "--web.config.file=/etc/prometheus/basic_auth.yml"

networks:
  skyeye:
    external: true

这里将配置文件prometheus,yml以及basic_auth.yml以挂载方式进行启动
step2: 启动容器

复制代码
docker-compose up -d
docker-compose ps

二、加密结果验证

访问http://IP:Port

三.集成grafana

在Data Source中打开开关Auth,根据如下提示:

相关推荐
学Linux的语莫12 小时前
prometheus、grafana的docker搭建
docker·容器·prometheus
为什么不问问神奇的海螺呢丶13 小时前
服务器巡检报告-基于categraf 采集数据-存入Prometheus-写入mysql后生成报告
服务器·mysql·prometheus
一枚正在学习的小白20 小时前
prometheus监控mysql服务
linux·运维·mysql·prometheus
chen_note2 天前
监控——普罗米修斯
grafana·prometheus
闲人编程2 天前
Prometheus监控指标集成指南
prometheus·监控·promql·仪表盘··cncf·codecapsule
木子欢儿3 天前
Prometheus Blackbox域名SSL证书监控并设置AlertManager告警
网络·网络协议·ssl·prometheus
lvbinemail3 天前
Grafana模板自动复制图表
数据库·mysql·zabbix·grafana·监控
wxjlkh4 天前
docker 搭建 grafana+prometheus 监控主机资源之node_exporter
docker·grafana·prometheus
yunson_Liu4 天前
kube-prometheus-stack基础上部署domain-exporter监控域名注册过期时间
prometheus
Gold Steps.4 天前
Alloy+Loki+Minio+Grafana云原生K8S日志收集方案
云原生·kubernetes·grafana