Nacos适配达梦数据库8

遇到问题可在评论区给我留言
从2.2.0版本开始,nacos可通过SPI机制注入多数据源实现插件,并在引入对应数据源实现后,便可在Nacos启动时通过读取application.properties配置文件中spring.datasource.platform配置项选择加载对应多数据源插件。
下面我来演示通过多数据源插件实现nacos适配达梦数据库

一、准备工作

首先要下载nacos源码,nacos-plugin源码,还要准备好达梦数据库环境。
这里我采用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
将下载的2个压缩包解压缩并用idea打开:
image.png

在达梦数据库中新建一个名叫NACOS的数据库,然后在NACOS数据库下创建如下表:(注意最后有个commit提交事务)

CREATE TABLE "NACOS"."USERS"
(
    "USERNAME" VARCHAR(50)  NOT NULL,
    "PASSWORD" VARCHAR(500) NOT NULL,
    "ENABLED"  TINYINT      NOT NULL
);
CREATE TABLE "NACOS"."TENANT_INFO"
(
    "ID"            BIGINT IDENTITY(1,1) NOT NULL,
    "KP"            VARCHAR(128) NOT NULL,
    "TENANT_ID"     VARCHAR(128) DEFAULT ''
        NULL,
    "TENANT_NAME"   VARCHAR(128) DEFAULT ''
        NULL,
    "TENANT_DESC"   VARCHAR(256) NULL,
    "CREATE_SOURCE" VARCHAR(32) NULL,
    "GMT_CREATE"    BIGINT       NOT NULL,
    "GMT_MODIFIED"  BIGINT       NOT NULL
);
CREATE TABLE "NACOS"."TENANT_CAPACITY"
(
    "ID"                BIGINT IDENTITY(1,1) NOT NULL,
    "TENANT_ID"         VARCHAR(128) DEFAULT ''
        NOT NULL,
    "QUOTA"             BIGINT       DEFAULT 0
        NOT NULL,
    "USAGE"             BIGINT       DEFAULT 0
        NOT NULL,
    "MAX_SIZE"          BIGINT       DEFAULT 0
        NOT NULL,
    "MAX_AGGR_COUNT"    BIGINT       DEFAULT 0
        NOT NULL,
    "MAX_AGGR_SIZE"     BIGINT       DEFAULT 0
        NOT NULL,
    "MAX_HISTORY_COUNT" BIGINT       DEFAULT 0
        NOT NULL,
    "GMT_CREATE"        TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
        NOT NULL,
    "GMT_MODIFIED"      TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
        NOT NULL
);
CREATE TABLE "NACOS"."ROLES"
(
    "USERNAME" VARCHAR(50) NOT NULL,
    "ROLE"     VARCHAR(50) NOT NULL
);
CREATE TABLE "NACOS"."PERMISSIONS"
(
    "ROLE"     VARCHAR(50)  NOT NULL,
    "RESOURCE" VARCHAR(255) NOT NULL,
    "ACTION"   VARCHAR(8)   NOT NULL
);
CREATE TABLE "NACOS"."HIS_CONFIG_INFO"
(
    "ID"                 DECIMAL(20, 0) NOT NULL,
    "NID"                BIGINT IDENTITY(1,1) NOT NULL,
    "DATA_ID"            VARCHAR(255)   NOT NULL,
    "GROUP_ID"           VARCHAR(128)   NOT NULL,
    "APP_NAME"           VARCHAR(128) NULL,
    "CONTENT"            CLOB           NOT NULL,
    "MD5"                VARCHAR(32) NULL,
    "GMT_CREATE"         TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
                                        NOT NULL,
    "GMT_MODIFIED"       TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
                                        NOT NULL,
    "SRC_USER"           TEXT NULL,
    "SRC_IP"             VARCHAR(50) NULL,
    "OP_TYPE"            CHAR(10) NULL,
    "TENANT_ID"          VARCHAR(128) DEFAULT ''
        NULL,
    "ENCRYPTED_DATA_KEY" TEXT           NOT NULL
);
CREATE TABLE "NACOS"."GROUP_CAPACITY"
(
    "ID"                BIGINT IDENTITY(1,1) NOT NULL,
    "GROUP_ID"          VARCHAR(128) DEFAULT ''
        NOT NULL,
    "QUOTA"             BIGINT       DEFAULT 0
        NOT NULL,
    "USAGE"             BIGINT       DEFAULT 0
        NOT NULL,
    "MAX_SIZE"          BIGINT       DEFAULT 0
        NOT NULL,
    "MAX_AGGR_COUNT"    BIGINT       DEFAULT 0
        NOT NULL,
    "MAX_AGGR_SIZE"     BIGINT       DEFAULT 0
        NOT NULL,
    "MAX_HISTORY_COUNT" BIGINT       DEFAULT 0
        NOT NULL,
    "GMT_CREATE"        TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
        NOT NULL,
    "GMT_MODIFIED"      TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
        NOT NULL
);
CREATE TABLE "NACOS"."CONFIG_TAGS_RELATION"
(
    "ID"        BIGINT       NOT NULL,
    "TAG_NAME"  VARCHAR(128) NOT NULL,
    "TAG_TYPE"  VARCHAR(64) NULL,
    "DATA_ID"   VARCHAR(255) NOT NULL,
    "GROUP_ID"  VARCHAR(128) NOT NULL,
    "TENANT_ID" VARCHAR(128) DEFAULT ''
        NULL,
    "NID"       BIGINT IDENTITY(1,1) NOT NULL
);
CREATE TABLE "NACOS"."CONFIG_INFO_TAG"
(
    "ID"           BIGINT IDENTITY(1,1) NOT NULL,
    "DATA_ID"      VARCHAR(255) NOT NULL,
    "GROUP_ID"     VARCHAR(128) NOT NULL,
    "TENANT_ID"    VARCHAR(128) DEFAULT ''
        NULL,
    "TAG_ID"       VARCHAR(128) NOT NULL,
    "APP_NAME"     VARCHAR(128) NULL,
    "CONTENT"      CLOB         NOT NULL,
    "MD5"          VARCHAR(32) NULL,
    "GMT_CREATE"   TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
                                NOT NULL,
    "GMT_MODIFIED" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
                                NOT NULL,
    "SRC_USER"     TEXT NULL,
    "SRC_IP"       VARCHAR(50) NULL
);
CREATE TABLE "NACOS"."CONFIG_INFO_BETA"
(
    "ID"                 BIGINT IDENTITY(1,1) NOT NULL,
    "DATA_ID"            VARCHAR(255) NOT NULL,
    "GROUP_ID"           VARCHAR(128) NOT NULL,
    "APP_NAME"           VARCHAR(128) NULL,
    "CONTENT"            CLOB         NOT NULL,
    "BETA_IPS"           VARCHAR(1024) NULL,
    "MD5"                VARCHAR(32) NULL,
    "GMT_CREATE"         TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
                                      NOT NULL,
    "GMT_MODIFIED"       TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
                                      NOT NULL,
    "SRC_USER"           TEXT NULL,
    "SRC_IP"             VARCHAR(50) NULL,
    "TENANT_ID"          VARCHAR(128) DEFAULT ''
        NULL,
    "ENCRYPTED_DATA_KEY" TEXT         NOT NULL
);
CREATE TABLE "NACOS"."CONFIG_INFO_AGGR"
(
    "ID"           BIGINT IDENTITY(1,1) NOT NULL,
    "DATA_ID"      VARCHAR(255) NOT NULL,
    "GROUP_ID"     VARCHAR(128) NOT NULL,
    "DATUM_ID"     VARCHAR(255) NOT NULL,
    "CONTENT"      CLOB         NOT NULL,
    "GMT_MODIFIED" TIMESTAMP(0) NOT NULL,
    "APP_NAME"     VARCHAR(128) NULL,
    "TENANT_ID"    VARCHAR(128) DEFAULT ''
        NULL
);
CREATE TABLE "NACOS"."CONFIG_INFO"
(
    "ID"                 BIGINT IDENTITY(1,1) NOT NULL,
    "DATA_ID"            VARCHAR(255) NOT NULL,
    "GROUP_ID"           VARCHAR(128) NULL,
    "CONTENT"            CLOB         NOT NULL,
    "MD5"                VARCHAR(32) NULL,
    "GMT_CREATE"         TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
                                      NOT NULL,
    "GMT_MODIFIED"       TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
                                      NOT NULL,
    "SRC_USER"           TEXT NULL,
    "SRC_IP"             VARCHAR(50) NULL,
    "APP_NAME"           VARCHAR(128) NULL,
    "TENANT_ID"          VARCHAR(128) DEFAULT ''
        NULL,
    "C_DESC"             VARCHAR(256) NULL,
    "C_USE"              VARCHAR(64) NULL,
    "EFFECT"             VARCHAR(64) NULL,
    "TYPE"               VARCHAR(64) NULL,
    "C_SCHEMA"           TEXT NULL,
    "ENCRYPTED_DATA_KEY" TEXT         NOT NULL
);
ALTER TABLE "NACOS"."USERS"
    ADD CONSTRAINT PRIMARY KEY ("USERNAME");

