Eureka设置服务上下线
被动下线(默认)
等待若干秒后,eureka server自动剔除失效的服务地址。(见Eureka配置优化)
直接执行http请求
- shell命令执行(成功:200;失败:404,500)
# 如果服务还存活着,那么在一定的时间内,服务会重新注册(非强制)
curl -X DELETE "http://[ip]:[port]/eureka/apps/[your_app_name]/[your_instance_id]" -I
# 强制上线/下线/移除服务(强制)
curl -X PUT "http://192.168.1.248:8761/eureka/apps/CONFIG-SERVER/192.168.1.248:8088/status?value=UP" -I
curl -X PUT "http://192.168.1.248:8761/eureka/apps/CONFIG-SERVER/192.168.1.248:8088/status?value=DOWN" -I
curl -X PUT "http://192.168.1.248:8761/eureka/apps/CONFIG-SERVER/192.168.1.248:8088/status?value=OUT_OF_SERVICE" -I
# 恢复以上强制操作为原始状态(解除强制覆盖:如果不加参数status的话,先初始化为UNKOWN状态,随即更新其真实状态)
curl -X DELETE "http://192.168.1.248:8761/eureka/apps/CONFIG-SERVER/192.168.1.248:8088/status?value=[status(,or you can ignore this param)]" -I
- POSTMAN执行(具体功能同上)
Java程序执行(强制)
@RestController
public class OfflineController {
@GetMapping("/offline")
public String offline() {
DiscoveryManager.getInstance().shutdownComponent();
return "offline OK";
}
}
OR
@RestController
public class OfflineController {
@Autowired
private EurekaClient discoveryClient;
@GetMapping("/offline2")
public String offline2() {
discoveryClient.shutdown();
discoveryClient = null;
return "offline OK2";
}
}
Python程序执行(非强制)
pip install py_eureka_client
#!/usr/bin/env python3
import eureka_client
eureka_client.cancel('http://192.168.1.248:8761/eureka/', app_name, id)
参考:
通过Spring Boot Actuator控制服务上下线
参考:ENDPOINT: shutdown、pause、service-registry
Spring Cloud应用优雅上下线(集成发布系统)
- 从注册中心强制移除服务,
curl -X PUT "http://192.168.1.248:8761/eureka/apps/CONFIG-SERVER/192.168.1.248:8088/status?value=OUT_OF_SERVICE" -I
; - 等待若干时间之后(等待各个端和组件对服务列表的缓存过期),发布重启应用(先用kill -15 [pid],若干时间后再按需kill -9 [pid]);
- 从注册中心恢复服务,覆盖之前的强制状态(修改method即可),
curl -X DELETE "http://192.168.1.248:8761/eureka/apps/CONFIG-SERVER/192.168.1.248:8088/status?value=OUT_OF_SERVICE" -I
,等待若干时间即可生效; - 按照以上步骤1-3发布其他应用节点(灰度发布)
Eureka配置优化
https://docs.qq.com/doc/DTUJSUW9jUFFpZXp0?appid=101520907&od_appid=101520907&from=weiyun
来源:oschina
链接:https://my.oschina.net/wnjustdoit/blog/4303916