将nacos从本地切换到远程服务器上时报错:客户端端未连接,Client not connected
报错信息:
09:34:38.438 [com.alibaba.nacos.client.Worker] ERROR com.alibaba.nacos.common.remote.client - Send request fail, request = ConfigBatchListenRequest{headers={charset=UTF-8, Client-AppName=unknown, Client-RequestToken=65c0fbf47282ae0a7b85178dcf076771, Client-RequestTS=1684114478337, exConfigInfo=true}, requestId='null'}, retryTimes = 0, errorMessage = Client not connected, current status:STARTING
09:34:38.462 [com.alibaba.nacos.client.remote.worker] ERROR com.alibaba.nacos.common.remote.client.grpc.GrpcClient - Server check fail, please check server localhost ,port 9848 is available , error =java.util.concurrent.ExecutionException: com.alibaba.nacos.shaded.io.grpc.StatusRuntimeException: UNAVAILABLE: io exception
09:34:38.539 [com.alibaba.nacos.client.Worker] ERROR com.alibaba.nacos.common.remote.client - Send request fail, request = ConfigBatchListenRequest{headers={charset=UTF-8, Client-AppName=unknown, Client-RequestToken=65c0fbf47282ae0a7b85178dcf076771, Client-RequestTS=1684114478337, exConfigInfo=true}, requestId='null'}, retryTimes = 1, errorMessage = Client not connected, current status:STARTING
09:34:38.640 [com.alibaba.nacos.client.Worker] ERROR com.alibaba.nacos.common.remote.client - Send request fail, request = ConfigBatchListenRequest{headers={charset=UTF-8, Client-AppName=unknown, Client-RequestToken=65c0fbf47282ae0a7b85178dcf076771, Client-RequestTS=1684114478337, exConfigInfo=true}, requestId='null'}, retryTimes = 2, errorMessage = Client not connected, current status:STARTING
09:34:38.640 [com.alibaba.nacos.client.Worker] ERROR com.alibaba.nacos.client.config.impl.ClientWorker - Async listen config change error
com.alibaba.nacos.api.exception.NacosException: Client not connected, current status:STARTING
at com.alibaba.nacos.common.remote.client.RpcClient.request(RpcClient.java:651) ~[nacos-client-2.1.0.jar:?]
at com.alibaba.nacos.client.config.impl.ClientWorker$ConfigRpcTransportClient.requestProxy(ClientWorker.java:1005) ~[nacos-client-2.1.0.jar:?]
at com.alibaba.nacos.client.config.impl.ClientWorker$ConfigRpcTransportClient.requestProxy(ClientWorker.java:986) ~[nacos-client-2.1.0.jar:?]
at com.alibaba.nacos.client.config.impl.ClientWorker$ConfigRpcTransportClient.executeConfigListen(ClientWorker.java:777) ~[nacos-client-2.1.0.jar:?]
at com.alibaba.nacos.client.config.impl.ClientWorker$ConfigRpcTransportClient.lambda$startInternal$2(ClientWorker.java:695) ~[nacos-client-2.1.0.jar:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_201]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_201]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_201]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:1.8.0_201]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_201]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_201]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_201]
找到了其中比较关键的一句:ERROR com.alibaba.nacos.common.remote.client.grpc.GrpcClient - Server check fail, please check server localhost,port 9848 is available , error =java.util.concurrent.ExecutionException: com.alibaba.nacos.shaded.io.grpc.StatusRuntimeException: UNAVAILABLE: io exception 大意是:请检查”服务器localhost 端口9848 ,这个服务器不可用“
本地nacos并没有启动,所以这样提示没有问题,但是问题在于为什么会提示服务器是localhost本地,而不是远程服务器,因为有关nacos的配置全都是配置的远程服务器的地址、端口等。
解决:
检查项目配置是否改掉了配置:没有改成远程的nacos的配置。结果发现配置没有问题,因为整个配置的更改都是直接使用Eclipse的替换的。 但是替换有个问题是:只能替换已有的文本,对应默认的配置是没法替换的。 比如,当前这个问题,就是因为spring.cloud.nacos.config的配置信息中没有配置nacos的配置地址spring.cloud.nacos.config.server-addr(采用的默认的本地地址端口localhost:8848), 只配置了nacos的服务发现的地址,spring.cloud.nacos.discovery.server-addr=47.109.90.76:8848。 所以,一定要显示同时配置出Nacos的服务注册/发现以及配置的地址,如下:
spring.application.name=your-application-name
spring.cloud.nacos.discovery.server-addr=ip:port
spring.cloud.nacos.discovery.enabled=true
spring.cloud.nacos.username=nacos
spring.cloud.nacos.password=your-password
spring.cloud.nacos.config.server-addr=ip:port
spring.cloud.nacos.config.group=your-group-name
spring.cloud.nacos.config.file-extension=properties
spring.cloud.nacos.config.refresh-enabled=true