1. 程式人生 > >解決dubbo 錯誤ip及ip亂入的問題

解決dubbo 錯誤ip及ip亂入的問題

問題

在本地啟動dubbo時,服務註冊在本地的zookeeper ,但是註冊IP卻不是本地的
iP。產生問題,導致consumer 找不到provider ,訪問不了服務。

  • 例如 本地IP為 10.0.0.1 ,但是zookeeper上的註冊ip 可能是 196.168.0.1

產生原因,隨機產生,可能是你重啟一下機器,或者電腦小智一段時間就會發生。

  • 報錯類似
Caused by: org.springframework.remoting.RemoteConnectFailureException: Could not connect to remote service [rmi://192.168.72.235:20881/com.ztesoft.zsmartcity.ynzw.demo.service.DemoService]; nested exception is java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is: 
Caused by: java.lang.IllegalStateException: Failed to check the status of the service com.xxx.xxx.service.LoginService. No provider available for the service com.xxxx.xxxx.service.LoginService:3.0 from the url zookeeper://202.106.199.37:2181/com.alibaba.dubbo.registry.RegistryService?anyhost=true&application=xxx&application.version=3.0&check=false&default.timeout=5000&dubbo=2.5.3&interface=com.xxx.xxx.service.LoginService&methods=aLogin,bPassword,userLogin,modifyPasswordLogin,validate,fVersion,xLogout,userLogout,getTest,getCode,aLogin,aToken,aUser&pid=2200&revision=1.0&side=consumer×tamp=1462534379328&version=3.0 to the consumer 202.106.199.37 use dubbo version 2.5.3

解決方法

在程式配置檔案中 配置dubbo 的註冊中心“dubbo.registry.address” 時要注意不要配置127.0.0.1 要配置為 localhost。

然後在配置 本地的/etc/hosts 檔案中

127.0.0.1 localhost 

問題原因

懷疑原因:為本地配置127.0.0.1 時由於連著網路所以dns 解析解析到了你的網路上了。麼有解析到本機造成的。但是並不確定是不是這個原因。