Dubbo无法访问远程Zookeeper已注册服务的问题解决方案

网友投稿 359 2023-01-10


Dubbo无法访问远程Zookeeper已注册服务的问题解决方案

背景

使用Dubbo的时候发现当Zookeeper、Dubbo-admin、生产者和消费者都在内网中的时候,生产者的生产和消费是没有问题的,但是当它Zookeeper、生产者放到远程服务器上,然后消费者在访问消费就出现了无法找到找到服务的问题。

内网环境使用情况

上述的图是在同一个内网中,使用的代码如下:

1、生产者配置

xmlns:xsi="http://w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"

xsi:schemaLocation="http://springframework.org/schema/beans

http://springframework.org/schema/beans/spring-beans.xsd

http://code.alibabatech.com/schema/dubbo

http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

ref="dubboDemoFacade"

interface="com.dubbo.demo.facade.IDubboDemoFacade"

version="1.0.0"

cluster="failfast"

executes="10"

timeout="500000"

registry="myjhd_id">

xmlns:xsi="http://w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"

xsi:schemaLocation="http://springframework.org/schema/beans

http://springframework.org/schema/beans/spring-beans.xsd

http://code.alibabatech.com/schema/dubbo

http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

ref="dubboDemoFacade"

interface="com.dubbo.demo.facade.IDubboDemoFacade"

version="1.0.0"

cluster="failfast"

executes="10"

timeout="500000"

registry="myjhd_id">

ref="dubboDemoFacade"

interface="com.dubbo.demo.facade.IDubboDemoFacade"

version="1.0.0"

cluster="failfast"

executes="10"

timeout="500000"

registry="myjhd_id">

2、消费者配置

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"

xsi:schemaLocation="http://springframework.org/schema/beans

http://springframework.org/schema/beans/spring-beans.xsd

http://code.alibabatech.com/schema/dubbo

http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

interface="com.dubbo.demo.facade.IDubboDemoFacade"

version="1.0.0"

cluster="failfast"

timeout="500000"

registry="myjhd_id"/>

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"

xsi:schemaLocation="http://springframework.org/schema/beans

http://springframework.org/schema/beans/spring-beans.xsd

http://code.alibabatech.com/schema/dubbo

http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

interface="com.dubbo.demo.facade.IDubboDemoFacade"

version="1.0.0"

cluster="failfast"

timeout="500000"

registry="myjhd_id"/>

interface="com.dubbo.demo.facade.IDubboDemoFacade"

version="1.0.0"

cluster="failfast"

timeout="500000"

registry="myjhd_id"/>

3、演示效果

可以看到生产者和消费者的ip是一样的,既是在本地上是可以运行的。

多网环境使用情况

如果根据相关的Zookeeper修改上述中的IP地址,其他不用修改的情况下,使用上边的代码,则会出现生产者可以注册到注册中心,但是消费者无法消费到该服务。

在Dubbo-admin上可以看到生产者信息,但是消费者确无法使用该服务,这是因为防火墙的问题。

可以看到上边的端口是20880,这是dubbo默认的,消费者在消费该服务的时候也会通过该端口去使用服务,因此修改防火墙名单。

在 /etc/sysconfig/iptables中添加下边内容:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 20880 -j ACCEPT

表示开启20880端口

然后:service iptables restart 重启防火墙即可。

另外的一种方式是:我们可以指定生产者消费者的端口,可以通过

这样的话,同样开启8889端口即可。

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对我们的支持。如果你想了解更多相关内容请查看下面相关链接


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:详解java封装继承多态
下一篇:中线软件线束研发管理平台(线束开发软件)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~