ALTER TABLE "NACOS"."TENANT_INFO"
    ADD CONSTRAINT PRIMARY KEY ("ID");

ALTER TABLE "NACOS"."TENANT_INFO"
    ADD CONSTRAINT "UK_TENANT_INFO_KPTENANTID" UNIQUE ("KP", "TENANT_ID");

ALTER TABLE "NACOS"."TENANT_CAPACITY"
    ADD CONSTRAINT PRIMARY KEY ("ID");

ALTER TABLE "NACOS"."TENANT_CAPACITY"
    ADD CONSTRAINT "UK_TENANT_ID" UNIQUE ("TENANT_ID");

ALTER TABLE "NACOS"."ROLES"
    ADD CONSTRAINT "IDX_USER_ROLE" UNIQUE ("USERNAME", "ROLE");

ALTER TABLE "NACOS"."PERMISSIONS"
    ADD CONSTRAINT "UK_ROLE_PERMISSION" UNIQUE ("ROLE", "RESOURCE", "ACTION");

ALTER TABLE "NACOS"."HIS_CONFIG_INFO"
    ADD CONSTRAINT PRIMARY KEY ("NID");

ALTER TABLE "NACOS"."GROUP_CAPACITY"
    ADD CONSTRAINT PRIMARY KEY ("ID");

