nacos 改造(支持达梦数据库)

1. 离线下载 jdbc的jar包

     方式一 :

     CSDN下载达梦8 jdbc依赖  :

       离线导入maven库

mvn install:install-file -DgroupId=com.dameng -DartifactId=DmJdbcDriver18 -Dversion=8.1.1.193 -Dpackaging=jar -Dfile=E:/DmJdbcDriver18.jar --settings D:/maven/user-settings/nacos/settings.xml

    方式二:   

    在线直接链接MAVEN库下载 (中央仓库和阿里的仓库都有)

<!-- https://search.maven.org/search?q=com.dameng  -->
<dependency>
    <groupId>com.dameng</groupId>
    <artifactId>DmJdbcDriver18</artifactId>
    <version>8.1.1.193</version>
</dependency>

2. 添加maven依赖 

     修改 nacos-2.0.3\pom.xml

<!-- 达梦8数据库版本号(添加到properties节点中) -->
<dm8-jdbc.version>8.1.2.84</dm8-jdbc.version>

<!-- 达梦8数据库jdbc (参考下图) -->
<dependency>
    <groupId>com.dameng</groupId>
    <artifactId>DmJdbcDriver18</artifactId>
    <version>${dm8-jdbc.version}</version>
</dependency>

 

     修改 nacos-2.0.3\config\pom.xml

<!-- 达梦8数据库jdbc -->
<dependency>
    <groupId>com.dameng</groupId>
    <artifactId>DmJdbcDriver18</artifactId>
</dependency>

3.添加数据库配置

   数据库脚本在最底部哦

    修改 nacos-2.0.3\console\src\main\resources\application.properties , 在注释掉的mysql配置下修改

# platform只是表示是否使用外置数据库 ; 使用什么数据库则由db.jdbcDriverName决定
spring.datasource.platform=mysql

db.num=1
db.jdbcDriverName=dm.jdbc.driver.DmDriver
db.url.0=jdbc:dm://127.0.0.1:5236/DMSERVER?STU&zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8
db.user.0=nacos
db.password.0=***********

 4.修改java代码

     修改 nacos-2.0.3\config\src\main\java\com\alibaba\nacos\config\server\service\datasource\ExternalDataSourceProperties.java

     注 : 下面代码红色部分为修改部分

    private String jdbcDriverName;

    public void setJdbcDriverName(String jdbcDriverName) {
        this.jdbcDriverName = jdbcDriverName;
    }

    public static final String TEST_QUERY = "SELECT 1 FROM dual";


    /**
     * Build serveral HikariDataSource.
     *
     * @param environment {@link Environment}
     * @param callback    Callback function when constructing data source
     * @return List of {@link HikariDataSource}
     */
    List<HikariDataSource> build(Environment environment, Callback<HikariDataSource> callback) {
        List<HikariDataSource> dataSources = new ArrayList<>();
        Binder.get(environment).bind("db", Bindable.ofInstance(this));
        Preconditions.checkArgument(Objects.nonNull(num), "db.num is null");
        Preconditions.checkArgument(CollectionUtils.isNotEmpty(user), "db.user or db.user.[index] is null");
        Preconditions.checkArgument(CollectionUtils.isNotEmpty(password), "db.password or db.password.[index] is null");
        for (int index = 0; index < num; index++) {
            int currentSize = index + 1;
            Preconditions.checkArgument(url.size() >= currentSize, "db.url.%s is null", index);
            DataSourcePoolProperties poolProperties = DataSourcePoolProperties.build(environment);
            if (StringUtils.isEmpty(jdbcDriverName)) {
                poolProperties.setDriverClassName(JDBC_DRIVER_NAME);
            } else {
                poolProperties.setDriverClassName(jdbcDriverName);
            }
            poolProperties.setJdbcUrl(url.get(index).trim());
            poolProperties.setUsername(getOrDefault(user, index, user.get(0)).trim());
            poolProperties.setPassword(getOrDefault(password, index, password.get(0)).trim());
            HikariDataSource ds = poolProperties.getDataSource();
            ds.setConnectionTestQuery(TEST_QUERY);
            ds.setIdleTimeout(TimeUnit.MINUTES.toMillis(10L));
            ds.setConnectionTimeout(TimeUnit.SECONDS.toMillis(3L));
            dataSources.add(ds);
            callback.accept(ds);
        }
        Preconditions.checkArgument(CollectionUtils.isNotEmpty(dataSources), "no datasource available");
        return dataSources;
    }

 5.编译并运行

 

