prometheus添加WEB页面登录basic auth加密认证

prometheus的web页面访问默认是没有账户密码认证的,这样如果部署暴露在公网上非常的不安全,可以使用httpd-tools工具对其进行basic_auth加密,这样登录的时候就需要输入账号密码了。

首先我们安装工具并生成密码

yum -y install httpd-tools
htpasswd -nBC 12 '' | tr -d ':\n' #回车然后输入两次密码生成以下加密密码
$2y$12$NXc9ESFgH2asrm2eYbhG1ecGJoMAptgPenpDI44JDlgKVjqfxWxOu

接下来我们把上述生成的加密密码添加到普罗米修斯的配置中

首先新增一个配置文件

cat > /usr/local/prometheus/config.yml<<EOF
basic_auth_users:
  # 当前设置的用户名为admin, 可以设置多个
  admin: $2y$12$NXc9ESFgH2asrm2eYbhG1ecGJoMAptgPenpDI44JDlgKVjqfxWxOu
EOF

然后修改prometheus.yml配置文件

scrape_configs:
- job_name: prometheus
  basic_auth:
    username: admin
    password: admin123
  static_configs:
    - targets: localhost:9090

最后我们还需要修改下启动命令,将刚才的新建的配置文件添加到启动命令中

/usr/bin/prometheus \
--web.enable-lifecycle \
--config.file=/etc/prometheus.yml \
--web.config.file=/usr/local/prometheus/config.yml \
--storage.tsdb.path=/home/orion/prometheus \
--storage.tsdb.retention.time=93d \
--web.console.libraries=/usr/share/prometheus/console_libraries \
--web.console.templates=/usr/share/prometheus/consoles


内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://sulao.cn/post/922.html

我要评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。