在一台机器上面搭建 nacos-server-2.2.3 集群,启动集群抛 “Failed to bind to address 0.0.0.0/0.0.0.0:9848,java.net.BindException: Address already in use: bind” 错误。
详细错误信息如下:
"nacos is starting with cluster" ,--. ,--.'| ,--,: : | Nacos 2.2.3 ,`--.'`| ' : ,---. Running in cluster mode, All function modules | : : | | ' ,'\ .--.--. Port: 8847 : | \ | : ,--.--. ,---. / / | / / ' Pid: 10028 | : ' '; | / \ / \. ; ,. :| : /`./ Console: http://10.87.10.89:8847/nacos/index.html ' ' ;. ;.--. .-. | / / '' | |: :| : ;_ | | | \ | \__\/: . .. ' / ' | .; : \ \ `. https://nacos.io ' : | ; .' ," .--.; |' ; :__| : | `----. \ | | '`--' / / ,. |' | '.'|\ \ / / /`--' / ' : | ; : .' \ : : `----' '--'. / ; |.' | , .-./\ \ / `--'---' '---' `--`---' `----' 2023-10-30 08:40:31,879 INFO The server IP list of Nacos is [127.0.0.1:8847, 127.0.0.1:8848, 127.0.0.1:8849] ... 2023-10-30 08:41:56,499 INFO Nacos Log files: E:\nacos-server-2.2.3-1\logs 2023-10-30 08:41:56,530 INFO Nacos Log files: E:\nacos-server-2.2.3-1\conf 2023-10-30 08:41:56,561 INFO Nacos Log files: E:\nacos-server-2.2.3-1\data 2023-10-30 08:41:56,580 ERROR Startup errors : org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grpcClusterServer': Invocation of init method failed; nested exception is java.io.IOException: Failed to bind to address 0.0.0.0/0.0.0.0:9848 at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:160) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:440) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$200/1651855867.getObject(Unknown Source) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:745) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:423) at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1317) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) at com.alibaba.nacos.Nacos.main(Nacos.java:35) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) at org.springframework.boot.loader.PropertiesLauncher.main(PropertiesLauncher.java:467) Caused by: java.io.IOException: Failed to bind to address 0.0.0.0/0.0.0.0:9848 at io.grpc.netty.shaded.io.grpc.netty.NettyServer.start(NettyServer.java:328) at io.grpc.internal.ServerImpl.start(ServerImpl.java:184) at io.grpc.internal.ServerImpl.start(ServerImpl.java:93) at com.alibaba.nacos.core.remote.grpc.BaseGrpcServer.startServer(BaseGrpcServer.java:106) at com.alibaba.nacos.core.remote.BaseRpcServer.start(BaseRpcServer.java:59) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:389) at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:333) at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:157) ... 27 common frames omitted 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:437) at sun.nio.ch.Net.bind(Net.java:429) at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223) at io.grpc.netty.shaded.io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:141) at io.grpc.netty.shaded.io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:562) at io.grpc.netty.shaded.io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1334) at io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:506) at io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:491) at io.grpc.netty.shaded.io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:973) at io.grpc.netty.shaded.io.netty.channel.AbstractChannel.bind(AbstractChannel.java:260) at io.grpc.netty.shaded.io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:356) at io.grpc.netty.shaded.io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:174) at io.grpc.netty.shaded.io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:167) at io.grpc.netty.shaded.io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470) at io.grpc.netty.shaded.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:503) at io.grpc.netty.shaded.io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) at io.grpc.netty.shaded.io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) at io.grpc.netty.shaded.io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.lang.Thread.run(Thread.java:745) 2023-10-30 08:41:57,140 WARN [WatchFileCenter] start close 2023-10-30 08:41:57,140 WARN [WatchFileCenter] start to shutdown this watcher which is watch : E:\nacos-server-2.2.3-1\conf 2023-10-30 08:41:57,140 WARN [WatchFileCenter] already closed 2023-10-30 08:41:57,171 WARN [NotifyCenter] Start destroying Publisher 2023-10-30 08:41:57,171 WARN [NotifyCenter] Destruction of the end 2023-10-30 08:41:57,186 ERROR Nacos failed to start, please see E:\nacos-server-2.2.3-1\logs\nacos.log for more details. 2023-10-30 08:41:57,485 WARN [ThreadPoolManager] Start destroying ThreadPool 2023-10-30 08:41:57,485 WARN [ThreadPoolManager] Destruction of the end
Nacos 默认端口是 8848,2.0 版本后另外还占用 9848,9849 两个端口,这两个是 gRPC 端口,用于服务端与客户端通讯,所以在单机上配置集群节点,节点要配置的端口不能连续,否则在启动时报端口占用的错误。
9848 端口:与主端口(8848)偏移量为 1000,用来客户端gRPC请求服务端口,用户客户端向服务端发起连接和请求
9849 端口:与主端口(8848)偏移量为 1001,用来服务端gRPC请求服务端口,用于服务间同步等
注意:Nacos 单机集群,端口不能连续;而且 Nginx 反向代理,需要配置 gRPC 端口映射。
例如,我们使用连续端口:
8847 -> gRPC 端口:9847,9848
8848 -> gRPC 端口:9848,9849
8849 -> gRPC 端口:9849,9850
上面连续端口根据偏移量计算出的 gRPC 端口中,9848、9849 两个端口冲突了,所以启动失败。
将 Nacos 的端口错开修改,如:
8748
8848
8948