Failed to bind NettyServer on /192.168.**.*:20880, cause: Failed to bind to: /0.0.0.0:20880

今天遇到的Dubbo的问题,第一天创建项目,在做Dubbo的Demo的时候遇到的问题,这个问题和解决方案,详见下面:


问题:


 Failed to bind NettyServer on /192.168.56.1:20880, cause: Failed to bind to: /0.0.0.0:20880
	at com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol.createServer(DubboProtocol.java:289)
	at com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol.openServer(DubboProtocol.java:266)
	at com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol.export(DubboProtocol.java:253)
	at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper.export(ProtocolFilterWrapper.java:55)
	at com.alibaba.dubbo.rpc.protocol.ProtocolListenerWrapper.export(ProtocolListenerWrapper.java:56)
	at com.alibaba.dubbo.rpc.Protocol$Adpative.export(Protocol$Adpative.java)
	at com.alibaba.dubbo.registry.integration.RegistryProtocol.doLocalExport(RegistryProtocol.java:153)
	at com.alibaba.dubbo.registry.integration.RegistryProtocol.export(RegistryProtocol.java:107)
	at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper.export(ProtocolFilterWrapper.java:53)
	at com.alibaba.dubbo.rpc.protocol.ProtocolListenerWrapper.export(ProtocolListenerWrapper.java:54)
	at com.alibaba.dubbo.rpc.Protocol$Adpative.export(Protocol$Adpative.java)
	at com.alibaba.dubbo.config.ServiceConfig.doExportUrlsFor1Protocol(ServiceConfig.java:485)
	at com.alibaba.dubbo.config.ServiceConfig.doExportUrls(ServiceConfig.java:281)
	at com.alibaba.dubbo.config.ServiceConfig.doExport(ServiceConfig.java:242)
	at com.alibaba.dubbo.config.ServiceConfig.export(ServiceConfig.java:143)
	at com.alibaba.dubbo.config.spring.ServiceBean.onApplicationEvent(ServiceBean.java:109)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:163)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:136)
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:381)
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:335)
	at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:855)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
	at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
	at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:93)
	at com.tgb.qmx.demo.dubbo.provider.Provider.main(Provider.java:8)
Caused by: com.alibaba.dubbo.remoting.RemotingException: Failed to bind NettyServer on /192.168.56.1:20880, cause: Failed to bind to: /0.0.0.0:20880
	at com.alibaba.dubbo.remoting.transport.AbstractServer.(AbstractServer.java:72)
	at com.alibaba.dubbo.remoting.transport.netty.NettyServer.(NettyServer.java:63)
	at com.alibaba.dubbo.remoting.transport.netty.NettyTransporter.bind(NettyTransporter.java:33)
	at com.alibaba.dubbo.remoting.Transporter$Adpative.bind(Transporter$Adpative.java)
	at com.alibaba.dubbo.remoting.Transporters.bind(Transporters.java:48)
	at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchanger.bind(HeaderExchanger.java:41)
	at com.alibaba.dubbo.remoting.exchange.Exchangers.bind(Exchangers.java:63)
	at com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol.createServer(DubboProtocol.java:287)
	... 24 more
Caused by: org.jboss.netty.channel.ChannelException: Failed to bind to: /0.0.0.0:20880
	at org.jboss.netty.bootstrap.ServerBootstrap.bind(ServerBootstrap.java:303)
	at com.alibaba.dubbo.remoting.transport.netty.NettyServer.doOpen(NettyServer.java:94)
	at com.alibaba.dubbo.remoting.transport.AbstractServer.(AbstractServer.java:67)2016-08-07 21:47:25,015 INFO [com.alibaba.dubbo.config.AbstractConfig] -  [DUBBO] Run shutdown hook now., dubbo version: 2.5.3, current host: 127.0.0.1



下面的错误:


Caused by: java.net.BindException: Address already in use: bind
	at sun.nio.ch.Net.bind0(Native Method)
	at sun.nio.ch.Net.bind(Net.java:414)
	at sun.nio.ch.Net.bind(Net.java:406)
	at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:214)
	at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
	at org.jboss.netty.channel.socket.nio.NioServerSocketPipelineSink.bind(NioServerSocketPipelineSink.java:148)
	at org.jboss.netty.channel.socket.nio.NioServerSocketPipelineSink.handleServerSocket(NioServerSocketPipelineSink.java:100)
	at org.jboss.netty.channel.socket.nio.NioServerSocketPipelineSink.eventSunk(NioServerSocketPipelineSink.java:74)
	at org.jboss.netty.channel.Channels.bind(Channels.java:468)
	at org.jboss.netty.channel.AbstractChannel.bind(AbstractChannel.java:192)
	at org.jboss.netty.bootstrap.ServerBootstrap$Binder.channelOpen(ServerBootstrap.java:348)
	at org.jboss.netty.channel.Channels.fireChannelOpen(Channels.java:176)
	at org.jboss.netty.channel.socket.nio.NioServerSocketChannel.(NioServerSocketChannel.java:85)
	at org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory.newChannel(NioServerSocketChannelFactory.java:142)
	at org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory.newChannel(NioServerSocketChannelFactory.java:90)
	at org.jboss.netty.bootstrap.ServerBootstrap.bind(ServerBootstrap.java:282)
	... 33 more


其实,我们看代码的话,就可以看到,是地址别占用的问题,我们使用的端口号是20880,说明,20880端口已经被占用了。


解决方案:


我们看Zookeeper的注册中心查找到了已经有提供者占用了20880端口:


我们发布一个系统,那么该系统的所有的提供者,就占用了20880端口:


Failed to bind NettyServer on /192.168.**.*:20880, cause: Failed to bind to: /0.0.0.0:20880_第1张图片


因此,如果我们,再写一个系统,该系统的dubbo-provider中写的20880:


Failed to bind NettyServer on /192.168.**.*:20880, cause: Failed to bind to: /0.0.0.0:20880_第2张图片


这个时候,就会报上面的错误,也就是20880端口被一个系统已经占用了,因此,这个提供者的端口,就要换一个了,换一个就随便一个没有被占用的端口就可以了:


Failed to bind NettyServer on /192.168.**.*:20880, cause: Failed to bind to: /0.0.0.0:20880_第3张图片


这样,我们运行一下provider就不会报错了:


Failed to bind NettyServer on /192.168.**.*:20880, cause: Failed to bind to: /0.0.0.0:20880_第4张图片


我们可以看一下,我们刚刚的两个系统:


Failed to bind NettyServer on /192.168.**.*:20880, cause: Failed to bind to: /0.0.0.0:20880_第5张图片


在开发环境上是这样的:


Failed to bind NettyServer on /192.168.**.*:20880, cause: Failed to bind to: /0.0.0.0:20880_第6张图片



总结:


一句话,一个系统一个端口号。







你可能感兴趣的:(&&项目开发)