nacos
今天在使用nacos时,启动时一直报错,错误日志如下:
2024-09-16 08:27:57 Caused by: java.lang.RuntimeException: com.alibaba.nacos.api.exception.runtime.NacosRuntimeException: errCode: 500, errMsg: load derby-schema.sql error.
2024-09-16 08:27:57 at com.alibaba.nacos.config.server.service.datasource.DynamicDataSource.getDataSource(DynamicDataSource.java:60)
2024-09-16 08:27:57 at com.alibaba.nacos.config.server.service.repository.embedded.StandaloneDatabaseOperateImpl.init(StandaloneDatabaseOperateImpl.java:60)
2024-09-16 08:27:57 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2024-09-16 08:27:57 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
2024-09-16 08:27:57 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2024-09-16 08:27:57 at java.lang.reflect.Method.invoke(Method.java:498)
2024-09-16 08:27:57 at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:389)
2024-09-16 08:27:57 at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:333)
2024-09-16 08:27:57 at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:157)
2024-09-16 08:27:57 ... 125 common frames omitted
2024-09-16 08:27:57 Caused by: com.alibaba.nacos.api.exception.runtime.NacosRuntimeException: errCode: 500, errMsg: load derby-schema.sql error.
2024-09-16 08:27:57 at com.alibaba.nacos.config.server.service.datasource.LocalDataSourceServiceImpl.reload(LocalDataSourceServiceImpl.java:100)
2024-09-16 08:27:57 at com.alibaba.nacos.config.server.service.datasource.LocalDataSourceServiceImpl.initialize(LocalDataSourceServiceImpl.java:167)
2024-09-16 08:27:57 at com.alibaba.nacos.config.server.service.datasource.LocalDataSourceServiceImpl.init(LocalDataSourceServiceImpl.java:83)
2024-09-16 08:27:57 at com.alibaba.nacos.config.server.service.datasource.DynamicDataSource.getDataSource(DynamicDataSource.java:49)
2024-09-16 08:27:57 ... 133 common frames omitted
2024-09-16 08:27:57 Caused by: java.sql.SQLTimeoutException: Login timeout exceeded.
2024-09-16 08:27:57 at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
2024-09-16 08:27:57 at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
2024-09-16 08:27:57 at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
2024-09-16 08:27:57 at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
2024-09-16 08:27:57 at org.apache.derby.jdbc.InternalDriver.timeLogin(Unknown Source)
2024-09-16 08:27:57 at org.apache.derby.jdbc.InternalDriver.connect(Unknown Source)
2024-09-16 08:27:57 at org.apache.derby.jdbc.InternalDriver.connect(Unknown Source)
2024-09-16 08:27:57 at org.apache.derby.jdbc.EmbeddedDriver.connect(Unknown Source)
2024-09-16 08:27:57 at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138)
2024-09-16 08:27:57 at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:354)
2024-09-16 08:27:57 at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:202)
2024-09-16 08:27:57 at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:473)
2024-09-16 08:27:57 at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:554)
2024-09-16 08:27:57 at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115)
2024-09-16 08:27:57 at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
2024-09-16 08:27:57 at com.alibaba.nacos.config.server.service.datasource.LocalDataSourceServiceImpl.reload(LocalDataSourceServiceImpl.java:95)
2024-09-16 08:27:57 ... 136 common frames omitted
2024-09-16 08:27:57 Caused by: org.apache.derby.iapi.error.StandardException: Login timeout exceeded.
2024-09-16 08:27:57 at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
2024-09-16 08:27:57 at org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown Source)
2024-09-16 08:27:57 ... 152 common frames omitted
2024-09-16 08:27:57 2024-09-16 08:27:57,603 WARN [WatchFileCenter] start close
核心的错误:
- Caused by: java.lang.RuntimeException: com.alibaba.nacos.api.exception.runtime.NacosRuntimeException: errCode: 500, errMsg:
load derby-schema.sql error.
- Caused by: com.alibaba.nacos.api.exception.runtime.NacosRuntimeException: errCode: 500, errMsg:
load derby-schema.sql error
. - Caused by: java.sql.SQLTimeoutException: Login timeout exceeded.
我的解决方法,将derby 换成 mysql
找到nacos的配置目录,找到其中的 application.properties
和mysql-schema.sql
- 将数据库初始化脚本执行,先创建一个数据库如:
nacos_config
, 执行完成后,数据表如下:
- 修改配置文件,需要注意的就是数据库url中的IP地址,需要换成真实的地址(我的是跑在docker中,所以就用了
172.17.0.1
)
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://172.17.0.1:3306/nacos_config?characterEncoding=utf8&serverTimezone=Asia/Shanghai&connectTimeout=1000&socketTimeout=3000&autoReconnect=true # 网络地址需要你实际的地址,localhost(127.0.0.1)环回测试地址并不可用
db.user=root # 替换成你自己的
db.password=123456 # 替换成你自己的
- 解决
错误的解决方法!!!(删除derby)
解决方法:把nacos的数据卷映射目录中的/data/nacos/data/derby-data
目录删除,然后重新启动。
这是一开始在某篇博客下看到的,删除掉derby后,nacos的数据会丢失,共享配置啥的…,错误的!