Java Spring Boot - 将Actuator Health端点的端口更改为自定义端口

9

我有一个Java Spring Boot应用程序,目前在http://localhost:8080上运行。我将对该应用程序进行容器化以在Kubernetes中部署。为此,我通过在pom.xml文件中添加以下内容启用了actuator health端点。

<!-- Spring boot actuator to expose metrics endpoint -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

现在,应用的健康端点在 http://localhost:8080/actuator/health 上成功工作。我希望将 健康端点URL的端口修改为8081(这是为了确保我可以将8080端口公开并将8081端口仅暴露给负载均衡器。这是个人偏好)

如何更改健康端点的端口,以便健康端点的URL变为http://localhost:8081/actuator/health,并且应用程序运行在http://localhost:8080/上。

3个回答

21

正如GreenGiant所指出的,Spring Boot 5+ 的实现方式是通过:

management.server.port

springboot5+ == springboot1.5+ 吗? - Lei Yang

9

默认情况下,actuator将使用默认配置的http端口(通常为8080端口)进行访问。

Actuator有一些配置属性可以配置,这些属性位于management.前缀下。您可以在application.properties中明确设置management.port,以使用自定义端口提供actuator终端点服务:

application.properties中设置:

management.port=8081

更多细节请查看Spring Boot - 生产就绪监控文档的第48.2节。


13
在新版本的 Spring Boot(5+)中,配置选项是 management.server.port - GreenGiant
@GreenGiant - 春天(不是Spring Boot) - gstackoverflow

0

如果您按照以下两个步骤操作,您可以将8081端口设置为私有端口,将8080端口设置为公共端口。

步骤1:

首先将应用服务器端口更改为8081。这意味着在您的本地主机上它将运行在8081端口。

http://localhost:8081/actuator/health

http://localhost:8081/

To do that, in your application.properties file, add server.port=8081

步骤2:

然而,在Kubernetes中部署时,8081端口将成为私有端口。

在Kubernetes中,将8080端口暴露给公共网络。

添加一条路由,将8080映射到您的应用程序的8081端口。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接