前提:
服务至少要部署两台机上,当其中一台下线后,由另一台提供对外服务
1,依赖
<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Hoxton.SR3</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
application.yml 配置
management.endpoint.shutdown.enabled=true management.endpoint.health.show-details=always management.endpoints.web.exposure.include=*
#微服务上线请求
curl -H "Content-Type:application/vnd.spring-boot.actuator.v2+json;charset=UTF-8" -X POST http://localhost:2{{ port }}/actuator/service-registry?status=UP
#微服务下线请求
curl -H "Content-Type:application/vnd.spring-boot.actuator.v2+json;charset=UTF-8" -X POST http://localhost:2890/actuator/service-registry?status=DOWN
#eureka 小知识
>eureka 清理过期服务的时间间隔是0s,即不清理实例
```yaml
eureka.server.eviction-interval-timer-in-ms
```
>eureka 客户端配置
eureka 服务端如果发现客户端在这个时间段内没有收到心跳,会将客户端下线
默认值90s
```yaml
eureka.instance.lease-expiration-duration-in-seconds
```
>客户端通过eureka.instance.lease-renewal-interval-in-seconds
每隔这个时间会主动心跳一次,默认值为30s,更新自己的状态。
原文:https://www.cnblogs.com/dongma/p/14727796.html