通过Nginx(basic auth)实现Prometheus账号密码登录

发布时间: 2026-01-30 09:30:46 来源: 互联网 栏目: 服务器 点击: 7

《通过Nginx(basicauth)实现Prometheus账号密码登录》本文主要介绍了在RedHat7.5服务器上安装和配置Grafana和Prometheus,并通过HTTPD和Nginx实现...

一、原因

客户Red Hat 7.5服务器安装部署grafana无法添加prometheus数据源,以及无法修改初始密码,为确保环境访问安全,特别研究通过账号密码认证访问prometheus,搜索了很多资料,但都缺这缺那,所以我这里记录下具体实现过程:

二、安Wwpnq装部署httpd

方法一:使用yum安装

yum -y install apr apr-util httpd

方法二:使用源码安装

yum -y install expat-devel gcc gcc-c++ autoreconf libtoolize aWWPnqutomake

1、下载httpd安装包

wget http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.46.tar.gz

2、解压

tar zxvf httpd-2.4.46.tar.gz

3、下载新的apr、apr-util安装(安装过程会有各种奇葩错误,自行搜索资料解决,这里不具体讲解)

wget http://mirror.bit.edu.cn/apache/apr/apr-1.7.0.tar.gz 
wgphpet http://mirror.bit.edu.cn/apache/apr/apr-util-1.6.1.tar.gz

4、安装apr、apr-util

tar -zxvf apr-1.7.0.tar.gz 
tar -zxvf apr-util-1.6.1.tar.gz
cd /opt/apr-1.7.0
./configure --prefix=/usr/local/apr && make && make install

cd /opt/apr-util-1.6.1
./configure --prefix=/usr/local/apr-util && make && make install

5、进入目录cd httpd-2.4.46/

cd /opt/httpd-2.4.46/
./configure --prefix=/usr/local/apache2/ --enable-rewrite --enable-so --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
make && make install

三、创建promethphpeus访问认证账号密码

备注:路径与用户名及密码根据实际环境操作变更(在交互界面输入两次相同的密码)

/usr/bin/htpasswd -c /etc/nginx/.htpasswd promethues

四、配置nginx访问配置

vim /etc/nginx/conf/nginx.conf
        location / {
            auth_basic           "Prometheus";
            auth_basic_user_file /etc/nginx/.htpasswd;
    轻语网        proxy_pass   http://localhost:9090;
            proxy_set_header   Host    $host;
            proxy_set_header   X-Real-IP   $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            root   html;
            index  index.html index.htm;
        }

/etc/nginx/sbin/nginx -t
/etc/nginx/sbin/nginx -s reload

五、修改prometheus.yml文件,配置basic auth认证

1、修改prometheus.yml文件

vim /usr/local/prometheus/prometheus.yml
  - job_name: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
    - targets: ['localhost:9090']
    basic_auth:
      username: promethues
      password: 密码

2、重启prometheus服务

systemctl restart prometheus
systemctl status prometheus

3、访问prometheus服务界面

通过Nginx(basic auth)实现Prometheus账号密码登录

4、输入配置的用户名与认证密码

通过Nginx(basic auth)实现Prometheus账号密码登录

5、查看targets信息

通过Nginx(basic auth)实现Prometheus账号密码登录

到此这篇关于通过Nginx(basic auth)实现Prometheus账号密码登录的文章就介绍到这了,更多相关Nginx 实现Prometheus账号密码登录内容请搜索轻语网(www.qingyu.net)以前的文章或继续浏览下面的相关文章希望大家以后多多支持轻语网(www.qingyu.net)!

本文标题: 通过Nginx(basic auth)实现Prometheus账号密码登录
本文地址: http://www.qingyu.net/jiqiao/fuwuqi/732076.html

如果本文对你有所帮助,在这里可以打赏

支付宝二维码微信二维码

  • 支付宝二维码
  • 微信二维码
  • 声明:凡注明"本站原创"的所有文字图片等资料,版权均属轻语网所有,欢迎转载,但务请注明出处。
    nginx+keepalived双主模式双主热备方式Nginx报Too Many Open Files总结
    Top