prometheus相比于zabbix在網站登錄的時候沒有賬密認證,就導致訪問ip埠的時候會把自身監控的資訊全部暴露出去,因此prometheus的部署建議是不要部署在公網上,另外就是開啟認證了,所謂的認證就是在登陸的時候提示輸入賬號密碼,在這里我們是通過nginx上的HTTP Basic Auth來實作,
1、部署nginx,忽略,
2、安裝apache-htpasswd工具
~:yum -y install httpd-tools
3、創建賬號密碼
~:cd /usr/local/nginx/conf/
~:htpasswd -c ht.passwd prometheus
New password:
Re-type new password:
Adding password for user prometheus
4、在nginx.conf里面編輯反向代理
server {
listen 19090;
location / {
proxy_pass http://localhost:9090;
auth_basic "Basic Authentication";
auth_basic_user_file "ht.passwd";
}
}
這里要提一下,反向代理為什么要用http://localhost:9090,我這里的prometheus和nginx是部署在同一臺服務器上的,同時在請求9090的時候,只允許該臺服務器的ip訪問,
5、修改prometheus.yml檔案
在編輯prometheus.yml檔案之前,先在prometheus目錄下執行
~:./prometheus --config.file=./prometheus.yml --web.external-url=http://localhost:19090 --web.route-prefix="/" --web.enable-lifecycle --web.listen-address="localhost:9090"
目的是使prometheus對外的埠是19090,同時設定9090埠是為了對接nginx上的反向代理,
~:vim prometheus.yml
static_configs:
- targets: ['xxx.xxx.xxx.xxx:19090']
basic_auth:
username: prometheus
password: 密碼
6、重啟prometheus
另外,這個時候如果grafana的監控出現問題的時候,需要重新添加prometheus的地址,并且點開Basic Auth,把剛剛設定的賬號密碼添加進去,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/173786.html
標籤:其他
上一篇:OpenSSH遠程注入漏洞升級
下一篇:Vi編輯器 終端編輯器命令