ALTER TABLE "NACOS"."GROUP_CAPACITY"
    ADD CONSTRAINT "UK_GROUP_ID" UNIQUE ("GROUP_ID");

ALTER TABLE "NACOS"."CONFIG_TAGS_RELATION"
    ADD CONSTRAINT PRIMARY KEY ("NID");

ALTER TABLE "NACOS"."CONFIG_TAGS_RELATION"
    ADD CONSTRAINT "UK_CONFIGTAGRELATION_CONFIGIDTAG" UNIQUE ("ID", "TAG_NAME", "TAG_TYPE");

ALTER TABLE "NACOS"."CONFIG_INFO_TAG"
    ADD CONSTRAINT PRIMARY KEY ("ID");

ALTER TABLE "NACOS"."CONFIG_INFO_TAG"
    ADD CONSTRAINT "UK_CONFIGINFOTAG_DATAGROUPTENANTTAG" UNIQUE ("DATA_ID", "GROUP_ID", "TENANT_ID", "TAG_ID");

ALTER TABLE "NACOS"."CONFIG_INFO_BETA"
    ADD CONSTRAINT PRIMARY KEY ("ID");

ALTER TABLE "NACOS"."CONFIG_INFO_BETA"
    ADD CONSTRAINT "UK_CONFIGINFOBETA_DATAGROUPTENANT" UNIQUE ("DATA_ID", "GROUP_ID", "TENANT_ID");

ALTER TABLE "NACOS"."CONFIG_INFO_AGGR"
    ADD CONSTRAINT PRIMARY KEY ("ID");

