weibocom / motan

A cross-language remote procedure call(RPC) framework for rapid development of high performance distributed services.
Other
5.88k stars 1.78k forks source link

motan 在发布服务注册时,注册的IP 获取有误 #195

Closed yelllowhat closed 8 years ago

yelllowhat commented 8 years ago

描述: 如题,当发布服务时 注册上报的IP经常有误,如发布服务的机器是 192.168.0.10 ,上报的时候,会报成其他地址,或不同一网段和不同网络均出现过.

结果: 导致 client 引用服务时,获取不能连接报 connection timed out

排查:

  1. 检察 发布机器 ping hostname ,发现解析正常
  2. 检察 consul ,consul 能正确识别 机器IP
  3. 检察 配置为 < motan:registry address="127.0.0.1:8500" />

错误截图: motan_registory_ip

rayzhang0603 commented 8 years ago

motan获取ip的策略是hostname对应的ip --> 根据连接目标端口得到的本地ip --> 轮询网卡 请检查是不是配置了hostname。如果存在多块网卡的情况可以选择配置hostname或在service或basicservice标签下配置host属性。

yelllowhat commented 8 years ago

感谢 @rayzhang0603 的回复 对于 hostname , 和 mutil 网卡 我第一时间就检察过, 当下 hostname 均配置的是 127.0.0.1 如下

jack@hadoop3 ~]# ping hadoop3 PING localhost.localdomain (127.0.0.1) 56(84) bytes of data. 64 bytes from localhost.localdomain (127.0.0.1): icmp_seq=1 ttl=64 time=0.105 ms

就是在这种情况下还是出现 乱获取IP的问题,是不是 hostname 需要配置 名网地址即不能是 127.0.0.1 ?

补充: 环境是单网卡,物理机器

rayzhang0603 commented 8 years ago

hostname不能是localip的。可以配置为client能够访问的具体ip,如192.168.0.10。你可以debug com.weibo.api.motan.util.NetUtils.getLocalAddress((Map<String, Integer> destHostPorts)方法,看实际获取到的ip是什么,这个ip最后会注册到注册中心。

yelllowhat commented 8 years ago

@rayzhang0603 非常感谢,应该是这个问题。