环境准备
- 64 位操作系统,Windows 10 / Linux Centos 7
- JDK 1.8
安装包下载
安装包下载官方地址:https://github.com/alibaba/nacos/releases
启动
将安装包解压到安装的目录下,改名为 nacos-2.0.4。然后进行到 bin 目录下,打开 CMD 窗口,使用如下命令以非集群模式启动服务。
startup.cmd -m standalone
如果要关闭 Nacos 服务,直接双击关闭脚本文件 shutdown.cmd 即可。
修改配置
为什么要修改配置?
遇到的问题: 创建命名空间时,页面无反应,后端报错。默认数据库可能存在问题,故切换为mysql.
spring.sql.init.platform=mysql
db.num=1
db.url.0=jdbc:mysql://loclhos:3306/nacos?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&useSSL=false&autoReconnect=true&rewriteBatchedStatements=true&useAffectedRows=true&allowMultiQueries=true
db.user.0=账户
db.password.0=密码
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [SELECT id,quota,`usage`,`max_size`,max_aggr_count,max_aggr_size,tenant_id FROM tenant_capacity WHERE tenant_id = ?]; nested exception is java.sql.SQLSyntaxErrorException: Lexical error at line 1, column 17. Encountered: "`" (96), after : "".at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:236)at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)at org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1575)at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:667)at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:713)at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:744)at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:757)at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:810)at com.alibaba.nacos.config.server.service.capacity.TenantCapacityPersistService.getTenantCapacity(TenantCapacityPersistService.java:101)at com.alibaba.nacos.config.server.service.NamespaceConfigInfoService.injectDetail(NamespaceConfigInfoService.java:48)at com.alibaba.nacos.core.namespace.injector.NamespaceDetailInjectorHolder.injectDetail(NamespaceDetailInjectorHolder.java:54)at com.alibaba.nacos.core.service.NamespaceOperationService.getNamespaceList(NamespaceOperationService.java:69)at com.alibaba.nacos.console.controller.NamespaceController.getNamespaces(NamespaceController.java:73)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.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:903)at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:809)at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1072)at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:965)at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)at javax.servlet.http.HttpServlet.service(HttpServlet.java:529)at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)at javax.servlet.http.HttpServlet.service(HttpServlet.java:623)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:199)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:144)at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:168)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:144)at com.alibaba.nacos.console.filter.XssFilter.doFilterInternal(XssFilter.java:42)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:168)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:144)at org.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter.java:91)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:168)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:144)at com.alibaba.nacos.core.paramcheck.ParamCheckerFilter.doFilter(ParamCheckerFilter.java:84)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:168)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:144)at com.alibaba.nacos.core.auth.AuthFilter.doFilter(AuthFilter.java:71)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:168)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:144)at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214)at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:186)at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:354)at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:267)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:168)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:144)at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:168)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:144)at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:168)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:144)at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:96)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:168)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:144)at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:168)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:144)at com.alibaba.nacos.core.context.remote.HttpRequestContextFilter.doFilter(HttpRequestContextFilter.java:57)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:168)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:144)at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:168)at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90)at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:482)at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:130)at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93)at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:660)at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:346)at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:383)at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63)at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:936)at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1791)at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1190)at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63)at java.base/java.lang.Thread.run(Thread.java:1623)