环境
centos7、jdk8、nacos-server-2.2.0.1.tar.gz
jdk配置(略)
部署nacos
- 参照官方文档 https://nacos.io/zh-cn/docs/v2/quickstart/quick-start.html,下载nacos(https://github.com/alibaba/nacos/releases/download/2.2.0.1/nacos-server-2.2.0.1.tar.gz),下载稳定版
- 上传压缩包到/usr/local下,解压压缩包
tar -zxvf nacos-server-2.2.0.1.tar.gz
- 执行启动命令
cd nacos/bin
sh startup.sh -m standalone
- 出现如下提示
nacos is starting with standalone
nacos is starting,you can check the /usr/local/nacos/logs/start.out
- 打开输入日志,如下异常
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'user': Unsatisfied dependency expressed through field 'jwtTokenManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jwtTokenManager' defined in URL [jar:file:/usr/local/nacos/target/nacos-server.jar!/BOOT-INF/lib/nacos-plugin-default-impl-2.2.0.jar!/com/alibaba/nacos/plugin/auth/impl/JwtTokenManager.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.alibaba.nacos.plugin.auth.impl.JwtTokenManager]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: the length of secret key must great than or equal 32 bytes; And the secret key must be encoded by base64.Please see https://nacos.io/zh-cn/docs/v2/guide/user/auth.html
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:659)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:639)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)
- 打开官网,提示打开授权和配置密钥
- 打开nacos/conf下的application.properties,修改如下两个配置项
### If turn on auth system:
nacos.core.auth.enabled=true
### The default token (Base64 String):
nacos.core.auth.plugin.nacos.token.secret.key=VGhpc0lzTXlDdXN0b21TZWNyZXRLZXkwMTIzNDU2Nzg=
- 再次启动,检查日志
2023-03-14 14:09:15,218 INFO Will secure any request with [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@138fe6ec, org.springframework.security.web.context.SecurityContextPersistenceFilter@3bd7f8dc, org.springframework.security.web.header.HeaderWriterFilter@54107f42, org.springframework.security.web.csrf.CsrfFilter@5ae76500, org.springframework.security.web.authentication.logout.LogoutFilter@4b21844c, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@1eba372c, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@25f9407e, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@5e77f0f4, org.springframework.security.web.session.SessionManagementFilter@476aac9, org.springframework.security.web.access.ExceptionTranslationFilter@770d0ea6]
2023-03-14 14:09:15,289 INFO Exposing 1 endpoint(s) beneath base path '/actuator'
2023-03-14 14:09:15,614 INFO Tomcat started on port(s): 8848 (http) with context path '/nacos'
2023-03-14 14:09:15,689 INFO Nacos started successfully in stand alone mode. use embedded storage
- 访问 http://IP:8848/nacos,输入默认账号密码nacos/nacos,打开配置页面