Spring Boot 应用集成 Spring Boot Actuator
Spring Boot Actuator 常规配置
maven依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
application.yml配置:
management:
endpoint:
health:
show-details: always
cache:
time-to-live: 30s
shutdown:
enabled: true
info:
cache:
time-to-live: 30s
endpoints:
web:
exposure:
include: "*"
cors:
allowed-origins: "*"
allowed-methods: "*"
Spring Boot 应用集成 Spring Boot Admin Client
通过注册中心集成(被动集成)
maven依赖:
<dependency>-->
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
application.yml配置:
eureka:
instance:
hostname: ${spring.cloud.client.ip-address}
prefer-ip-address: true
instance-id: ${spring.cloud.client.ip-address}:${server.port}
client:
serviceUrl:
defaultZone: @eureka.client.serviceUrl.defaultZone@
register-with-eureka: false
主动集成
maven依赖:
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>${spring-boot-admin.version}</version>
</dependency>
application.yml配置:
spring:
boot:
admin:
client:
url: @spring.boot.admin.client.url@
instance:
prefer-ip: true
Spring Boot Admin Server(服务端)
常规配置
maven依赖:
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
</dependency>
application.yml配置:
server:
port: @server.port@
spring:
application:
name: spring-boot-admin-server
profiles:
active: @spring.profiles.active@
security:
user:
name: @spring.security.user.name@
password: @spring.security.user.password@
mail:
host: smtp.exmail.qq.com
port: 465
username: devops@xxx.com
password: ENC(n6KG9CBMqfqhaEf8tXYA99T0LPF6VDJr)
protocol: smtp
test-connection: true
default-encoding: UTF-8
properties:
mail.smtp.auth: true
mail.smtp.starttls.enable: true
mail.smtp.starttls.required: true
mail.smtp.ssl.enable: true
mail.display.sendmail: spring-boot-admin-server(xxx监控平台)
boot:
admin:
notify:
mail:
from: devops@xxx.com
to: wn@xxx.com,zjs@xxx.com,zyl@xxx.com
enabled: true
monitor:
period: 60000ms
status-lifetime: 60000ms
jasypt:
encryptor:
password: spring-boot-admin-server
eureka:
instance:
hostname: ${spring.cloud.client.ip-address}
prefer-ip-address: true
instance-id: ${spring.cloud.client.ip-address}:${server.port}
leaseRenewalIntervalInSeconds: 10
health-check-url-path: /actuator/health
metadata-map:
#startup: ${random.int} #needed to trigger info and endpoint update after restart
user.name: ${spring.security.user.name}
user.password: ${spring.security.user.password}
client:
registryFetchIntervalSeconds: 5
serviceUrl:
defaultZone: @eureka.client.serviceUrl.defaultZone@
register-with-eureka: false
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: always