附1: nacos 达梦新建用户脚本(默认表空间)

-- CREATE USER "nacos" IDENTIFIED BY "******" DEFAULT TABLESPACE "TESTUSER_DATA" DEFAULT INDEX TABLESPACE "TESTUSER_IDX";

create user "nacos" identified by "******" ;
grant dba to nacos ;

 

附2: nacos 达梦数据库脚本

/*
 * Copyright 1999-2018 Alibaba Group Holding Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

CREATE TABLE CONFIG_INFO (
    ID BIGINT NOT NULL IDENTITY(1, 1),
    DATA_ID VARCHAR(255) NOT NULL,
    GROUP_ID VARCHAR(255),
    CONTENT CLOB NOT NULL,
    MD5 VARCHAR(32),
    GMT_CREATE TIMESTAMP,
    GMT_MODIFIED TIMESTAMP,
    SRC_USER TEXT,
    SRC_IP VARCHAR(20),
    APP_NAME VARCHAR(128),
    TENANT_ID VARCHAR(128) DEFAULT '',
    C_DESC VARCHAR(256),
    C_USE VARCHAR(64),
    EFFECT VARCHAR(64),
    "TYPE" VARCHAR(64),
    C_SCHEMA TEXT,
    CONSTRAINT CONS134220047 PRIMARY KEY (ID)
);

CREATE UNIQUE INDEX "uk_configinfo_datagrouptenant" ON CONFIG_INFO (DATA_ID,GROUP_ID,TENANT_ID);


CREATE TABLE CONFIG_INFO_AGGR (
    ID BIGINT NOT NULL IDENTITY(1, 1),
    DATA_ID VARCHAR(255) NOT NULL,
    GROUP_ID VARCHAR(255) NOT NULL,
    DATUM_ID VARCHAR(255) NOT NULL,
    CONTENT CLOB NOT NULL,
    GMT_MODIFIED TIMESTAMP NOT NULL,
    APP_NAME VARCHAR(128),
    TENANT_ID VARCHAR(128) DEFAULT '',
    CONSTRAINT CONS134220045 PRIMARY KEY (ID)
);
CREATE UNIQUE INDEX "uk_configinfoaggr_datagrouptenantdatum" ON CONFIG_INFO_AGGR (DATA_ID,GROUP_ID,TENANT_ID,DATUM_ID);
  

CREATE TABLE CONFIG_INFO_BETA (
    ID BIGINT NOT NULL IDENTITY(1, 1),
    DATA_ID VARCHAR(255) NOT NULL,
    GROUP_ID VARCHAR(128) NOT NULL,
    APP_NAME VARCHAR(128),
    CONTENT CLOB NOT NULL,
    BETA_IPS VARCHAR(1024),
    MD5 VARCHAR(32),
    GMT_CREATE TIMESTAMP,
    GMT_MODIFIED TIMESTAMP,
    SRC_USER TEXT,
    SRC_IP VARCHAR(20),
    TENANT_ID VARCHAR(128) DEFAULT '',
    CONSTRAINT CONS134220043 PRIMARY KEY (ID)
);
CREATE UNIQUE INDEX "uk_configinfobeta_datagrouptenant" ON CONFIG_INFO_BETA (DATA_ID,GROUP_ID,TENANT_ID);  
  

CREATE TABLE CONFIG_INFO_TAG (
    ID BIGINT NOT NULL IDENTITY(1, 1),
    DATA_ID VARCHAR(255) NOT NULL,
    GROUP_ID VARCHAR(128) NOT NULL,
    TENANT_ID VARCHAR(128) DEFAULT '',
    TAG_ID VARCHAR(128) NOT NULL,
    APP_NAME VARCHAR(128),
    CONTENT CLOB NOT NULL,
    MD5 VARCHAR(32),
    GMT_CREATE TIMESTAMP,
    GMT_MODIFIED TIMESTAMP,
    SRC_USER TEXT,
    SRC_IP VARCHAR(20),
    CONSTRAINT CONS134220041 PRIMARY KEY (ID)
);
CREATE UNIQUE INDEX "uk_configinfotag_datagrouptenanttag" ON CONFIG_INFO_TAG (DATA_ID,GROUP_ID,TENANT_ID,TAG_ID);
    
   
CREATE TABLE CONFIG_TAGS_RELATION (
    ID BIGINT NOT NULL,
    TAG_NAME VARCHAR(128) NOT NULL,
    TAG_TYPE VARCHAR(64),
    DATA_ID VARCHAR(255) NOT NULL,
    GROUP_ID VARCHAR(128) NOT NULL,
    TENANT_ID VARCHAR(128) DEFAULT '',
    NID BIGINT NOT NULL IDENTITY(1, 1),
    CONSTRAINT CONS134220039 PRIMARY KEY (NID)
);
CREATE INDEX "idx_tenant_id" ON CONFIG_TAGS_RELATION (TENANT_ID);
CREATE UNIQUE INDEX "uk_configtagrelation_configidtag" ON CONFIG_TAGS_RELATION (ID,TAG_NAME,TAG_TYPE);
   
   
CREATE TABLE GROUP_CAPACITY (
    ID BIGINT NOT NULL IDENTITY(1, 1),
    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,
    GMT_MODIFIED TIMESTAMP,
    CONSTRAINT CONS134220037 PRIMARY KEY (ID)
);
CREATE UNIQUE INDEX "uk_group_id" ON GROUP_CAPACITY (GROUP_ID);
   

CREATE TABLE HIS_CONFIG_INFO (
    ID DECIMAL(20,0) NOT NULL,
    NID BIGINT NOT NULL IDENTITY(1, 1),
    DATA_ID VARCHAR(255) NOT NULL,
    GROUP_ID VARCHAR(128) NOT NULL,
    APP_NAME VARCHAR(128),
    CONTENT CLOB NOT NULL,
    MD5 VARCHAR(32),
    GMT_CREATE TIMESTAMP,
    GMT_MODIFIED TIMESTAMP,
    SRC_USER TEXT,
    SRC_IP VARCHAR(20),
    OP_TYPE CHAR(10),
    TENANT_ID VARCHAR(128) DEFAULT '',
    CONSTRAINT CONS134220036 PRIMARY KEY (NID)
);
CREATE INDEX IDX_DID ON HIS_CONFIG_INFO (DATA_ID);
CREATE INDEX IDX_GMT_CREATE ON HIS_CONFIG_INFO (GMT_CREATE);
CREATE INDEX IDX_GMT_MODIFIED ON HIS_CONFIG_INFO (GMT_MODIFIED);  
   
   
CREATE TABLE TENANT_CAPACITY (
    ID BIGINT NOT NULL IDENTITY(1, 1),
    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,
    GMT_MODIFIED TIMESTAMP,
    CONSTRAINT CONS134220034 PRIMARY KEY (ID)
);
CREATE UNIQUE INDEX "uk_tenant_id" ON TENANT_CAPACITY (TENANT_ID);


CREATE TABLE TENANT_INFO (
    ID BIGINT NOT NULL IDENTITY(1, 1),
    KP VARCHAR(128) NOT NULL,
    TENANT_ID VARCHAR(128) DEFAULT '',
    TENANT_NAME VARCHAR(128) DEFAULT '',
    TENANT_DESC VARCHAR(256),
    CREATE_SOURCE VARCHAR(32),
    GMT_CREATE BIGINT NOT NULL,
    GMT_MODIFIED BIGINT NOT NULL,
    CONSTRAINT CONS134220032 PRIMARY KEY (ID)
);
CREATE INDEX "ti_tenant_id" ON TENANT_INFO (TENANT_ID);
CREATE UNIQUE INDEX "uk_tenant_info_kptenantid" ON TENANT_INFO (KP,TENANT_ID);


CREATE TABLE USERS (
    USERNAME VARCHAR(50) NOT NULL,
    PASSWORD VARCHAR(500) NOT NULL,
    ENABLED TINYINT NOT NULL,
    CONSTRAINT CONS134220049 PRIMARY KEY (USERNAME)
);

CREATE TABLE ROLES (
    USERNAME VARCHAR(50) NOT NULL,
    "ROLE" VARCHAR(50) NOT NULL
);

CREATE TABLE permissions (
    role varchar(50) NOT NULL,
    resource varchar(255) NOT NULL,
    action varchar(8) NOT NULL
);
CREATE UNIQUE INDEX "uk_role_permission" ON permissions(role,resource,action);


INSERT INTO users (username, password, enabled) VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', TRUE);

INSERT INTO roles (username, role) VALUES ('nacos', 'ROLE_ADMIN');

 

备注 :

 

posted on 2022-04-19 13:54  hi-gdl  阅读(2051)  评论(0编辑  收藏  举报

导航