gz-yami / mall4cloud

⭐️⭐️⭐️微服务商城系统 springcloud微服务商城 小程序商城
https://www.mall4j.com
GNU Affero General Public License v3.0
5.99k stars 1.49k forks source link

新版nacos容器无法正常启动 #15

Open DiiD1999 opened 1 year ago

DiiD1999 commented 1 year ago

环境

  1. CentOS7.6
  2. 使用最新docker-compose.yaml,部署运行了nacos容器

现象

  1. 通过http://192.168.1.46:8848/nacos无法进入Nacos管理界面
  2. 其他docker容器如MySQLRocketMQ等都正常启动。
  3. 使用docker ps -a | grep nacos 命令查看nacos状态,发现nacos一直处于重启状态。命令结果如下
[root@slave1 ~]# docker ps -a | grep nacos
90fb3b7bc783   nacos/nacos-server:v2.2.0-slim             "bin/docker-startup.…"   2 hours ago   Restarting (1) Less than a second ago                                                                                                                       mall4cloud-nacos
  1. 使用vim /root/docker/nacos/logs/nacos.log查看日志发现,在nacos中存在以下错误Unknown column 'encrypted_data_key' in 'field list'.具体错误片段如下
2023-03-02 17:32:43,237 INFO

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.

2023-03-02 17:32:43,257 ERROR Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'memoryMonitor' defined in URL [jar:file:/home/nacos/target/nacos-server.jar!/BOOT-INF/lib/nacos-config-2.2.0.jar!/com/alibaba/nacos/config/server/monitor/MemoryMonitor.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'asyncNotifyService': Unsatisfied dependency expressed through field 'dumpService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'externalDumpService': Invocation of init method failed; nested exception is ErrCode:500, ErrMsg:Nacos Server did not start because dumpservice bean construction failure :
PreparedStatementCallback; bad SQL grammar [SELECT id,data_id,group_id,tenant_id,app_name,content,md5,gmt_modified,type,encrypted_data_key FROM config_info WHERE id > ? ORDER BY id ASC LIMIT 0,1000]; nested exception is java.sql.SQLSyntaxErrorException: Unknown column 'encrypted_data_key' in 'field list'

原因

为保证用户敏感配置数据的安全,Nacos 提供了配置加密的新特性。降低了用户使用的风险,也不需要再对配置进行单独的加密处理。新版本的默认创建表的sql中已经添加该字段。

docker-compose.yml执行时在导入MySQLmall4cloud_nacos数据库与表结构并没有该字段。导致nacos容器无法正常启动。

解决

数据库表 config_info、config_info_beta、his_config_info中需要新增字段 encrypted_data_key ,用来存储每一个配置项加密使用的秘钥。在mall4cloud_nacos数据库下执行以下语句

ALTER TABLE config_info ADD COLUMN `encrypted_data_key` text NOT NULL COMMENT '秘钥';
ALTER TABLE config_info_beta ADD COLUMN `encrypted_data_key` text NOT NULL COMMENT '秘钥';
ALTER TABLE his_config_info ADD COLUMN `encrypted_data_key` text NOT NULL COMMENT '秘钥';
gz-yami commented 1 year ago

已解决

zhx47 commented 1 year ago

已解决

config_intoencrypted_data_key 字段定义为非空,但是插入语句给的是 null,貌似偷懒了啊,哈哈