Mozartaa commented on issue #8523:
URL: https://github.com/apache/dubbo/issues/8523#issuecomment-900323863


   您好,感谢回复!
       这个报错和代码其实没有关系,我使用的是最基本的Hello 
World代码,主要原因在于当我电脑有多个网卡时,dubbo没有进行正确判断区分,使用了错误的网卡对外提供服务,导致服务不可用。
   报错原因分析如下:
       1.在provider的配置文件中,配置协议时我没有配置host信息。
   
   2.由于没有配置host信息,dubbo会读取我本机IP,并且把机器IP注册到zookeeper中。如下:
   可以看到注册到zookeeper中的ip是一个VMWare的虚拟网卡的IP,这个IP使用 telnet命令是连接不到的。因为这个IP不能对外提供服务。
   
   
   (1)查看本机IP
   
   (2)查看zookeeper中注册信息
   
   
   
   3.通过debug 
consumer的代码,可以发现可以从注册中心获取到provider地址,但是使用这个虚拟IP,导致网络不通。如果在provider的配置文件中加上正确的host配置,不用dubbo自动获取IP,则consumer可以正确调用。
   
   
   
4.查看dubbo源码,可以发现在ServiceConfig类中,有一个findConfigedHosts()方法,如果配置文件没有配置host信息,这个方法会读取机器IP,使用如下的方式,但是这个获取机器IP的方式是有问题的,导致获取到的是虚拟网卡的IP地址,不能正确对外提供服务。具体原因可以参考下边的帖子。
   
   
        hostToBind = InetAddress.getLocalHost().getHostAddress();
   
   
   
InetAddress.getLocalHost()问题解释:https://blog.csdn.net/f641385712/article/details/105233229
   
   
   建议获取机器IP地址的代码进行优化,可以参考下方代码:
   
   
   
   
   
   ------------------ 原始邮件 ------------------
   发件人:                                                                         
                                               "apache/dubbo"                   
                                                                 
***@***.***>;
   发送时间: 2021年8月17日(星期二) 晚上7:52
   ***@***.***>;
   ***@***.******@***.***>;
   主题: Re: [apache/dubbo] 【call provider service failed】The provider 
service used a virtual IP when registering (#8523)
   
   
   
   
   
      
   看报错,你这个是消费者发起订阅的时候没有拿到提供者列表吧?和ip有关吗?
     
   有关的,这个ip不能对外提供服务,如果我暴露服务的时候指定host,就可以成功调用
     
   能把你的消费者代码也发一下吗?我本地用你的用例试下看看
    
   —
   You are receiving this because you authored the thread.
   Reply to this email directly, view it on GitHub, or unsubscribe.
   Triage notifications on the go with GitHub Mobile for iOS or Android.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to