Nacos 2.2.3+Seata+Sentinel 版本踩坑
Seata1.6.1使用Nacos2.2.3配置中心时报错
问题出现场景
本地Nacos版本基于2.2.1进行正常seata以及sentinel环境搭建配置成功运行,开发环境进行了Nacos版本升级,并未及时告知,导致链接失败。
seata+nacos配置中心进行配置的时候, seata日志里会一直报错:
c.a.nacos.client.security.SecurityProxy : [SecurityProxy] login http request failed url: http://10.10.*.1*:8848/nacos/v1/auth/users/login, params: {username=nacos},
bodyMap: {password=nacos},
errorMsg: Server returned HTTP response code: 500 for URL:
java.lang.NullPointerException: 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)
问题出现原因
由于以前版本配置文件中配置文件默认开启登录验证,新版本配置中默认不开启登录验证,导致seata配置文件中配置了登录用户名以及密码,登录失败。
当前排查版本差异。2.2.1版本默认为true,2.2.3版本默认为false。
nacos.conf.application.properties文件中138行左右
nacos.core.auth.caching.enabled=true/false
### The ignore urls of auth
nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-ui/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**
### The auth system to use, currently only 'nacos' and 'ldap' is supported:
nacos.core.auth.system.type=nacos
### If turn on auth system:
nacos.core.auth.enabled=false
### Turn on/off caching of auth information. By turning on this switch, the update of auth information would have a 15 seconds delay.
nacos.core.auth.caching.enabled=true
### Since 1.4.1, Turn on/off white auth for user-agent: nacos-server, only for upgrade from old version.
nacos.core.auth.enable.userAgentAuthWhite=false
### Since 1.4.1, worked when nacos.core.auth.enabled=true and nacos.core.auth.enable.userAgentAuthWhite=false.
### The two properties is the white list for auth and used by identity the request from other server.
nacos.core.auth.server.identity.key=
nacos.core.auth.server.identity.value=
问题解决
解决方式其两种,任选其一
其一:将nacos配置文件中修改为true
nacos.core.auth.caching.enabled=true
其二:将seata中配置链接nacos的用户名和密码去除
seata:
# 配置中心,以下是以nacos为配置中心
config:
# support: nacos, consul, apollo, zk, etcd3
type: nacos
nacos:
server-addr: 10.10.*.*:8848
# 以下namespace命名空间,需要在nacos中手动创建
namespace: 07ccbec381a011d121a215719199ac49
group: DEFAULT_GROUP
# username: nacos
# password: nacos
context-path:
##if use MSE Nacos with auth, mutex with username/password attribute
#access-key:
#secret-key:
data-id: seataServer.properties