背景:默认的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

3121

被折叠的 条评论
为什么被折叠?



