Keycloak http-management returns 连接被拒绝

Keycloak http-management returns Connection refused

我有 Keycloak 14 运行 并想从中抓取指标数据。

所以我配置了 Prometheus 来抓取 http://KEYCLOAK_HOST:9990/metrics。不幸的是,这给了我一个“连接被拒绝”。

当我尝试从另一台主机手动连接时,我得到了同样的结果:

user@host:/$ curl -vvv 10.244.3.154:9990/metrics
* Expire in 0 ms for 6 (transfer 0x5566ecabbfb0)
*   Trying 10.244.3.154...
* TCP_NODELAY set
* Expire in 200 ms for 4 (transfer 0x5566ecabbfb0)
* connect to 10.244.3.154 port 9990 failed: Connection refused
* Failed to connect to 10.244.3.154 port 9990: Connection refused
* Closing connection 0
curl: (7) Failed to connect to 10.244.3.154 port 9990: Connection refused
user@host:/$

事实上,我在管理端口的所有路径上都遇到了这个错误。即使在那些上,也不存在:

user@host:/$ curl -vvv 10.244.3.154:9990/some_endpoint
* Expire in 0 ms for 6 (transfer 0x55eea4059fb0)
*   Trying 10.244.3.154...
* TCP_NODELAY set
* Expire in 200 ms for 4 (transfer 0x55eea4059fb0)
* connect to 10.244.3.154 port 9990 failed: Connection refused
* Failed to connect to 10.244.3.154 port 9990: Connection refused
* Closing connection 0
curl: (7) Failed to connect to 10.244.3.154 port 9990: Connection refused
user@host:/$

在 Keycloak 主机中运行良好:

bash-4.4$ curl -vvv localhost:9990/metrics
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 9990 (#0)
> GET /metrics HTTP/1.1
> Host: localhost:9990
> User-Agent: curl/7.61.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Connection: keep-alive
...
bash-4.4$

它只适用于 localhost 不过:

bash-4.4$ hostname -I
10.244.3.154
bash-4.4$ curl -vvv 10.244.3.154:9990/metrics
*   Trying 10.244.3.154...
* TCP_NODELAY set
* connect to 10.244.3.154 port 9990 failed: Connection refused
* Failed to connect to 10.244.3.154 port 9990: Connection refused
* Closing connection 0
curl: (7) Failed to connect to 10.244.3.154 port 9990: Connection refused
bash-4.4$

所以我假设 Keycloak 没有向“外部世界”提供管理端点。但是我怎样才能启用它呢?

我正在使用 codecentric Helm 图表进行部署 (https://github.com/codecentric/helm-charts/tree/master/charts/keycloak)。我现在是 运行 Keycloak 14.0.0,但与 15.x 有同样的问题(由于错误现在无法更新)。

提前致谢!

在 Helm 图表的文档中发现,我必须通过将环境变量 KEYCLOAK_STATISTICS 设置为 all 来启用它。

https://github.com/codecentric/helm-charts/tree/master/charts/keycloak#prometheus-metrics-support