咱們都知道 Promethetheus 是不帶認證和數據加密的,但不少時候咱們又想在公網中直接使用它的管理界面,若是不作任何處理,它將存在嚴重的數據泄漏安全問題。nginx
下面我將介紹如何經過 nginx 的 basic 認證來解決這一問題。apache
server { listen 80; server_name example.coom; location / { proxy_pass http://localhost:9090/; } }
說明:使用 nignx 的 proxy_pass 代理咱們 Prometheus 服務。安全
使用 htpasswd 生成認證密鑰對ide
htpasswd 屬於 apache2-utils 包,下面我將演示在 Ubuntu 上的安裝和配置過程。post
Step1: 安裝 apache2-utils加密
$ sudo apt-get install apache2-utils
Step2: 生成認證密鑰代理
$ htpasswd -c /etc/nginx/.htpasswd monitor New password: Re-type new password: Adding password for user monitor
說明:monitor 能夠修改成任意用戶名。code
Step3: 使用 cat 查看生成內容:server
$ cat /etc/nginx/.htpasswd monitor:$apr1$EEV......
server { listen 80; server_name example.coom; location / { auth_basic "Prometheus"; auth_basic_user_file "/etc/nginx/.htpasswd"; proxy_pass http://localhost:9090/; } }
保存配置,重啓 nignx 服務後,你訪問域名 example.com 將出現 basic 認證的界面:blog
輸入正確的帳號密碼,你將進入 Prometheus 管理界面。
咱們能夠使用 nginx 的 basic auth 的方式來解決 Prometheus 認證的問題,此方法一樣適用 Alertmanger 或者 NodeExporter。
從如今起,不要再讓你的監控數據在公網中裸奔,趕快去修改配置吧。
做者:宋佳洋
本文連接:http://www.songjiayang.com/posts/prometheus-shu-ju-an-quan-zhi-basic-ren-zhengk8s課程、Golang 課程火熱招生資料找WeChat:17812796384