ALTER TABLE "NACOS"."CONFIG_INFO_AGGR"
    ADD CONSTRAINT "UK_CONFIGINFOAGGR_DATAGROUPTENANTDATUM" UNIQUE ("DATA_ID", "GROUP_ID", "TENANT_ID", "DATUM_ID");

ALTER TABLE "NACOS"."CONFIG_INFO"
    ADD CONSTRAINT PRIMARY KEY ("ID");

ALTER TABLE "NACOS"."CONFIG_INFO"
    ADD CONSTRAINT "UK_CONFIGINFO_DATAGROUPTENANT" UNIQUE ("DATA_ID", "GROUP_ID", "TENANT_ID");

CREATE INDEX "IDX_TENANT_ID"
    ON "NACOS"."TENANT_INFO" ("TENANT_ID");

COMMENT
ON TABLE "NACOS"."TENANT_INFO" IS 'tenant_info';

COMMENT
ON COLUMN "NACOS"."TENANT_INFO"."ID" IS 'id';

COMMENT
ON COLUMN "NACOS"."TENANT_INFO"."KP" IS 'kp';

COMMENT
ON COLUMN "NACOS"."TENANT_INFO"."TENANT_ID" IS 'tenant_id';

COMMENT
ON COLUMN "NACOS"."TENANT_INFO"."TENANT_NAME" IS 'tenant_name';

COMMENT
ON COLUMN "NACOS"."TENANT_INFO"."TENANT_DESC" IS 'tenant_desc';

COMMENT
ON COLUMN "NACOS"."TENANT_INFO"."CREATE_SOURCE" IS 'create_source';

COMMENT
ON COLUMN "NACOS"."TENANT_INFO"."GMT_CREATE" IS '创建时间';

COMMENT
ON COLUMN "NACOS"."TENANT_INFO"."GMT_MODIFIED" IS '修改时间';

ALTER TABLE "NACOS"."TENANT_CAPACITY"
    ADD CHECK ("QUOTA" >= 0) ENABLE;

ALTER TABLE "NACOS"."TENANT_CAPACITY"
    ADD CHECK ("MAX_HISTORY_COUNT" >= 0) ENABLE;

ALTER TABLE "NACOS"."TENANT_CAPACITY"
    ADD CHECK ("MAX_AGGR_SIZE" >= 0) ENABLE;

ALTER TABLE "NACOS"."TENANT_CAPACITY"
    ADD CHECK ("MAX_AGGR_COUNT" >= 0) ENABLE;

ALTER TABLE "NACOS"."TENANT_CAPACITY"
    ADD CHECK ("MAX_SIZE" >= 0) ENABLE;

ALTER TABLE "NACOS"."TENANT_CAPACITY"
    ADD CHECK ("USAGE" >= 0) ENABLE;

COMMENT
ON TABLE "NACOS"."TENANT_CAPACITY" IS '租户容量信息表';

COMMENT
ON COLUMN "NACOS"."TENANT_CAPACITY"."ID" IS '主键ID';

COMMENT
ON COLUMN "NACOS"."TENANT_CAPACITY"."TENANT_ID" IS 'Tenant ID';

COMMENT
ON COLUMN "NACOS"."TENANT_CAPACITY"."QUOTA" IS '配额,0表示使用默认值';

COMMENT
ON COLUMN "NACOS"."TENANT_CAPACITY"."USAGE" IS '使用量';

COMMENT
ON COLUMN "NACOS"."TENANT_CAPACITY"."MAX_SIZE" IS '单个配置大小上限,单位为字节,0表示使用默认值';

COMMENT
ON COLUMN "NACOS"."TENANT_CAPACITY"."MAX_AGGR_COUNT" IS '聚合子配置最大个数';

COMMENT
ON COLUMN "NACOS"."TENANT_CAPACITY"."MAX_AGGR_SIZE" IS '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值';

COMMENT
ON COLUMN "NACOS"."TENANT_CAPACITY"."MAX_HISTORY_COUNT" IS '最大变更历史数量';

COMMENT
ON COLUMN "NACOS"."TENANT_CAPACITY"."GMT_CREATE" IS '创建时间';

