consul 服务治理

无效节点自动清除

服务正常关闭情况下,会向consul发起Deregistering ,例如:

// spring的生命周期destroy节点,通过AbstractAutoServiceRegistration destroy的stop函数调用ConsulServiceRegistry#deregister
	@PreDestroy
	public void destroy() {
		stop();
	}
//ConsulServiceRegistry
	@Override
	public void deregister(ConsulRegistration reg) {
		if (ttlScheduler != null) {
			ttlScheduler.remove(reg.getInstanceId());
		}
		if (log.isInfoEnabled()) {
			log.info("Deregistering service with consul: " + reg.getInstanceId());
		}
		client.agentServiceDeregister(reg.getInstanceId(), properties.getAclToken());
	}

但对于宕机直接结束进程的情况,节点会一直驻留,直到检测超时,默认是72小时,原文如下:

Consul will automatically remove dead nodes out of the catalog. This process is called reaping. This is currently done on a configurable interval of 72 hours (changing the reap interval is not recommended due to its consequences during outage situations). Reaping is similar to leaving, causing all associated services to be deregistered.

对于上述情况可以手动清除

consule ip:port+ "/v1/agent/service/deregister/" + serviceId

启动指令 -dev

使用 consul agent -dev 启动时会挂载在前台启动,窗口关闭后日志记录会丢失,生产不建议使用。

Consul ships with a -dev flag that configures the agent to run in server mode and several additional settings that enable you to quickly get started with Consul. The -dev flag is provided for learning purposes only. We strongly advise against using it for production environments.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

你我无缘,全靠BUG

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值