若是直接KILL SpringCloud的服务,由于Eureka采用心跳的机制来上下线服务,会致使服务消费者调用此已经kill的服务提供者而后出错,处理这种状况有2中方案。html
如需平滑的发布服务请参考:spring
1、利用Spring Boot Actuato的管理端点(推荐)缓存
一、pom中引用Actuato服务器
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
二、properties中添加以下内容curl
#启用shutdown endpoints.shutdown.enabled=true #禁用密码验证 endpoints.shutdown.sensitive=false # 禁用actuator管理端鉴权 management.security.enabled=false # 开启重启支持 endpoints.restart.enabled=true
若是只容许本机访问,能够添加以下属性spring-boot
#(只容许本机访问) server.address=localhost
三、在服务器上用curl发送post请求到pause.post
curl -X POST http://localhost:8080/pause
此时eurake上该服务被标记问下线,但该服务其实仍是能够正常访问的,当client还未及时更新本地Instances缓存时,依然不会中断服务。当全部client都感知到该服务DOWN后就不会再往该服务发请求了。url
四、在服务器上利用curl发送shutdown命令spa
curl -X POST http://localhost:8080/shutdown 或者 curl -d "" http://localhost:8080/shutdown
2、利用Eureka的rest管理端点下线服务rest
eureka界面注册的服务:
发送DELETE的Restfull请求
对照关系看上面的2张图。
注意:因为cloud服务是心跳检测,全部在eureka进行DELETE后要快速的中止服务,不然服务可能会被从新注册上。