COMMENT
ON COLUMN "NACOS"."TENANT_CAPACITY"."GMT_MODIFIED" IS '修改时间';

ALTER TABLE "NACOS"."HIS_CONFIG_INFO"
    ADD CHECK ("ID" >= 0) ENABLE;

CREATE INDEX "IDX_GMT_MODIFIED"
    ON "NACOS"."HIS_CONFIG_INFO" ("GMT_MODIFIED");

CREATE INDEX "IDX_GMT_CREATE"
    ON "NACOS"."HIS_CONFIG_INFO" ("GMT_CREATE");

CREATE INDEX "IDX_DID"
    ON "NACOS"."HIS_CONFIG_INFO" ("DATA_ID");

COMMENT
ON TABLE "NACOS"."HIS_CONFIG_INFO" IS '多租户改造';

COMMENT
ON COLUMN "NACOS"."HIS_CONFIG_INFO"."APP_NAME" IS 'app_name';

COMMENT
ON COLUMN "NACOS"."HIS_CONFIG_INFO"."TENANT_ID" IS '租户字段';

COMMENT
ON COLUMN "NACOS"."HIS_CONFIG_INFO"."ENCRYPTED_DATA_KEY" IS '密钥';

ALTER TABLE "NACOS"."GROUP_CAPACITY"
    ADD CHECK ("QUOTA" >= 0) ENABLE;

ALTER TABLE "NACOS"."GROUP_CAPACITY"
    ADD CHECK ("MAX_HISTORY_COUNT" >= 0) ENABLE;

ALTER TABLE "NACOS"."GROUP_CAPACITY"
    ADD CHECK ("MAX_AGGR_SIZE" >= 0) ENABLE;

ALTER TABLE "NACOS"."GROUP_CAPACITY"
    ADD CHECK ("MAX_AGGR_COUNT" >= 0) ENABLE;

ALTER TABLE "NACOS"."GROUP_CAPACITY"
    ADD CHECK ("MAX_SIZE" >= 0) ENABLE;

ALTER TABLE "NACOS"."GROUP_CAPACITY"
    ADD CHECK ("USAGE" >= 0) ENABLE;

COMMENT
ON TABLE "NACOS"."GROUP_CAPACITY" IS '集群、各Group容量信息表';

COMMENT
ON COLUMN "NACOS"."GROUP_CAPACITY"."ID" IS '主键ID';

COMMENT
ON COLUMN "NACOS"."GROUP_CAPACITY"."GROUP_ID" IS 'Group ID,空字符表示整个集群';

COMMENT
ON COLUMN "NACOS"."GROUP_CAPACITY"."QUOTA" IS '配额,0表示使用默认值';

COMMENT
ON COLUMN "NACOS"."GROUP_CAPACITY"."USAGE" IS '使用量';

COMMENT
ON COLUMN "NACOS"."GROUP_CAPACITY"."MAX_SIZE" IS '单个配置大小上限,单位为字节,0表示使用默认值';

COMMENT
ON COLUMN "NACOS"."GROUP_CAPACITY"."MAX_AGGR_COUNT" IS '聚合子配置最大个数,,0表示使用默认值';

COMMENT
ON COLUMN "NACOS"."GROUP_CAPACITY"."MAX_AGGR_SIZE" IS '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值';

COMMENT
ON COLUMN "NACOS"."GROUP_CAPACITY"."MAX_HISTORY_COUNT" IS '最大变更历史数量';

COMMENT
ON COLUMN "NACOS"."GROUP_CAPACITY"."GMT_CREATE" IS '创建时间';

COMMENT
ON COLUMN "NACOS"."GROUP_CAPACITY"."GMT_MODIFIED" IS '修改时间';

COMMENT
ON TABLE "NACOS"."CONFIG_TAGS_RELATION" IS 'config_tag_relation';

COMMENT
ON COLUMN "NACOS"."CONFIG_TAGS_RELATION"."ID" IS 'id';

COMMENT
ON COLUMN "NACOS"."CONFIG_TAGS_RELATION"."TAG_NAME" IS 'tag_name';

