经过Nginx(basic auth)实现Prometheus帐号密码登陆

1、缘由

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

2、安装部署httpd

方法一:使用yum安装nginx

yum -y install apr apr-util httpd

方法二:使用源码安装c++

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

一、下载httpd安装包apache

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

二、解压vim

tar zxvf httpd-2.4.46.tar.gz

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

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

四、安装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

五、进入目录cd httpd-2.4.46/ide

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

3、建立prometheus访问认证帐号密码

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

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

4、配置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

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

一、修改prometheus.yml文件code

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: 密码

二、重启prometheus服务

systemctl restart prometheus
systemctl status prometheus

三、访问prometheus服务界面
经过Nginx(basic auth)实现Prometheus帐号密码登陆
四、输入配置的用户名与认证密码
经过Nginx(basic auth)实现Prometheus帐号密码登陆
五、查看targets信息
经过Nginx(basic auth)实现Prometheus帐号密码登陆

相关文章
相关标签/搜索