使用 TLS 加密 Prometheus API 和 UI 端点
最后更新于
这有帮助吗?
最后更新于
这有帮助吗?
对于与 Prometheus 实例(即表达式浏览器或 )的连接,Prometheus 不直接支持 (TLS)加密如果您想对这些连接强制执行 TLS,建议将 Prometheus 与结合使用,并在代理层应用 TLS。您可以使用任何您喜欢的反向代理,在本指南中,我们将提供一个 。
假设您要在 example.com
域(您所拥有的) 上可用的 服务后面运行 Prometheus 实例,并且所有 Prometheus 端点都可以通过 /prometheus
端点使用。因此 Prometheus 的 /metrics
端点的完整 URL 为:
假设您已经使用 或类似工具生成了以下内容:
SSL 证书文件 /root/certs/example.com/example.com.crt
SSL 密钥文件 /root/certs/example.com/example.com.key
您可以使用以下命令生成自签名证书和私钥:
在提示符下填写适当的信息,并确保在 Common Name
提示符下填入 example.com
。
使用您提供的证书和密钥实现 TLS 加密
将 /prometheus
端点的所有连接代理到在同一主机上运行的 Prometheus 服务器(同时从URL中删除 /prometheus
)
以 root 用户启动 nginx(因为 nginx 需要监听到 443 端口):
在 nginx 代理后面运行 Prometheus 时,您需要将外部 URL 设置为 http://example.com/prometheus
,并将路由前缀设置为 /
:
如果您想使用 example.com
域在本地测试 nginx 代理,则可以在 /etc/hosts
文件中添加一个条目,以将 example.com
重新路由到 localhost
:
然后,您可以使用 cURL 与本地 nginx/Prometheus 进行交互:
您可以使用 --insecure
或 -k
标志连接到 nginx 服务器,而无需指定证书:
下面是一个示例 配置文件。 使用此配置,nginx将: Below is an example configuration file. With this configuration, nginx will:
NOTE: 此示例使用 /etc/nginx
作为 nginx 配置文件,但这会因安装而异。其它包括 /usr/local/nginx/conf
和 /usr/local/etc/nginx
。