COMMENT
ON COLUMN "NACOS"."CONFIG_TAGS_RELATION"."TAG_TYPE" IS 'tag_type';

COMMENT
ON COLUMN "NACOS"."CONFIG_TAGS_RELATION"."DATA_ID" IS 'data_id';

COMMENT
ON COLUMN "NACOS"."CONFIG_TAGS_RELATION"."GROUP_ID" IS 'group_id';

COMMENT
ON COLUMN "NACOS"."CONFIG_TAGS_RELATION"."TENANT_ID" IS 'tenant_id';

COMMENT
ON TABLE "NACOS"."CONFIG_INFO_TAG" IS 'config_info_tag';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO_TAG"."ID" IS 'id';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO_TAG"."DATA_ID" IS 'data_id';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO_TAG"."GROUP_ID" IS 'group_id';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO_TAG"."TENANT_ID" IS 'tenant_id';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO_TAG"."TAG_ID" IS 'tag_id';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO_TAG"."APP_NAME" IS 'app_name';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO_TAG"."CONTENT" IS 'content';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO_TAG"."MD5" IS 'md5';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO_TAG"."GMT_CREATE" IS '创建时间';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO_TAG"."GMT_MODIFIED" IS '修改时间';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO_TAG"."SRC_USER" IS 'source user';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO_TAG"."SRC_IP" IS 'source ip';

COMMENT
ON TABLE "NACOS"."CONFIG_INFO_BETA" IS 'config_info_beta';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO_BETA"."ID" IS 'id';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO_BETA"."DATA_ID" IS 'data_id';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO_BETA"."GROUP_ID" IS 'group_id';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO_BETA"."APP_NAME" IS 'app_name';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO_BETA"."CONTENT" IS 'content';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO_BETA"."BETA_IPS" IS 'betaIps';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO_BETA"."MD5" IS 'md5';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO_BETA"."GMT_CREATE" IS '创建时间';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO_BETA"."GMT_MODIFIED" IS '修改时间';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO_BETA"."SRC_USER" IS 'source user';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO_BETA"."SRC_IP" IS 'source ip';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO_BETA"."TENANT_ID" IS '租户字段';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO_BETA"."ENCRYPTED_DATA_KEY" IS '密钥';

COMMENT
ON TABLE "NACOS"."CONFIG_INFO_AGGR" IS '增加租户字段';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO_AGGR"."ID" IS 'id';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO_AGGR"."DATA_ID" IS 'data_id';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO_AGGR"."GROUP_ID" IS 'group_id';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO_AGGR"."DATUM_ID" IS 'datum_id';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO_AGGR"."CONTENT" IS '内容';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO_AGGR"."GMT_MODIFIED" IS '修改时间';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO_AGGR"."TENANT_ID" IS '租户字段';

COMMENT
ON TABLE "NACOS"."CONFIG_INFO" IS 'config_info';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO"."ID" IS 'id';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO"."DATA_ID" IS 'data_id';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO"."CONTENT" IS 'content';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO"."MD5" IS 'md5';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO"."GMT_CREATE" IS '创建时间';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO"."GMT_MODIFIED" IS '修改时间';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO"."SRC_USER" IS 'source user';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO"."SRC_IP" IS 'source ip';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO"."TENANT_ID" IS '租户字段';

COMMENT
ON COLUMN "NACOS"."CONFIG_INFO"."ENCRYPTED_DATA_KEY" IS '密钥';



INSERT INTO "NACOS"."USERS"("USERNAME", "PASSWORD", "ENABLED")
VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', 1);

INSERT INTO "NACOS"."ROLES"("USERNAME", "ROLE")
VALUES ('nacos', 'ROLE_ADMIN');

commit; 

image.png

二、实现步骤

2.1 nacos源码中引入达梦8数据库的驱动包

建议使用达梦数据库自带的驱动,达梦数据库安装目录下drivers/jdbc下的驱动,否则可能会出现驱动版本不兼容的问题 (读取超长CLOB,TEXT)
在naming模块和console模块的resources目录下新建lib目录,把DmJdbcDriver18.jar包拷贝进去,自行找一个合适的驱动jar包。
分别在naming模块和console模块的pom.xml下新增依赖项:

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

