Dubbo無法訪問遠程Zookeeper已注冊服務的問題解決方案
背景
使用Dubbo的時候發(fā)現(xiàn)當Zookeeper、Dubbo-admin、生產(chǎn)者和消費者都在內(nèi)網(wǎng)中的時候,生產(chǎn)者的生產(chǎn)和消費是沒有問題的,但是當它Zookeeper、生產(chǎn)者放到遠程服務器上,然后消費者在訪問消費就出現(xiàn)了無法找到找到服務的問題。
內(nèi)網(wǎng)環(huán)境使用情況

上述的圖是在同一個內(nèi)網(wǎng)中,使用的代碼如下:
1、生產(chǎn)者配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="Jhd_Security" owner="allen.xu" organization="MyJhd"/>
<dubbo:registry address="zookeeper://172.16.61.101:2181" timeout="500000" group="JhdGroup" id="myjhd_id"/>
<!-- 暴露出去的接口-->
<bean id="dubboDemoFacade" class="com.dubbo.demo.facade.impl.DubboDemoFacade"/>
<dubbo:service
ref="dubboDemoFacade"
interface="com.dubbo.demo.facade.IDubboDemoFacade"
version="1.0.0"
cluster="failfast"
executes="10"
timeout="500000"
registry="myjhd_id">
</dubbo:service>
</beans>
2、消費者配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="consumer-of-sayHello-app" owner="allen.xu" organization="MyJhd"/>
<dubbo:registry address="zookeeper://172.16.61.101:2181" timeout="500000" group="JhdGroup" id="myjhd_id"/>
<dubbo:reference id="dubboDemoFacade"
interface="com.dubbo.demo.facade.IDubboDemoFacade"
version="1.0.0"
cluster="failfast"
timeout="500000"
registry="myjhd_id"/>
</beans>
3、演示效果


可以看到生產(chǎn)者和消費者的ip是一樣的,既是在本地上是可以運行的。
多網(wǎng)環(huán)境使用情況

如果根據(jù)相關的Zookeeper修改上述中的IP地址,其他不用修改的情況下,使用上邊的代碼,則會出現(xiàn)生產(chǎn)者可以注冊到注冊中心,但是消費者無法消費到該服務。
在Dubbo-admin上可以看到生產(chǎn)者信息,但是消費者確無法使用該服務,這是因為防火墻的問題。

可以看到上邊的端口是20880,這是dubbo默認的,消費者在消費該服務的時候也會通過該端口去使用服務,因此修改防火墻名單。
在 /etc/sysconfig/iptables中添加下邊內(nèi)容:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 20880 -j ACCEPT
表示開啟20880端口

然后:service iptables restart 重啟防火墻即可。
另外的一種方式是:我們可以指定生產(chǎn)者消費者的端口,可以通過
<dubbo:protocol name="dubbo" port="8889"/>
這樣的話,同樣開啟8889端口即可。
總結
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對腳本之家的支持。如果你想了解更多相關內(nèi)容請查看下面相關鏈接
相關文章
springboot使用redis對單個對象進行自動緩存更新刪除的實現(xiàn)
本文主要介紹了springboot使用redis對單個對象進行自動緩存更新刪除的實現(xiàn),具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-08-08
springcloud + mybatis + seate集成示例
本文主要介紹了springcloud + mybatis + seate集成示例,文中通過示例代碼介紹的非常詳細,需要的朋友們下面隨著小編來一起學習學習吧2021-06-06
SpringBoot多數(shù)據(jù)源的兩種實現(xiàn)方式實例
最近在項目開發(fā)中,需要為一個使用MySQL數(shù)據(jù)庫的SpringBoot項目,新添加一個PLSQL數(shù)據(jù)庫數(shù)據(jù)源,下面這篇文章主要給大家介紹了關于SpringBoot多數(shù)據(jù)源的兩種實現(xiàn)方式,需要的朋友可以參考下2022-04-04
Quartz實現(xiàn)JAVA定時任務的動態(tài)配置的方法
這篇文章主要介紹了Quartz實現(xiàn)JAVA定時任務的動態(tài)配置的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-07-07

