[英]Java Spring Boot - Change the Port of Actuator Health Endpoint to a Custom Port
我有一個 Java Spring 引導應用程序,它目前正在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>
現在,應用程序 Health Endpoint 在http://localhost:8080/actuator/health端點上成功運行。 我希望將Health Endpoint URL 的 PORT 更改為 8081 。 (這是為了保證我可以將8080端口暴露給公眾,而將8081端口只暴露給負載均衡器。這是個人喜好)
如何更改 Health Endpoint 的端口,以便Health Endpoint URL 變為http://localhost:8081/actuator/health ,並且應用程序在Z80791B3AE7002CB88C24687080998080D上運行。
默認情況下,可以使用配置的默認 http 端口(通常為 8080)訪問執行器。
Actuator 具有許多可以配置的配置屬性,這些屬性屬於management.
字首。 您可以在application.properties
中專門設置management.port
以在自定義端口上提供執行器端點:
在application.properties
中,設置:
management.port=8081
有關更多詳細信息,請查看Spring 啟動 - 生產就緒監控文檔的第 48.2 節。
正如 GreenGiant 所指出的,Spring Boot 5+ 的執行方式是:
management.server.port
如果您遵循以下 2 個步驟,您可以將 8081 設為私有,將 8080 設為公開。
步驟1:
首先將您的應用程序服務器端口更改為 8081。 這意味着在您的本地主機中它將在 8081 上運行。
http://localhost:8081/actuator/health
To do that, in your application.properties file, add server.port=8081
第2步:
但是,當部署在 Kubernetes 中時,8081 端口將是私有端口。
在 Kubernetes 中,公開 8080 端口。
添加將 8080 映射到應用程序 8081 端口的路由。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.