Prometheus配置WEB登录使用账密认证【basic-auth】

背景:默认的prometheus的web ui界面无需授权登录即可访问,为提高安全性,增加账密登录。
prometheus官网文档:https://prometheus.io/docs/guides/basic-auth/

下载安装包

下载地址:https://github.com/prometheus/prometheus/releases
prometheus安装包版本要求2.24.0以上。
本项目选择版本 prometheus-2.53.5.linux-amd64.tar

HTTP加密(基于basic-auth)

基于prometheus-web-config.yml配置,通过web.config.file参数加载包含认证配置的文件实现basic-auth。

1、安装htpasswd(httpd-tools)

sudo yum install httpd-tools

2、使用htpasswd 命令加密密码

htpasswd -nBC 10 “” | tr -d ‘:\n’

密码:baiyeyou

[root@VM-4-17-centos prometheus-2.53.5]# htpasswd -nBC 10 "" | tr -d ':\n'
New password:
Re-type new password:
$2y$10$9SfSRYTr8tDN89/3XFrFzu69ETjqor8Z18qOm8WF20bFcNNeUIXo.
# 这个就是密码密文

3、进入prometheus安装目录,创建prometheus-web-config.yml 密码文件。将密码密文存储到prometheus-web-config.yml ,指定登录用户名和密钥,密钥为步骤2输出的密码密文。

basic_auth_users:
    prometheus: $2y$10$9SfSRYTr8tDN89/3XFrFzu69ETjqor8Z18qOm8WF20bFcNNeUIXo.
# prometheus为用户名
# $2y$10$9SfSRYTr8tDN89/3XFrFzu69ETjqor8Z18qOm8WF20bFcNNeUIXo. 为密码的密文,web登录时用明文即可

服务启动

启动命令,指定web登录密码文件

prometheus \
--config.file=prometheus.yml \
--web.listen-address=:9090 --web.enable-lifecycle \
--web.config.file=prometheus-web-config.yml

浏览器访问 http://ip:9090 需要输入账号密码才能访问

为方便后续直接使用,可以将配置好的prometheus打包成jar包

tar -zcf prometheus-2.53.5.tar.gz prometheus-2.53.5
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值