通過Nginx(basic auth)實現(xiàn)Prometheus賬號密碼登錄
一、原因
因客戶Red Hat 7.5服務(wù)器安裝部署grafana無法添加prometheus數(shù)據(jù)源,以及無法修改初始密碼,為確保環(huán)境訪問安全,特別研究通過賬號密碼認證訪問prometheus,搜索了很多資料,但都缺這缺那,所以我這里記錄下具體實現(xiàn)過程:
二、安裝部署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.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
三、創(chuàng)建prometheus訪問認證賬號密碼
備注:路徑與用戶名及密碼根據(jù)實際環(huán)境操作變更(在交互界面輸入兩次相同的密碼)
/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服務(wù)
systemctl restart prometheus systemctl status prometheus
3、訪問prometheus服務(wù)界面

4、輸入配置的用戶名與認證密碼

5、查看targets信息

到此這篇關(guān)于通過Nginx(basic auth)實現(xiàn)Prometheus賬號密碼登錄的文章就介紹到這了,更多相關(guān)Nginx 實現(xiàn)Prometheus賬號密碼登錄內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Prometheus 和 Grafana 通過nginx-exporter監(jiān)控nginx的詳細步驟
- 解析prometheus+grafana監(jiān)控nginx的方法
- prometheus監(jiān)控nginx并實現(xiàn)可視化的操作指南
- Prometheus監(jiān)控實戰(zhàn)篇Nginx、Hbase操作詳解
- prometheus監(jiān)控nginx的兩種方式
- 詳解Prometheus 抓取 nginx 訪問日志的指標(biāo)
- Nginx配置Prometheus監(jiān)控的實現(xiàn)
- prometheus監(jiān)控nginx的實現(xiàn)
- Nginx使用Prometheus+Grafana實現(xiàn)日志分析與監(jiān)控
相關(guān)文章
Nginx默認location?index設(shè)置網(wǎng)站的默認首頁方法詳解
我們都知道index后面可以跟多個設(shè)置,如果訪問的時候沒有指定具體訪問的資源,則會依次進行查找,找到第一個為止,這篇文章主要給大家介紹了關(guān)于Nginx默認location?index設(shè)置網(wǎng)站的默認首頁的相關(guān)資料,需要的朋友可以參考下2023-12-12
Nginx Lua 根據(jù)參數(shù)請求轉(zhuǎn)發(fā)的實現(xiàn)
本文介紹了如何使用Nginx和Lua腳本實現(xiàn)基于參數(shù)的請求轉(zhuǎn)發(fā),文章詳細說明了配置方法,并提供了示例代碼,幫助讀者理解如何通過NginxLua模塊根據(jù)請求參數(shù)將流量轉(zhuǎn)發(fā)到不同后端服務(wù),這種方法有助于實現(xiàn)靈活的負載均衡和動態(tài)內(nèi)容處理2022-05-05
Nginx 1.28.0 源碼編譯安裝與自定義網(wǎng)頁部署詳細指南
本文介紹了Nginx1.28.0的安裝過程,提供了自定義HTML文件部署步驟、安裝后核心目錄說明、常用管理命令、部署前端項目示例等內(nèi)容,感興趣的朋友跟隨小編一起看看吧2026-05-05

