首页 > 其他分享 >Prometheus配置basic_auth

Prometheus配置basic_auth

时间:2023-11-06 10:35:27浏览次数:47  
标签:web -- prometheus auth Prometheus usr basic

一、什么是Prometheus?

  1. Prometheus是一个开源的系统监控和报警框架,其本身也是一个时序列数据库(TSDB),它的设计灵感来源于Google的Borgmon,就像Kubernetes是基于Borg系统开源的。
  2. Prometheus是由SoundCloud的Google前员工设计并开源的,官方网站:Prometheus - Monitoring system & time series database 。Prometheus于2016年加入云原生计算机基金会(Cloud Native Computing Foundation,简称CNCF),成为了受欢迎程度仅次于Kubernetes的开源项目。

问题

prometheus部署完成后,是通过web进行访问的,但是大部分人部署完成后是没有进行加密的安全措施,导致在公网上可以给任何人都能访问,从而暴露出公司内部监控的所有Targets。

在FOFA平台通过protocol="prometheus(http)"的语法进行搜索

可以发现很多都是没有进行加密的,导致Targets以及配置的泄露。

解决问题

使用basic_auth加密

二、配置

1、安装所需的工具包,并生成basic_auth密钥
# yum install httpd-tools -y

# htpasswd -nBC 12 '' | tr -d ':\n'
# 密码设置的是123
New password: 			
Re-type new password: 
# 生成的密钥信息
$2y$12$p/NIsggcAYK.qr89GgY6NeiSCROoX//nOELaBX3mQl5GnxtX7tNPS
2、在prometheus的文件夹下添加配置文件
# cd /usr/local/prometheus
# vim web-config.yml 
basic_auth_users:
    admin: $2y$12$p/NIsggcAYK.qr89GgY6NeiSCROoX//nOELaBX3mQl5GnxtX7tNPS
3、修改prometheus.yml配置文件
scrape_configs:
  - job_name: "prometheus"
    basic_auth:
      username: admin	# 账号为admin
      password: 123		# 密码为123
    static_configs:
      - targets: ["192.168.20.50:39090"]
4、修改prometheus的Service文件。[我这里使用的是二进制部署的prometheus]
# vim /usr/lib/systemd/system/prometheus.service
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/prometheus/prometheus \
--config.file=/usr/local/prometheus/prometheus.yml \
--web.listen-address=:39090 \
--web.config.file=/usr/local/prometheus/web-config.yml \
--storage.tsdb.path=/usr/local/prometheus/data/ \
--storage.tsdb.retention=15d \
--web.enable-lifecycle

ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
5、重启服务
# systemctl restart prometheus

三、检验

在浏览器使用Ctrl+F5,强制刷新

此时需要刚刚设置的账号和密码才能登录进入prometheus的页面,防止了相关数据的泄露。


欢迎关注我的CSDN个人博客知乎

标签:web,--,prometheus,auth,Prometheus,usr,basic
From: https://www.cnblogs.com/oldit/p/17811965.html

相关文章

  • Prometheus黑盒监控
    什么是白盒、黑盒?白盒监控:程序内部的一些指标,这类监控专注的点是原因,也就是一般为出现问题的根本,此类监控称为白盒监控,主要关注的是原因黑盒监控:监控关注的是现象,也就是正在发生的告警,比如某个网站突然慢了,或者是打不开了。此类告警是站在用户的角度看到的东西,比较关注现象,表......
  • smtp-server: 526 Authentication failure[0]
    报错内容:smtp-server:526Authenticationfailure[0]"/root/dead.letter"11/313...messagenotsent.官方解释:526Authenticationfailure:请您检查发信服务器需要身份验证是否勾选解决办法:另外就是账号密码的问题,这里的密码包括第三方....所以建议是把这个东西关掉,或者......
  • Prometheus系列---【PromQL常用语法】
    1.聚合运算sum()count()avg()min()max()2.数学运算+-*/%取模^3.常用符号=等于=~模糊查询#统计所有以"-pa-mgr-prometheus"结尾的指标的数量count(process_update_seconds{namespace="afp",service=".*-pa-mgr-prometheus$"})......
  • prometheus添加自定义监控与告警(etcd为例)
    一、步骤及注意事项(前提,部署参考部署篇)一般etcd集群会开启HTTPS认证,因此访问etcd需要对应的证书使用证书创建etcd的secret将etcd的secret挂在到prometheus创建etcd的servicemonitor对象(匹配kube-system空间下具有k8s-app=etcd标签的service)创建service关联被监控对象二、......
  • prometheus docker部署安装
    prometheusprometheusdocker部署安装之前用docker-compose部署过一套自动注册的prometheus,也用k8s的operator部署过一套,详情见promethues栏的文档。时隔许久,今天在自己虚拟机部署一套promethues玩玩准备工作准备三台虚拟机,规格均为1C2G20G,因为是自己玩,所以对性能啥的不要......
  • prometheus Error on ingesting samples that are too old or a re too far into the
    目录prometheusErroroningestingsamplesthataretoooldoraretoofarintothefuture磁盘问题时间问题版本问题历史prometheus旧数据prometheusErroroningestingsamplesthataretoooldoraretoofarintothefuture之前在自己服务器上用docker部署过一个p......
  • Prometheus接入(四、Spring Boot接入)
    环境CentOS7.9+SpringBoot2.6.8安装1、依赖引入<!--预设监控--><dependency><groupId>io.micrometer</groupId><artifactId>micrometer-registry-prometheus</artifactId></depen......
  • Linux环境Prometheus接入(三、MySQL监控接入mysqld_exporter)
    环境CentOS7.9安装1、命令下载wgethttps://github.com/prometheus/mysqld_exporter/releases/download/v0.15.0/mysqld_exporter-0.15.0.linux-amd64.tar.gztar-zxfmysqld_exporter-0.15.0.linux-amd64.tar.gzmvmysqld_exporter-0.15.0.linux-amd64.tar.gz/home/mysq......
  • Linux环境Prometheus接入(四、系统监控接入node_exporter)
    环境CentOS7.9安装1、命令下载wgethttps://github.com/prometheus/node_exporter/releases/download/v1.6.1/node_exporter-1.6.1.linux-amd64.tar.gztar-zxfnode_exporter-1.6.1.linux-amd64.tar.gzmvnode_exporter-1.6.1.linux-amd64/home/node_exporter2、配置系......
  • Linux环境Prometheus接入(一、Prometheus安装)
    环境CentOS7.9安装1、自行下载https://prometheus.io/download/2、命令下载wgethttps://github.com/prometheus/prometheus/releases/download/v2.47.2/prometheus-2.47.2.linux-amd64.tar.gz3、解压tar-zvfprometheus-2.47.2.linux-amd64.tar.gzmvprometheus-2.......