image.png

2.2 修改nacos源码

(1).把下载的nacos-plugin-develop中的nacos-datasource-plugin-ext模块下的nacos-datasource-plugin-ext-base中的源码依次拷贝进入nacos-2.3.2中的datasource模块下,注意路径。如图所示:
image.png
(2).把下载的nacos-plugin-develop中的nacos-datasource-plugin-ext模块下的nacos-dm-datasource-plugin-ext中的源码依次拷贝进入nacos-2.3.2中的datasource模块下,注意路径。
注意不要拷贝src/main/resources/META-INF/services/com.alibaba.nacos.plugin.datasource.mapper.Mapper这个文件,防止覆盖,等下我们要自己新增一些内容。
image.png
(3).修改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

image.png

2.3 编译打包

在终端打开nacos-2.3.2,运行如下命令:

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

image.png
如果构建成功,则在distribution模块下有生成的nacos包:
image.png

三、运行验证

把nacos-server-2.3.2.zip取出解压缩,修改conf目录下的application.properties配置文件:

### Default web context path:
server.servlet.contextPath=/nacos
### Include message field
server.error.include-message=ALWAYS
### Default web server port:
server.port=8848

### Count of DB:
db.num=1

### Connect URL of DB:
spring.sql.init.platform=dm
db.url.0=jdbc:dm://10.10.10.104:5236?schema=NACOS
db.user.0=SYSDBA
db.password.0=SYSDBA001
db.pool.config.driverClassName=dm.jdbc.driver.DmDriver

### Connection pool configuration: hikariCP
db.pool.config.connectionTimeout=30000
db.pool.config.validationTimeout=10000
db.pool.config.maximumPoolSize=20
db.pool.config.minimumIdle=2

### the maximum retry times for push
nacos.config.push.maxRetryTime=50

#***********Metrics for tomcat **************************#
server.tomcat.mbeanregistry.enabled=true

#***********Expose prometheus and health **************************#
#management.endpoints.web.exposure.include=prometheus,health

### Metrics for elastic search
management.metrics.export.elastic.enabled=false
#management.metrics.export.elastic.host=http://localhost:9200

### Metrics for influx
management.metrics.export.influx.enabled=false

#*************** Access Log Related Configurations ***************#
### If turn on the access log:
server.tomcat.accesslog.enabled=true

### file name pattern, one file per hour
server.tomcat.accesslog.rotate=true
server.tomcat.accesslog.file-date-format=.yyyy-MM-dd-HH
### The access log pattern:
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i %{Request-Source}i

### The directory of access log:
server.tomcat.basedir=file:.

#*************** Access Control Related Configurations ***************#
### If enable spring security, this option is deprecated in 1.2.0:
#spring.security.enabled=false

### The ignore urls of auth
nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-ui/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**

### The auth system to use, currently only 'nacos' and 'ldap' is supported:
nacos.core.auth.system.type=nacos

### If turn on auth system:
nacos.core.auth.enabled=true

### Turn on/off caching of auth information. By turning on this switch, the update of auth information would have a 15 seconds delay.
nacos.core.auth.caching.enabled=true

### Since 1.4.1, Turn on/off white auth for user-agent: nacos-server, only for upgrade from old version.
nacos.core.auth.enable.userAgentAuthWhite=false

### Since 1.4.1, worked when nacos.core.auth.enabled=true and nacos.core.auth.enable.userAgentAuthWhite=false.
### The two properties is the white list for auth and used by identity the request from other server.
nacos.core.auth.server.identity.key=nacos
nacos.core.auth.server.identity.value=nacos

### worked when nacos.core.auth.system.type=nacos
### The token expiration in seconds:
nacos.core.auth.plugin.nacos.token.cache.enable=false
nacos.core.auth.plugin.nacos.token.expire.seconds=18000
### The default token (Base64 String):
nacos.core.auth.plugin.nacos.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789

