Skip to main content

Nacos更换达梦数据库

tip

采用nacos2.3.2的源码进行编译:https://github.com/alibaba/nacos/archive/refs/tags/2.3.2.zip

nacos插件源码:https://github.com/pkyit/nacos-plugin/archive/refs/heads/develop.zip

配置数据库

1 获取数据库配置

可以使用docker进行简易部署安装,以下是编排代码:

version: '2'
services:
dameng8:
image: dm8_single:dm8_20240715_rev232765_x86_rh6_64
container_name: dameng8
privileged: true
ports:
- "5236:5236"
environment:
TZ: Asia/Shanghai
LD_LIBRARY_PATH: /opt/dmdbms/bin
PAGE_SIZE: 16
EXTENT_SIZE: 32
LOG_SIZE: 1024
UNICODE_FLAG: 1
LENGTH_IN_CHAR: 0
INSTANCE_NAME: dm8_shanhy
volumes:
- /opt/soft/dameng8/data:/opt/dmdbms/data
logging:
driver: "json-file"
options:
max-size: "500m"
max-file: "5"

运行SQL文件:达梦数据库SQL !!!!!!!!!!!!!!!!!!

在naming模块和console模块的resources目录下新建lib目录,把DmJdbcDriver18.jar包拷贝进去 : DmJdbcDriver18.jar

分别在naming模块和console模块的pom.xml下新增依赖项:

<dependency>
<groupId>com.dameng</groupId>
<artifactId>DmJdbcDriver18</artifactId>
<version>8.1.3.140</version>
</dependency>

2 配置Nacos达梦数据库驱动

添加application文件有关达梦数据库配置

db.num=1  
spring.sql.init.platform=dm
db.url.0=jdbc:dm://localhost:5236?schema=NACOS&compatibleMode=mysql&ignoreCase=true&ENCODING=utf-8
db.user.0=SYSDBA
db.password.0=SYSDBA001
db.pool.config.driverClassName=dm.jdbc.driver.DmDriver

3 修改nacos源码

把下载的nacos-plugin-develop中的nacos-datasource-plugin-ext模块下的nacos-datasource-plugin-ext-base中的源码依次拷贝进入nacos-2.3.2中的datasource模块下。同时把下载的nacos-plugin-develop中的nacos-datasource-plugin-ext模块下的nacos-dm-datasource-plugin-ext中的源码依次拷贝进入nacos-2.3.2中的datasource模块下,注意路径。 修改nacos-2.3.2\plugin\datasource\src\main\resources\META-INF\services\com.alibaba.nacos.plugin.datasource.mapper.Mapper的这个文件,在最下面新增如下:

com.alibaba.nacos.plugin.datasource.impl.dm.ConfigInfoAggrMapperByDaMeng
com.alibaba.nacos.plugin.datasource.impl.dm.ConfigInfoBetaMapperByDaMeng
com.alibaba.nacos.plugin.datasource.impl.dm.ConfigInfoMapperByDaMeng
com.alibaba.nacos.plugin.datasource.impl.dm.ConfigInfoTagMapperByDaMeng
com.alibaba.nacos.plugin.datasource.impl.dm.ConfigTagsRelationMapperByDaMeng
com.alibaba.nacos.plugin.datasource.impl.dm.HistoryConfigInfoMapperByDaMeng
com.alibaba.nacos.plugin.datasource.impl.dm.TenantInfoMapperByDaMeng
com.alibaba.nacos.plugin.datasource.impl.dm.TenantCapacityMapperByDaMeng
com.alibaba.nacos.plugin.datasource.impl.dm.GroupCapacityMapperByDaMeng

4 编译打包

在Nacos本地目录编译:

mvn -Prelease-nacos -Dmaven.test.skip=true -Dpmd.skip=true -Drat.skip=true -Dcheckstyle.skip=true clean install -U
danger

有一个坑在windows的powershell中-Dmaven.test.skip带点的命令行会读取错误,需要用单引号圈出来,'-Dmaven.test.skip'

5 运行测试

在输出文件夹中的bin目录下运行cmd,输入startup.cmd -m standalone,即可成功连接