jvm端口冲突导致consul服务发现的404错误
背景
服务名称是task-notification

某服务通过feign调用它走consul服务发现机制的时候,提示404错误。接口怎么可能不存在呢?
之前是配置了url,走的是内网域名调用,一切都OK。

问题就是出在consul服务发现,发现的地址不对。所以第一反应是要看注册到task-notification的节点地址是什么。
经过一些列的排查及重启服务,最后是依靠手动将之从consul注册中心下线以解决。
排查过程
可以看到,服务注册ok,因为health接口返回成功。
UP状态表示服务健康
{"status":"UP"}
但是,我们进一步查看该节点的版本号和服务名称,就傻眼了,变成了另外一个服务。
{"git":{"build":{"time":"2022-08-01T08:28:05Z","version":"1.0.31"},"commit":{"id":{"abbrev":"1edbf5a","full":"1edbf5a4e1cda68864d391fd3e5d95d520dbd4f5"}}},"build":{"version":"1.0.31","artifact":"index-service","name":"index-service","group":"com.xhtech.service","time":"2022-08-01T08:27:51.104Z"}}
服务预期是task-notification, 这里注册上来的却是index-service。
- 3、其他排查
登录到192.168.10.19机器,只有服务index-service,而没有task-notification,起初我以为是同一台机器上部署了两个相同端口号的jvm进程导致。
修改程序的端口号
task-notification:9033(新增端口)
index-service:7023(保持不变)
登录服务task-notification所在的机器192.168.80.149,重启生效后,见下图:

相比之前,只是将服务task-notification注册上来了,并没有解决为什么192.168.10.19节点上的服务误注册的问题。
1、http://192.168.80.149:9033/mgm/info
{"git":{"build":{"time":"2022-11-08T09:38:58Z","version":"2.3.4"},"commit":{"id":{"abbrev":"a63c6f0","full":"a63c6f0f15dc755984c3fe711964deaa8a6597e0"}}},"build":{"version":"2.3.4","artifact":"task-notification","name":"task-notification","group":"com.xuehai.crplatform","time":"2022-11-08T09:38:44.729Z"}}
注册上来的节点地址无误。。(开始怀疑一切了~~)
2、查看index-service服务的注册情况:

- index-service服务我重启下,仍然是两边都注册了,还是没有解决问题。在重启的过程中,发现task-notification-192-168-10-19-7203节点会从task-notification移除,随启动成功后,仍旧注册到task-notification上来。
问题总结
task-notification-192-168-10-19-7203 为什么会注册到task-notification, 第一它的服务名是index-service,第二它已经注册到了index-service下。
1、重启过程
区别是前者只是不健康,后者是会先从consul注册中心下线的。


2、手动从consul注册中心下线
- 需要携带token,因为consul集群是有认证的。

3、再次重启index-service,验证是否还会死灰复燃!!
- 恭喜192.168.10.19上的index-service,它再也没能注册到task-notification了!!

相应地,它只会注册到原本属于它自己的index-service上
