Dubbo cannot access the remote Zookeeper registered service
Background
When Dubbo is used, it is found that when Zookeeper, Dubbo-admin, producer, and consumer are
In the Intranet, there is no problem with producer production and consumption. However, when Zookeeper and producer are placed on the remote server, the consumer cannot find the service when accessing and consuming the service.
Intranet environment usage
The above figure shows the code used in the same Intranet:
1. Producer Configuration
<code class=" hljs xml"><!--{cke_protected}{C}%3C!%2D%2D%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%2D%2D%3E--><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"> <!--{cke_protected}{C}%3C!%2D%2D%20%E6%9A%B4%E9%9C%B2%E5%87%BA%E5%8E%BB%E7%9A%84%E6%8E%A5%E5%8F%A3%2D%2D%3E--> <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></bean></dubbo:registry></dubbo:application></beans></code>
2. Consumer Configuration
<code class=" hljs xml"><!--{cke_protected}{C}%3C!%2D%2D%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%2D%2D%3E--><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"></dubbo:reference></dubbo:registry></dubbo:application></beans></code>
3. Demo results
Vcn6svrV37rNz/u30dXftcRpcMrH0rvR + bXEo6y8yMrH1NqxvrXYyc/Kx7/usage = "Multi-network environment usage"> multi-network environment usage
If you modify the IP address based on the relevant Zookeeper and use the above Code without modification, the producer can register in the registration center, but the consumer cannot consume the service.
The producer information can be viewed on Dubbo-admin, but the consumer cannot use the service because of firewall problems.
We can see that the port above is 20880, Which is dubbo's default. When the consumer consumes the service, it also uses the port to use the service. Therefore, the firewall list is modified.
Add the following content to/etc/sysconfig/iptables:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 20880 -j ACCEPT
Indicates that port 20880 is enabled.
Then:service iptables restart
Restart the firewall.
Another method is: we can specify the port of the producer consumer.
In this case, you can also enable port 8889.