除了basic auth, 如果希望更安全,可以使用https加密
前提
- 有公网域名
- 有域名证书,可以申请个免费的二级域名证书,申请成功后获取example.com.crt和example.com.key
有可以生成自签名证书和私钥,本地测试时可以用这种方式
mkdir -p /root/certs/example.com && cd /root/certs/example.com
openssl req \
-x509 \
-newkey rsa:4096 \
-nodes \
-keyout example.com.key \
-out example.com.crt
建议将 Prometheus 与反向代理结合使用,并在代理层应用 TLS。可以使用任何喜欢的反向代理,在本指南中,我们将提供一个 nginx 示例。
Nginx 配置
nginx 创建站点 prometheus.mafeifan.com.conf
http {
server {
listen 443 ssl;
server_name prometheus.mafeifan.com;
ssl_certificate /etc/nginx/certs/prometheus.mafeifan.com.crt;
ssl_certificate_key /etc/nginx/certs/prometheus.mafeifan.com.key;
location /prometheus {
proxy_pass http://localhost:9090/;
}
}
}
events {}
Prometheus 配置
加入 web.external-url 参数并将前缀设置为”/“
prometheus \
--config.file=/path/to/prometheus.yml \
--web.external-url=http://prometheus.mafeifan.com\prometheus \
--web.route-prefix="/"
测试
curl -k https://prometheus.mafeifan.com\prometheus/api/v1/label/job/values
参考
https://hulining.gitbook.io/prometheus/guides/tls-encryption
[