Prometheus默认开箱即食,并没有设置认证方式,如果你使用Grafana那就另当别论。
如果你想直接访问Prometheus并且需要设置个认证,那么通过Nginx反向代理是一个不错的选择。
本文通过Nginx反向代理增加401认证方式来实现。
1、安装Nginx
安装Nginx方式多种,我这里以whsir一键包为例
rpm -ivh http://mirrors.whsir.com/centos/whsir-release-centos.noarch.rpm
yum install wnginx
2、安装apache-htpasswd工具
yum -y install httpd-tools
3、加密认证密码
这里账号是whsir,对密码加密
htpasswd -cs /usr/local/nginx/conf/401htpasswd whsir
4、设置Nginx反向代理及401认证
cd /usr/local/nginx/conf/vhost
rm -f demo.conf
vi demo.conf
server {
listen 80;
server_name 192.168.1.191;
location / {
auth_basic "Prometheus";
auth_basic_user_file /usr/local/nginx/conf/401htpasswd;
proxy_pass http://localhost:9090/;
}
}
其中server_name 192.168.1.191为本机IP,可根据个人使用情况自行选择
5、启动Nginx验证
/etc/init.d/nginx start
访问http://192.168.1.191
正常输入密码后,会看到Prometheus页面,如果提示403则表示账号密码不正确,或者路径配错。

注:本文转自https://blog.whsir.com/post-4241.html
Be First to Comment