nacos.istio.mcp.server.enabled=false

具体的配置规则参考官网:https://nacos.io/docs/latest/concepts/
在bin目录下运行cmd,输入startup.cmd -m standalone
image.png
访问localhost:8848/nacos
image.png
新增一些配置文件,在达梦数据库的NACOS.CONFIG——INFO表中看到如下:
cde742cc4d11289dc8a05d3507fcc3d1.png
也可以创建一个简单的spring cloud的demo来实验注册中心和配置中心:
5d757ccb560d5772d2c1c3f37a7f768a.png
673bff880e08592bdf002969839b2990.png
如上图,springcloud-demo已经成功注册到nacos,并且能读出nacos中的配置文件的值,说明此达梦数据库版nacos可用。
至此nacos适配达梦数据库成功!

四、福利(直接看这里可以拿到已经做好的成品)

我这里已经把弄好的源码发布在了github上,需要的话可以下载直接运行mvn编译就好了
https://github.com/pkyit/nacos-2.3.2
点击这里下载源码和nacos达梦版压缩包
如果不想编译也可以直接用我已经构建好的nacos,解压缩就可以使用了。
点击这里免费下载达梦版nacos-2.3.2.tar.gz
https://github.com/pkyit/nacos-2.3.2/releases/download/v2.3.2/nacos-server-2.3.2.tar.gz
docker版的也有哦,请看这里(arm64和amd64) 点这里看docker的nacos-dm8
docker pull pkyit/nacos:2.3.2-dm8
参考:https://github.com/nacos-group/nacos-plugin
参考:https://github.com/alibaba/nacos
参考:https://nacos.io/
参考:https://blog.csdn.net/zhuyangyong/article/details/136215650
参考:https://blog.csdn.net/weixin_45726578/article/details/129835862
如果我的文章对您有帮助,还请您多多支持我。支付宝帮忙扫一下吧
在这里插入图片描述

要将Docker与Nacos适配达梦数据库,我们可以采取以下步骤: 1. 在Docker中下载并安装Nacos镜像。可以使用Docker Hub上的官方Nacos镜像,该镜像提供了可用于适配不同数据库的配置选项。 2. 配置Nacos连接达梦数据库。编辑Nacos的配置文件nacos/conf/application.properties,在该文件中找到数据库相关配置项,如`spring.datasource.url`、`spring.datasource.username`、`spring.datasource.password`等,将其按照达梦数据库连接信息进行相应修改。 3. 构建并启动Nacos容器。使用Docker命令行工具,执行类似以下命令来构建并启动Nacos容器: ``` docker run -d -p 8848:8848 --name nacos-server \ -e MODE=standalone \ -e MYSQL_SERVICE_HOST=<数据库主机地址> \ -e MYSQL_SERVICE_PORT=<数据库端口> \ -e MYSQL_SERVICE_DB_NAME=<数据库名称> \ -e MYSQL_SERVICE_USER=<数据库用户名> \ -e MYSQL_SERVICE_PASSWORD=<数据库密码> \ --restart=always \ nacos/nacos-server:latest ``` 替换<数据库主机地址>、<数据库端口>、<数据库名称>、<数据库用户名>、<数据库密码>为实际达梦数据库的信息。 4. 确认Nacos容器已成功启动。使用Docker命令行工具执行以下命令来查看容器状态: ``` docker ps ``` 如果容器状态为Up,则表示Nacos容器已成功运行。 5. 启动达梦数据库。确保达梦数据库已成功启动,并且Nacos容器可以连接达梦数据库。可以使用数据库客户端验证连接信息是否正确。 6. 访问Nacos管理界面。在浏览器中输入Nacos容器所在主机的IP地址和端口号(默认为8848),访问Nacos的管理界面。在界面中可以配置和管理Nacos的服务、配置等。 通过以上步骤,我们可以在Docker中适配Nacos达梦数据库实现服务注册和配置管理。这样,我们就可以使用Docker来构建和管理基于Nacos达梦数据库的应用程序。
评论 39
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

pengkai火火火

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值