prometheus设置用户名密码

您所在的位置:网站首页 怎样设置监控密码忘了 prometheus设置用户名密码

prometheus设置用户名密码

2024-07-16 11:50| 来源: 网络整理| 查看: 265

说明

在本指南中,您将用户名和散列密码存储在web.yml文件,使用该文件中的凭证对访问prometheus HTTP端点的用户进行身份验证根据参数–web.config.file启动prometheus.

散列密码

假设您希望所有访问Prometheus实例的用户都提供用户名和密码。对于此示例,请使用admin作为用户名,并选择任何你想要的密码。

首先,生成一个bcrypt密码的哈希。为了生成散列密码,我们将使用python3-bcrypt。(安装python3环境)

让我们通过运行来安装它sudo dnf install python3-bcrypt.x86_64

下面是一个python脚本,它使用python3-bcrypt提示输入密码并对其进行哈希处理:

import getpass

import bcrypt

password = getpass.getpass("password: ")

hashed_password = bcrypt.hashpw(password.encode(“utf-8”), bcrypt.gensalt())

print(hashed_password.decode())

将脚本另存为gen-pass.py并运行它:

$ python3 gen-pass.py

这应该会提示您输入密码:

password:

$2b 12 12 12hNf2lSsxfm0.i4a.1kVpSOVyBCfIB51VRjgBUyv6kdnyTlgWj81Ay

在这个例子中,我使用“test”作为密码。

将密码保存在某个地方,我们将在接下来的步骤中使用它!

创建web.yml

让我们创建一个web.yml文件(证明文件),内容如下:

basic_auth_users:

admin: $2b 12 12 12hNf2lSsxfm0.i4a.1kVpSOVyBCfIB51VRjgBUyv6kdnyTlgWj81Ay

您可以使用以下命令来验证该文件promtool check web-config web.yml

$ promtool check web-config web.yml

web.yml SUCCESS

您可以向文件中添加多个用户。

启动普罗米修斯

可以使用web配置文件启动prometheus,如下所示:

$ prometheus --web.config.file=web.yml

测试

您可以使用CURL与您的设置进行交互。尝试以下请求:

curl --head http://localhost:9090/graph

这会返回一个401 Unauthorized因为您未能提供有效的用户名和密码。

要使用基本身份验证成功访问Prometheus端点,例如/metrics端点,使用提供正确的用户名-u出现提示时,标记并提供密码:

curl -u admin http://localhost:9090/metrics

Enter host password for user ‘admin’:

这将返回Prometheus metrics输出,类似于:

# HELP go_gc_duration_seconds A summary of the GC invocation durations.

# TYPE go_gc_duration_seconds summary

go_gc_duration_seconds{quantile=“0”} 0.0001343

go_gc_duration_seconds{quantile=“0.25”} 0.0002032

go_gc_duration_seconds{quantile=“0.5”} 0.0004485



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3