文章目录
- 0. nacos客户端日志文件位置
- 最常见的问题
- 1. 容器环境端口开放不够导致的问题
- 原理解析
- 2.服务端启用了鉴权
- 客户端常见错误信息如下
- 服务端报错信息如下
- 其他一些问题
- 0. nacos高版本服务端是否支持旧的客户端?
- 1. Error code:503,msg:server is DOWN now, please try again later! during using.
- 2. com.alibaba.nacos.consistency.entity can't be found in source codes
- 3. Error Connection is unregistered. or Client not connected, current status:STARTING during startup client.
- Nacos2.0增加了用于GRPC通信的9848和9849端口。是否需要在application.properties中配置额外的设置?
- nginx 代理 nacos 2.x版本问题
- 1071 - nacos 数据库 Specified key was too long; max key length is 767 bytes, Time: 0.008000s
- nacos java.net.ConnectException: no available server, currentServerAddr
- c.a.c.n.registry.NacosServiceRegistry : nacos registry,xx register
- nacos Error to process server push response 报错
0. nacos客户端日志文件位置
有的问题我们都是基于日志分析,所以大家要了解日志的文件在哪
windows下 C:\Users\用户名\logs\nacos
linux 在 当前用户目录下 ~\logs\nacos
最常见的问题
虽然nacos支持客户端版本和服务端版本不同甚至差异很大的情况下服务端也能正常服务,但是在这个过程中会出现一些。
目前服务端2.2版本也是支持client 依赖未1.4版本正常运行。 但是当支持2.2.x客户端版本的时候,就需要做一些额外的配置。比如端口,以及鉴权等。
1. 容器环境端口开放不够导致的问题
报错信息
2023-11-01 14:14:33.223 ERROR [com.alibaba.nacos.client.remote.worker:c.a.n.c.r.c.g.GrpcClient] Server check fail, please check server 10.161.xx.xx ,port 9848 is available , error ={}
java.util.concurrent.TimeoutException: Waited 3000 milliseconds (plus 719300 nanoseconds delay) for com.alibaba.nacos.shaded.io.grpc.stub.ClientCallsKaTeX parse error: Expected '}', got 'EOF' at end of input: ….ProtoLiteUtilsMessageMarshaller@31611954, responseMarshaller=com.alibaba.nacos.shaded.io.grpc.protobuf.lite.ProtoLiteUtils M e s s a g e M a r s h a l l e r @ 3 e 598 d f 9 , s c h e m a D e s c r i p t o r = c o m . a l i b a b a . n a c o s . a p i . g r p c . a u t o . R e q u e s t G r p c MessageMarshaller@3e598df9, schemaDescriptor=com.alibaba.nacos.api.grpc.auto.RequestGrpc MessageMarshaller@3e598df9,schemaDescriptor=com.alibaba.nacos.api.grpc.auto.RequestGrpcRequestMethodDescriptorSupplier@7e31ce0f}}}]]
at com.alibaba.nacos.shaded.com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:508) ~[nacos-client-2.2.0.jar:na]
at com.alibaba.nacos.common.remote.client.grpc.GrpcClient.serverCheck(GrpcClient.java:196) [nacos-client-2.2.0.jar:na]
at com.alibaba.nacos.common.remote.client.grpc.GrpcClient.connectToServer(GrpcClient.java:307) [nacos-client-2.2.0.jar:na]
at com.alibaba.nacos.common.remote.client.RpcClient.reconnect(RpcClient.java:498) [nacos-client-2.2.0.jar:na]
at com.alibaba.nacos.common.remote.client.RpcClient.lambda$start 2 ( R p c C l i e n t . j a v a : 339 ) [ n a c o s − c l i e n t − 2.2.0. j a r : n a ] a t j a v a . u t i l . c o n c u r r e n t . E x e c u t o r s 2(RpcClient.java:339) [nacos-client-2.2.0.jar:na] at java.util.concurrent.Executors 2(RpcClient.java:339)[nacos−client−2.2.0.jar:na]atjava.util.concurrent.ExecutorsRunnableAdapter.call(Executors.java:511) ~[na:1.8.0_131]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_131]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access 201 ( S c h e d u l e d T h r e a d P o o l E x e c u t o r . j a v a : 180 ) [ n a : 1.8. 0 1 31 ] a t j a v a . u t i l . c o n c u r r e n t . S c h e d u l e d T h r e a d P o o l E x e c u t o r 201(ScheduledThreadPoolExecutor.java:180) ~[na:1.8.0_131] at java.util.concurrent.ScheduledThreadPoolExecutor 201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0131]atjava.util.concurrent.ScheduledThreadPoolExecutorScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) ~[na:1.8.0_131]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_131]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_131]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_131]
2023-11-01 14:14:36.330 ERROR [com.alibaba.nacos.client.remote.worker:c.a.n.c.r.c.g.GrpcClient] Server check fail, please check server 10.161.xx.xx ,port 9848 is available , error ={}
查阅资料
https://nacos.io/en-us/docs/v2/upgrading/2.0.0-compatibility.html
Whether support the old client? Configuration Management can support
all clients after 1.0, and Service Management can support all client
after 1.2.So recommending use Nacos client after 1.2.0.
But Nacos 1.X client can’t use new connection features, so
recommending to use 2.0.0 client strongly.Error code:503,msg:server is DOWN now, please try again later! during
using. After version 1.4, Nacos use SOFA-Jraft to replace old raft
implementation by nacos-self. Jraft will election leader with raft
protocol and save the cluster metadata. If cluster restart with ip
changed, it might cause Jraft can election leader successfully so that
nacos can’t start up.The solution is removed the data directory under nacos directory and
restart.Or use -Dnacos.server.ip=${domain} jvm parameters to start nacos and
set domain list in nacos/conf/cluster.conf to avoid the ip change
effect.com.alibaba.nacos.consistency.entity can’t be found in source codes
This package will be auto-generated by protobuf, so if you want to
read source code or do some develop, you can use mvn compile to
generate them. If you are using IDEA, you can also use IDEA’s protobuf
plugin.Error Connection is unregistered. or Client not connected, current
status:STARTING during startup client. The reason is that the client
gRPC cannot establish a connection with the server. Please use telnet
n a c o s . s e r v e r . a d d r e s s : {nacos.server.address}: nacos.server.address:{nacos.server.grpc.port} to test the network
and to check the server port is correct.If there is no problem with the server, check whether the
configuration is wrong. The configured ports of the server and client
should be the same.If there is no problem with the configuration, check whether there is
a firewall or VIP port forwarding problem. The gRPC ports of Nacos2.0
are calculated by the offset of the main port, so the port forwarding
also needs to meet the offset.Nacos2.0 adds ports 9848 and 9849 for GRPC communication. Do I need to
configure additional settings in application.properties? No, these two
ports are calculated by 8848 + 1000 and 8848 + 1001 in Nacos2.0
internally. No additional configuration by the user is required in the
configuration file. But if you are using docker or there is a port
forwarding method to start, you need to configure these two ports.###I want to start nacos2.0, and uses nginx proxy, how to deal with the port 9848, should it be exposed through nginx?
If there is a firewall or nginx port forwarding problem, you need to
configure the corresponding port exposure. For example, in nginx, on
the basis of the already exposed 8848(x), an additional 9848(x+1000)
needs to be exposed.
原理解析
在Nacos 2.2.0版本中,主要涉及4个端口
-
8848:这是Nacos服务器的默认端口,客户端通过此端口连接到Nacos服务器获取配置信息和服务注册信息。
-
7848:这是Nacos服务器的集群通信端口,它主要在集群模式下使用,用于节点间的状态同步。
-
9848:这是Nacos服务器的嵌入式的CP协议Raft通信端口。
-
9849:这是Nacos服务器的嵌入式的CP协议Raft Leader选举端口。
这些端口都可以在Nacos的配置文件中进行修改。
2.服务端启用了鉴权
服务端配置了 nacos.auth.enable=true
nacos 的yaml
kind: ConfigMap
apiVersion: v1
metadata:name: nacos-cmnamespace: hngh-devannotations:originName: nacos-cm
data:mysql.db.host: mysql8.dev.ahn1.e6niu.commysql.db.name: hnhg3_nacos_configmysql.param: characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=falsemysql.password: WiY_y_syt1gu7gvO0ev-mysql.port: '3306'mysql.user: hnhg3_usernacos.auth.enable: 'false'nacos.auth.identity.key: nacosnacos.auth.identity.value: nacosnacos.auth.token: YkFdyixnNhUZOp6pWw902QjBnqJH3HAmCJTAwYQgzu4=
客户端常见错误信息如下
错误文件在
windows下 C:\Users\用户名\logs\nacos
linux 在 当前用户目录下 ~\logs\nacos
错误内容如下
ERROR c.a.n.c.a.i.process.HttpLoginProcessor : login failed: {“code”:500,“message”:“caused: Cannot invoke “com.alibaba.nacos.plugin.auth.impl.jwt.NacosJwtParser.getExpireTimeInSeconds(String)” because “this.jwtParser” is null;”,“header”:{“header”:{“Accept-Charset”:“UTF-8”,“Authorization”:“Bearer”,“Connection”:“close”,“Content-Length”:“142”,“Content-Security-Policy”:“script-src ‘self’”,“Content-Type”:“text/html;charset=UTF-8”,“Date”:“Tue, 25 Jul 2023 02:58:33 GMT”,“Vary”:“Access-Control-Request-Headers”},“originalResponseHeader”:{“Authorization”:[“Bearer”],“Connection”:[“close”],“Content-Length”:[“142”],“Content-Security-Policy”:[“script-src ‘self’”],“Content-Type”:[“text/html;charset=UTF-8”],“Date”:[“Tue, 25 Jul 2023 02:58:33 GMT”],“Vary”:[“Access-Control-Request-Headers”,“Access-Control-Request-Method”,“Origin”]},“charset”:“UTF-8”}}
服务端报错信息如下
打开服务端日志文件,报错详情如下:
2023-07-25 10:58:23,669 ERROR CONSOLE /nacos/v1/auth/users/login
java.lang.NullPointerException: Cannot invoke “com.alibaba.nacos.plugin.auth.impl.jwt.NacosJwtParser.getExpireTimeInSeconds(String)” because “this.jwtParser” is null
at com.alibaba.nacos.plugin.auth.impl.token.impl.JwtTokenManager.getTokenTtlInSeconds(JwtTokenManager.java:150)
at com.alibaba.nacos.plugin.auth.impl.token.TokenManagerDelegate.getTokenTtlInSeconds(TokenManagerDelegate.java:89)
at com.alibaba.nacos.plugin.auth.impl.controller.UserController.login(UserController.java:235)
at jdk.internal.reflect.GeneratedMethodAccessor38.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
at
其他一些问题
0. nacos高版本服务端是否支持旧的客户端?
配置管理支持1.0之后的所有客户端,服务管理支持1.2之后的所有客户端。
因此,建议使用1.2.0之后的Nacos客户端。
但是,Nacos 1.X客户端不能使用新的连接功能,所以强烈建议使用2.0.0客户端。
1. Error code:503,msg:server is DOWN now, please try again later! during using.
在使用过程中出现错误代码:503,消息:服务器现在关闭,请稍后再试!
在1.4版本之后,Nacos用SOFA-Jraft替换了自己的旧raft实现。Jraft会用raft协议选举领导者并保存集群元数据。如果集群在ip改变后重启,可能会导致Jraft无法成功选举领导者,从而使nacos无法启动。
解决方案
删除nacos目录下的数据目录并重新启动。
或者使用-Dnacos.server.ip=${domain} jvm参数启动nacos,并在nacos/conf/cluster.conf中设置域名列表,以避免ip更改影响。
2. com.alibaba.nacos.consistency.entity can’t be found in source codes
在源代码中找不到com.alibaba.nacos.consistency.entity 错误
这个包是由protobuf自动生成的,所以如果你想阅读源代码或进行一些开发,你可以使用mvn编译来生成它们。如果你在使用IDEA,你也可以使用IDEA的protobuf插件。
3. Error Connection is unregistered. or Client not connected, current status:STARTING during startup client.
启动客户端时出现错误 连接未注册。或者 客户端未连接,当前状态:正在启动。
原因是客户端gRPC无法与服务器建立连接。
解决方案
请使用telnet n a c o s . s e r v e r . a d d r e s s : {nacos.server.address}: nacos.server.address:{nacos.server.grpc.port}测试网络,并检查服务器端口是否正确。
如果服务器没有问题,检查配置是否错误。服务器和客户端的配置端口应该相同。
如果配置没有问题,检查是否存在防火墙或VIP端口转发问题。Nacos2.0的gRPC端口是通过主端口的偏移量计算的,所以端口转发也需要满足偏移量。
Nacos2.0增加了用于GRPC通信的9848和9849端口。是否需要在application.properties中配置额外的设置?
不需要,这两个端口在Nacos2.0内部通过8848 + 1000和8848 + 1001计算得出。用户在配置文件中不需要进行额外配置。
但是,如果你正在使用docker或者有端口转发方式启动,你需要配置这两个端口。
nginx 代理 nacos 2.x版本问题
如果存在防火墙或nginx端口转发问题,需要配置相应的端口暴露。例如,在nginx中,除了已经暴露的8848(x),还需要额外暴露9848(x+1000)。
1071 - nacos 数据库 Specified key was too long; max key length is 767 bytes, Time: 0.008000s
这个是bug 已经修复 https://github.com/alibaba/nacos/pull/11307
nacos java.net.ConnectException: no available server, currentServerAddr
这个问题在容器环境遇到过,因为服务下线和网络不稳定导致
c.a.c.n.registry.NacosServiceRegistry : nacos registry,xx register
failed…NacosRegistration{nacosDiscoveryProperties=NacosDiscoveryProperties{serverAddr=‘nacos:8848’, username=‘service’, password=‘nacos’, endpoint=‘’, namespace=‘’, watchDelay=30000, logName=‘’, service=‘xx’, weight=1.0, clusterName=‘DEFAULT’, group=‘DEFAULT_GROUP’, namingLoadCacheAtStart=‘false’, metadata={IPv6=null, preserved.register.source=SPRING_CLOUD}, registerEnabled=true, ip=‘xx.xx.xx.xx’, networkInterface=‘’, port=xx, secure=false, accessKey=‘’, secretKey=‘’, heartBeatInterval=null, heartBeatTimeout=null, ipDeleteTimeout=null, instanceEnabled=true, ephemeral=true, failureToleranceEnabled=false}, ipDeleteTimeout=null, failFast=true}},
com.alibaba.nacos.api.exception.NacosException: authorization failed!
nacos Error to process server push response 报错
通过debug发现,好像是PlayloadRegistry中的 REGISTRY_REQUEST,没有注册NotifySubscriberRequest ,从服务端push一个这个类型的消息过来。
引入依赖导致的
<dependency><groupId>org.reflections</groupId><artifactId>reflections</artifactId>
</dependency>