apache / dubbo

The java implementation of Apache Dubbo. An RPC and microservice framework.
https://dubbo.apache.org/
Apache License 2.0
40.5k stars 26.43k forks source link

[2.7.8],dubbo提供者注册到nacos使用外网地址失败,报错Caused by: java.net.BindException: Cannot assign requested address #9605

Open studyyun opened 2 years ago

studyyun commented 2 years ago

环境

image

/etc/hosts文件里面配置了:外网IP 机器的hostname dubbo:2.7.8

提供者

配置:dubbo.protocol.host=云服务器外网IP地址 相关nacos依赖: image

报错信息

PS:xxx.xx.xxx.xx为服务器外网的IP地址

2022-01-21 15:20:44.066 ERROR 294076 --- [ main] o.s.boot.SpringApplication : Application run failed

org.apache.dubbo.rpc.RpcException: Fail to start server(url: dubbo://xxx.xx.xxx.xx:20880/com.dubbo.demo.service.HelloService?anyhost=false&application=provider-service&bind.ip=xxx.xx.xxx.xx&bind.port=20880&channel.readonly.sent=true&codec=dubbo&deprecated=false&dubbo=2.0.2&dynamic=true&generic=false&heartbeat=60000&interface=com.dubbo.demo.service.HelloService&metadata-type=remote&methods=sayHello,noticeMsg,sayHi,addListener&pid=294076&qos.enable=false&release=2.7.8&revision=1.0-SNAPSHOT&side=provider&timestamp=1642749643629&version=2.0.0) Failed to bind NettyServer on /xxx.xx.xxx.xx:20880, cause: Cannot assign requested address at org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol.createServer(DubboProtocol.java:348) ~[dubbo-2.7.8.jar!/:2.7.8] at org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol.openServer(DubboProtocol.java:320) ~[dubbo-2.7.8.jar!/:2.7.8] at org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol.export(DubboProtocol.java:303) ~[dubbo-2.7.8.jar!/:2.7.8] at org.apache.dubbo.rpc.protocol.ProtocolListenerWrapper.export(ProtocolListenerWrapper.java:64) ~[dubbo-2.7.8.jar!/:2.7.8] at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper.export(ProtocolFilterWrapper.java:155) ~[dubbo-2.7.8.jar!/:2.7.8] at org.apache.dubbo.qos.protocol.QosProtocolWrapper.export(QosProtocolWrapper.java:66) ~[dubbo-2.7.8.jar!/:2.7.8] at org.apache.dubbo.rpc.Protocol$Adaptive.export(Protocol$Adaptive.java) ~[dubbo-2.7.8.jar!/:2.7.8] at org.apache.dubbo.registry.integration.RegistryProtocol.lambda$doLocalExport$2(RegistryProtocol.java:255) ~[dubbo-2.7.8.jar!/:2.7.8] at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660) ~[na:1.8.0_161] at org.apache.dubbo.registry.integration.RegistryProtocol.doLocalExport(RegistryProtocol.java:253) ~[dubbo-2.7.8.jar!/:2.7.8] at org.apache.dubbo.registry.integration.RegistryProtocol.export(RegistryProtocol.java:205) ~[dubbo-2.7.8.jar!/:2.7.8] at org.apache.dubbo.rpc.protocol.ProtocolListenerWrapper.export(ProtocolListenerWrapper.java:62) ~[dubbo-2.7.8.jar!/:2.7.8] at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper.export(ProtocolFilterWrapper.java:153) ~[dubbo-2.7.8.jar!/:2.7.8] at org.apache.dubbo.qos.protocol.QosProtocolWrapper.export(QosProtocolWrapper.java:64) ~[dubbo-2.7.8.jar!/:2.7.8] at org.apache.dubbo.rpc.Protocol$Adaptive.export(Protocol$Adaptive.java) ~[dubbo-2.7.8.jar!/:2.7.8] at org.apache.dubbo.config.ServiceConfig.doExportUrlsFor1Protocol(ServiceConfig.java:492) ~[dubbo-2.7.8.jar!/:2.7.8] at org.apache.dubbo.config.ServiceConfig.doExportUrls(ServiceConfig.java:325) ~[dubbo-2.7.8.jar!/:2.7.8] at org.apache.dubbo.config.ServiceConfig.doExport(ServiceConfig.java:300) ~[dubbo-2.7.8.jar!/:2.7.8] at org.apache.dubbo.config.ServiceConfig.export(ServiceConfig.java:206) ~[dubbo-2.7.8.jar!/:2.7.8] at org.apache.dubbo.config.bootstrap.DubboBootstrap.lambda$exportServices$15(DubboBootstrap.java:1103) ~[dubbo-2.7.8.jar!/:2.7.8] at java.util.HashMap$Values.forEach(HashMap.java:981) ~[na:1.8.0_161] at org.apache.dubbo.config.bootstrap.DubboBootstrap.exportServices(DubboBootstrap.java:1090) ~[dubbo-2.7.8.jar!/:2.7.8] at org.apache.dubbo.config.bootstrap.DubboBootstrap.start(DubboBootstrap.java:901) ~[dubbo-2.7.8.jar!/:2.7.8] at org.apache.dubbo.config.spring.context.DubboBootstrapApplicationListener.onContextRefreshedEvent(DubboBootstrapApplicationListener.java:59) ~[dubbo-2.7.8.jar!/:2.7.8] at org.apache.dubbo.config.spring.context.DubboBootstrapApplicationListener.onApplicationContextEvent(DubboBootstrapApplicationListener.java:52) ~[dubbo-2.7.8.jar!/:2.7.8] at org.apache.dubbo.config.spring.context.OneTimeExecutionApplicationContextEventListener.onApplicationEvent(OneTimeExecutionApplicationContextEventListener.java:40) ~[dubbo-2.7.8.jar!/:2.7.8] at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-5.2.5.RELEASE.jar!/:5.2.5.RELEASE] at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-5.2.5.RELEASE.jar!/:5.2.5.RELEASE] at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-5.2.5.RELEASE.jar!/:5.2.5.RELEASE] at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:403) ~[spring-context-5.2.5.RELEASE.jar!/:5.2.5.RELEASE] at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:360) ~[spring-context-5.2.5.RELEASE.jar!/:5.2.5.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:897) ~[spring-context-5.2.5.RELEASE.jar!/:5.2.5.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:162) ~[spring-boot-2.2.6.RELEASE.jar!/:2.2.6.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553) ~[spring-context-5.2.5.RELEASE.jar!/:5.2.5.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.6.RELEASE.jar!/:2.2.6.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.2.6.RELEASE.jar!/:2.2.6.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.2.6.RELEASE.jar!/:2.2.6.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.2.6.RELEASE.jar!/:2.2.6.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.6.RELEASE.jar!/:2.2.6.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.6.RELEASE.jar!/:2.2.6.RELEASE] at com.dubbo.provider.ProviderApplication.main(ProviderApplication.java:18) [classes!/:1.0-SNAPSHOT] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161] at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [provider-1.0-SNAPSHOT.jar:1.0-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [provider-1.0-SNAPSHOT.jar:1.0-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:51) [provider-1.0-SNAPSHOT.jar:1.0-SNAPSHOT] at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52) [provider-1.0-SNAPSHOT.jar:1.0-SNAPSHOT] Caused by: org.apache.dubbo.remoting.RemotingException: Failed to bind NettyServer on /xxx.xx.xxx.xx:20880, cause: Cannot assign requested address at org.apache.dubbo.remoting.transport.AbstractServer.(AbstractServer.java:77) ~[dubbo-2.7.8.jar!/:2.7.8] at org.apache.dubbo.remoting.transport.netty4.NettyServer.(NettyServer.java:77) ~[dubbo-2.7.8.jar!/:2.7.8] at org.apache.dubbo.remoting.transport.netty4.NettyTransporter.bind(NettyTransporter.java:35) ~[dubbo-2.7.8.jar!/:2.7.8] at org.apache.dubbo.remoting.Transporter$Adaptive.bind(Transporter$Adaptive.java) ~[dubbo-2.7.8.jar!/:2.7.8] at org.apache.dubbo.remoting.Transporters.bind(Transporters.java:56) ~[dubbo-2.7.8.jar!/:2.7.8] at org.apache.dubbo.remoting.exchange.support.header.HeaderExchanger.bind(HeaderExchanger.java:44) ~[dubbo-2.7.8.jar!/:2.7.8] at org.apache.dubbo.remoting.exchange.Exchangers.bind(Exchangers.java:70) ~[dubbo-2.7.8.jar!/:2.7.8] at org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol.createServer(DubboProtocol.java:346) ~[dubbo-2.7.8.jar!/:2.7.8] ... 48 common frames omitted Caused by: java.net.BindException: Cannot assign requested address at sun.nio.ch.Net.bind0(Native Method) ~[na:1.8.0_161] at sun.nio.ch.Net.bind(Net.java:433) ~[na:1.8.0_161] at sun.nio.ch.Net.bind(Net.java:425) ~[na:1.8.0_161] at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223) ~[na:1.8.0_161] at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:134) ~[netty-all-4.1.48.Final.jar!/:4.1.48.Final] at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:550) ~[netty-all-4.1.48.Final.jar!/:4.1.48.Final] at io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1334) ~[netty-all-4.1.48.Final.jar!/:4.1.48.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:506) ~[netty-all-4.1.48.Final.jar!/:4.1.48.Final] at io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:491) ~[netty-all-4.1.48.Final.jar!/:4.1.48.Final] at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:973) ~[netty-all-4.1.48.Final.jar!/:4.1.48.Final] at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:248) ~[netty-all-4.1.48.Final.jar!/:4.1.48.Final] at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:356) ~[netty-all-4.1.48.Final.jar!/:4.1.48.Final] at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164) ~[netty-all-4.1.48.Final.jar!/:4.1.48.Final] at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472) ~[netty-all-4.1.48.Final.jar!/:4.1.48.Final] at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500) ~[netty-all-4.1.48.Final.jar!/:4.1.48.Final] at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) ~[netty-all-4.1.48.Final.jar!/:4.1.48.Final] at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-all-4.1.48.Final.jar!/:4.1.48.Final] at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-all-4.1.48.Final.jar!/:4.1.48.Final] at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_161]

疑问

要怎样才能实现将dubbo提供者的外网地址注册到nacos中,使用配置项dubbo.protocol.host报错

juzi214032 commented 2 years ago

检查一下端口是否被占用

studyyun commented 2 years ago

没有被占用

chenhuaming commented 2 years ago

检查一下端口是否被占用

dubbo 3.0.5 可以复现这个问题。

首先配置 dubbo.protocol.port=-1 在一台centos机器里面,用docker来启动一个dubbo应用(docker hostname配置成外网域名,配置dubbo.protocol.host=hostname) 这样启动就会报20880被占用。感觉问题跟这个差不多(https://github.com/apache/dubbo/issues/8859%EF%BC%89 ====================================== 解决方法 配置了一个 dubbo.protocol.port=20957 这样可以启动成功,但是MetadataService是发布在20880端口,其他服务发布在20957。 感觉依然是个bug

studyyun commented 2 years ago

谢谢回复,我这边看了这个issues,照着你说的修改了配置dubbo.protocol.port,还是同样的报错。 我这个报错并不是提示端口已被占用,也查过端口占用情况。 我是报的这个错误:Caused by: java.net.BindException: Cannot assign requested address

chenhuaming commented 2 years ago

谢谢回复,我这边看了这个issues,照着你说的修改了配置dubbo.protocol.port,还是同样的报错。 我这个报错并不是提示端口已被占用,也查过端口占用情况。 我是报的这个错误:Caused by: java.net.BindException: Cannot assign requested address

docker在启动的时候设置docker run --hostname 设置外网可以访问的域名

studyyun commented 2 years ago

谢谢回复,我这边看了这个issues,照着你说的修改了配置dubbo.protocol.port,还是同样的报错。 我这个报错并不是提示端口已被占用,也查过端口占用情况。 我是报的这个错误:Caused by: java.net.BindException: Cannot assign requested address

docker在启动的时候设置docker run --hostname 设置外网可以访问的域名

OK,学到了,但是我这个就是普通的java -jar 启动方式

chenhuaming commented 2 years ago

可以提个bug,理论上应该可以配置在成外网地址。 Net.bind 应该直接绑定在0.0.0.0上

zuozhiwen commented 2 years ago

IP只绑定了一个网卡,没有绑定0.0.0.0导致暴露的端口在容器外部无法访问 image

zuozhiwen commented 2 years ago

先看看这个:https://dubbo.apache.org/zh/docs/advanced/set-host/

如果是容器对外映射尽量不要配置这个dubbo.protocol.host或dubbo.provider.host,得用DUBBO_IP_TO_REGISTRY环境变量的形式。而且两种配置有一定的冲突,配置了dubbo.provider.host这种的,会导致端口无法绑定到0.0.0.0,一定要删除dubbo.provider.host这几个类似的配置。


PS: DUBBO_IP_TO_REGISTRY环境变量有没有等效的服务配置项,有知道的兄弟可以分享下

chris45888 commented 2 months ago

请问这个问题解决了吗,我也遇到这个问题