热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

用户名密码输入框源码_通过Nginx实现Prometheus账号密码认证登录

一、原因因客户RedHat7.5服务器安装部署grafana无法添加prometheus数据源,以及无法修改初始密码,为确保环境访问安全,

一、原因

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

二、安装部署httpd

方法一:使用yum安装

yum -y install apr apr-util httpd

方法二:使用源码安装

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

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 wget 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.gzcd apr-1.7.0./configure --prefix=/usr/local/apr && make && make installc./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-utilmake && make install

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

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

/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 prometheussystemctl status prometheus

3、访问prometheus服务界面

9c3a1dd6-9615-eb11-8da9-e4434bdf6706.png


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

a93a1dd6-9615-eb11-8da9-e4434bdf6706.png


5、查看targets信息

af3a1dd6-9615-eb11-8da9-e4434bdf6706.png



推荐阅读
author-avatar
十点半的
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有