Nacos v2.2运行出错

文章描述了在初次运行Nacos时遇到的由于JWT密钥不足256位导致的异常,以及如何通过修改`application.properties`文件,设置`nacos.core.auth.*`相关参数来解决此问题。首先,将默认的secretkey设置为足够安全的值,然后添加serveridentitykey和value以满足认证需求,最终成功运行Nacos。
摘要由CSDN通过智能技术生成

第一次下载Nacos,直接运行后出现异常错误:

Caused by: java.lang.IllegalArgumentException: The specified key byte array is 0 bits which is not secure enough for any JWT HMAC-SHA algorithm.  The JWT JWA Specification (RFC 7518, Section 3.2) states that keys used with HMAC-SHA algorithms MUST have a size >= 256 bits (the key size must be greater than or equal to the hash output size).  See https://tools.ietf.org/html/rfc7518#section-3.2 for more information.
        at com.alibaba.nacos.plugin.auth.impl.jwt.NacosJwtParser.<init>(NacosJwtParser.java:56)
        at com.alibaba.nacos.plugin.auth.impl.token.impl.JwtTokenManager.processProperties(JwtTokenManager.java:71)
        ... 115 common frames omitted
2023-03-23 11:20:14,716 WARN [ThreadPoolManager] Start destroying ThreadPool

查看某度、官方才知道,Nacos官方因前期爆出的权限漏洞,把安装包内的默认参数置空了,所以把application.properties文件修改如下:

nacos.core.auth.enabled=true 
nacos.core.auth.system.type=nacos #启用
nacos.core.auth.plugin.nacos.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789 #官方默认参数,自行修改

然后再尝试运行,出现如下异常信息:

Caused by: com.alibaba.nacos.api.exception.NacosException: Empty identity, Please set `nacos.core.auth.server.identity.key` and `nacos.core.auth.server.identity.value`, detail: https://nacos.io/zh-cn/docs/v2/guide/user/auth.html
        at com.alibaba.nacos.auth.config.AuthConfigs.validate(AuthConfigs.java:100)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
        at java.base/java.lang.reflect.Method.invoke(Method.java:578)
        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)

修改参数配置文件:

### The two properties is the white list for auth and used by identity the request from other server.
nacos.core.auth.server.identity.key=test
nacos.core.auth.server.identity.value=test

修改后,运行成功!

安装Nacos源码2.2的步骤如下: 1. 首先,你需要下载Nacos源码。你可以从Nacos的官方GitHub仓库下载最新的源码版本。 2. 下载完成后,解压源码包到你想要的目录。 3. 接下来,你需要配置并安装构建工具。Nacos使用Gradle作为构建工具,所以你需要确保你已经安装了Gradle。你可以在Gradle的官方网站上下载并安装最新版本的Gradle。 4. 打开命令行终端,进入到解压后的Nacos源码目录。 5. 在命令行中执行以下命令以编译和构建Nacos项目: ``` ./gradlew build ``` 6. 等待编译和构建过程完成。这可能需要一些时间,取决于你的计算机性能和网络连接速度。 7. 编译和构建成功后,你可以在`target`目录下找到生成的Nacos服务端jar包。 8. 现在,你可以按照Nacos的官方文档提供的指南,进行配置和启动Nacos服务端。你可以参考Nacos官方文档中关于如何部署和运行Nacos的详细说明。 总结起来,你需要下载Nacos源码,安装构建工具Gradle,然后在命令行中进行编译和构建。最后,根据官方文档的指南进行配置和启动Nacos服务端。 <span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [Nacos源码分析](https://blog.csdn.net/qq_41720396/article/details/124066829)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [Nacos源码流程——服务注册与发现.png](https://download.csdn.net/download/qq_30166729/12297304)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值