简体   繁体   English

Java Spring 启动 - 将执行器健康端点的端口更改为自定义端口

[英]Java Spring Boot - Change the Port of Actuator Health Endpoint to a Custom Port

I have a Java Spring Boot Application, which is currently running on http://localhost:8080 .我有一个 Java Spring 引导应用程序,它目前正在http://localhost:8080上运行。 I will be containerising this application to be deployed in Kubernetes.我将容器化这个应用程序以部署在 Kubernetes 中。 For this I have enabled the actuator health endpoint by adding the following to the pom.xml file.为此,我通过将以下内容添加到pom.xml文件中来启用actuator health端点。

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

Now, the application Health Endpoint works successfully on http://localhost:8080/actuator/health endpoint.现在,应用程序 Health Endpoint 在http://localhost:8080/actuator/health端点上成功运行。 I wish to change the PORT of the Health Endpoint URL to be 8081 .我希望将Health Endpoint URL 的 PORT 更改为 8081 (This is to ensure that I can expose 8080 port to the public and expose 8081 port only to the load balancer. This is a personal preference) (这是为了保证我可以将8080端口暴露给公众,而将8081端口只暴露给负载均衡器。这是个人喜好)

How can I change the port of the Health Endpoint so that the health endpoint URL becomes http://localhost:8081/actuator/health , and the application runs on http://localhost:8080/ .如何更改 Health Endpoint 的端口,以便Health Endpoint URL 变为http://localhost:8081/actuator/health ,并且应用程序在Z80791B3AE7002CB88C24687080998080D上运行。

By default, actuator will be accessible using the default http port configured (commonly 8080).默认情况下,可以使用配置的默认 http 端口(通常为 8080)访问执行器。

Actuator has a number of configuration properties you can configure that fall under the management. Actuator 具有许多可以配置的配置属性,这些属性属于management. prefix.字首。 You can specifically set the management.port in application.properties to have actuator endpoints to be served on the custom port:您可以在application.properties中专门设置management.port以在自定义端口上提供执行器端点:

In application.properties , set:application.properties中,设置:

management.port=8081

For more details, check section 48.2 of the Spring Boot - Production Ready Monitoring documentation.有关更多详细信息,请查看Spring 启动 - 生产就绪监控文档的第 48.2 节。

As pointed out by GreenGiant, the Spring Boot 5+ way of doing this is through:正如 GreenGiant 所指出的,Spring Boot 5+ 的执行方式是:

management.server.port

If you follow the bellow 2 steps you can have 8081 private and 8080 as public.如果您遵循以下 2 个步骤,您可以将 8081 设为私有,将 8080 设为公开。

Step 1:步骤1:

Change your application server port to 8081 first.首先将您的应用程序服务器端口更改为 8081。 That means in your localhost it will run on 8081.这意味着在您的本地主机中它将在 8081 上运行。

http://localhost:8081/actuator/health http://localhost:8081/actuator/health

http://localhost:8081/ http://localhost:8081/

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

Step 2:第2步:

However, when deployed in Kubernetes, 8081 port will be the private port.但是,当部署在 Kubernetes 中时,8081 端口将是私有端口。

In Kubernetes, expose 8080 port to the public.在 Kubernetes 中,公开 8080 端口。

Add a route that maps 8080 to your application 8081 port.添加将 8080 映射到应用程序 8081 端口的路由。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Boot Actuator - 自定义健康端点 - Spring Boot Actuator - Custom Health Endpoint 如何在Spring Boot执行器中实现自定义终结点以保持健康 - How to implement custom endpoint in Spring Boot actuator to health Spring Boot Actuator - Java 端点 - Spring Boot Actuator - Java Endpoint 升级到 Boot 1.2 后无法访问 Spring Boot 执行器运行状况端点 - Spring Boot actuator health endpoint not accessible after upgrading to Boot 1.2 Spring 启动执行器未从指定端口启动 - Spring boot actuator not start with the port specified 不显示Spring Boot Actuator / health端点的磁盘空间和数据库 - Do not show diskspace and db for Spring Boot Actuator /health endpoint spring 启动执行器健康检查端点,在生产服务器的浏览器中没有信息 - spring boot actuator health check endpoint with no information in browser in Production server 用于 Spring MVC 的 Spring Boot Actuator,无需在另一个端口上启动 Spring - Spring Boot Actuator for Spring MVC without Spring boot on another port Spring 当使用“management.server.port”属性而不是弃用的“management.port”时,启动 MockMvc 测试为执行器端点提供 404 - Spring Boot MockMvc test giving 404 for actuator endpoint when using the "management.server.port" property instead of the deprecated "management.port" 是否可以在spring-boot中更改/ health端点? - Is it possible to change the /health endpoint in spring-boot?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM