nacos版本2.2.0
人大金仓版本8.6.0
一、相关文件
Nacos官方文档-数据源插件https://nacos.io/zh-cn/docs/v2/plugin/datasource-plugin.html
Nacos2.2.0源码https://github.com/alibaba/nacos/archive/refs/tags/2.2.0.zip
人大金仓驱动https://download.csdn.net/download/qq_36802726/88165221
二、Nacos源码修改
1.配置人大金仓依赖
下载源码与驱动。
源码打开后,如果项目依赖下载太慢可以换成阿里的:可以打开maven的setting.xml文件,把内容换成以下内容:
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
</settings>
引入人大金仓驱动,先用maven 安装kingbase8.8.6.0.jar:
//打开命令行,使用以下命令安装本地jar
mvn install:install-file -Dfile=D:\library\kingbase8.8.6.0.jar -DgroupId=com.kingbase -DartifactId=kingbase8 -Dversion=8.6.0 -Dpackaging=jar
引入依赖,打开项目父pom文件 nacos-all
<!--人大金仓 -->
<dependency>
<groupId>com.kingbase</groupId>
<artifactId>kingbase8</artifactId>
<version>8.6.0</version>
</dependency>
2、源码修改
2.1.找到DataSourceConstant.java,增加kingbase数据常量
public class DataSourceConstant {
public static final String MYSQL = "mysql";
public static final String DERBY = "derby";
public static final String KINGBASE = "kingbase";
}
2.2、新建人大金仓数据源插件
2.2.1、ConfigInfoAggrMapperByKingbase
/*
* Copyright 1999-2022 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.
*/
package com.alibaba.nacos.plugin.datasource.impl.kingbase;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.impl.base.BaseConfigInfoAggrMapper;
/**
* The derby implementation of ConfigInfoAggrMapper.
*
* @author zc
**/
public class ConfigInfoAggrMapperByKingbase extends BaseConfigInfoAggrMapper {
@Override
public String getDataSource() {
return DataSourceConstant.KINGBASE;
}
}
2.2.2、ConfigInfoBetaMapperByKingbase.java
2.2.3、ConfigInfoMapperByKingbase.java
2.2.4、ConfigInfoTagMapperByKingbase.java
2.2.5、ConfigInfoTagsRelationMapperByKingbase.java
2.2.6、GroupCapacityMapperByKingbase.java
2.2.7、HistoryConfigInfoMapperByKingbase.java
2.2.8、TenantCapacityMapperByKingbase.java
2.2.9、TenantInfoMapperByKingbase.java
2.3、plugin/datasource/src/main/resources/META-INF/services 下增加以下数据
#
# Copyright 1999-2022 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.
#
com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoAggrMapperByMySql
com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoBetaMapperByMySql
com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoMapperByMySql
com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoTagMapperByMySql
com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigTagsRelationMapperByMySql
com.alibaba.nacos.plugin.datasource.impl.mysql.HistoryConfigInfoMapperByMySql
com.alibaba.nacos.plugin.datasource.impl.mysql.TenantInfoMapperByMySql
com.alibaba.nacos.plugin.datasource.impl.mysql.TenantCapacityMapperByMySql
com.alibaba.nacos.plugin.datasource.impl.mysql.GroupCapacityMapperByMysql
com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoAggrMapperByDerby
com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoBetaMapperByDerby
com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoMapperByDerby
com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoTagMapperByDerby
com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoTagsRelationMapperByDerby
com.alibaba.nacos.plugin.datasource.impl.derby.HistoryConfigInfoMapperByDerby
com.alibaba.nacos.plugin.datasource.impl.derby.TenantInfoMapperByDerby
com.alibaba.nacos.plugin.datasource.impl.derby.TenantCapacityMapperByDerby
com.alibaba.nacos.plugin.datasource.impl.derby.GroupCapacityMapperByDerby
com.alibaba.nacos.plugin.datasource.impl.kingbase.ConfigInfoAggrMapperByKingbase
com.alibaba.nacos.plugin.datasource.impl.kingbase.ConfigInfoBetaMapperByKingbase
com.alibaba.nacos.plugin.datasource.impl.kingbase.ConfigInfoMapperByKingbase
com.alibaba.nacos.plugin.datasource.impl.kingbase.ConfigInfoTagMapperByKingbase
com.alibaba.nacos.plugin.datasource.impl.kingbase.ConfigInfoTagsRelationMapperByKingbase
com.alibaba.nacos.plugin.datasource.impl.kingbase.GroupCapacityMapperByKingbase
com.alibaba.nacos.plugin.datasource.impl.kingbase.HistoryConfigInfoMapperByKingbase
com.alibaba.nacos.plugin.datasource.impl.kingbase.TenantCapacityMapperByKingbase
com.alibaba.nacos.plugin.datasource.impl.kingbase.TenantInfoMapperByKingbase
2.4、修改配置文件连接数据库
### kingbase:
spring.sql.init.platform=kingbase
db.num=1
db.url.0=jdbc:kingbase8://192.168.0.1:54321/nacos?currentSchema=nacos&allowEncodingChanges=true&clientEncoding=UTF8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
db.user.0=nacos
db.password.0=nacos
db.pool.config.driverClassName=com.kingbase8.Driver
需要注意url的第一个nacos代表数据库名,参数currentSchema后面是数据库的模式名。
2.5、手动增加数据源
不然后面启动项目会报错
Invocation of init method failed; nested exception is ErrCode:500, ErrMsg:Nacos Server did not start because dumpservice bean construction failure :
No DataSource set
在ExternalDataSourceServiceImpl
找到方法public void init() 追加
if(Objects.isNull(jt.getDataSource())){
jt.setDataSource(dataSourceList.get(0));
}
完整方法
@Override
public void init() {
queryTimeout = ConvertUtils.toInt(System.getProperty("QUERYTIMEOUT"), 3);
jt = new JdbcTemplate();
// Set the maximum number of records to prevent memory expansion
jt.setMaxRows(50000);
jt.setQueryTimeout(queryTimeout);
testMasterJT = new JdbcTemplate();
testMasterJT.setQueryTimeout(queryTimeout);
testMasterWritableJT = new JdbcTemplate();
// Prevent the login interface from being too long because the main library is not available
testMasterWritableJT.setQueryTimeout(1);
// Database health check
testJtList = new ArrayList<>();
isHealthList = new ArrayList<>();
tm = new DataSourceTransactionManager();
tjt = new TransactionTemplate(tm);
// Transaction timeout needs to be distinguished from ordinary operations.
tjt.setTimeout(TRANSACTION_QUERY_TIMEOUT);
dataSourceType = DatasourcePlatformUtil.getDatasourcePlatform(defaultDataSourceType);
if (PropertyUtil.isUseExternalDB()) {
try {
reload();
} catch (IOException e) {
FATAL_LOG.error("[ExternalDataSourceService] datasource reload error", e);
throw new RuntimeException(DB_LOAD_ERROR_MSG, e);
}
if (this.dataSourceList.size() > DB_MASTER_SELECT_THRESHOLD) {
ConfigExecutor.scheduleConfigTask(new SelectMasterTask(), 10, 10, TimeUnit.SECONDS);
}
ConfigExecutor.scheduleConfigTask(new CheckDbHealthTask(), 10, 10, TimeUnit.SECONDS);
}
if(Objects.isNull(jt.getDataSource())){
jt.setDataSource(dataSourceList.get(0));
}
}
2.6、配置调试
maven执行 mvn install
如果控制台显示
java: 程序包com.alibaba.nacos.consistency.entity不存在java: 程序包com.alibaba.nacos.consistency.entity不存在
可以执行
然后刷新一下maven在执行 mvn install
成功后进行运行配置
-Dnacos.standalone=true 代表单例运行
这说明项目启动成功
3、人大金仓数据库
CREATE SCHEMA nacos AUTHORIZATION nacos;
CREATE TABLE config_info (
id bigint NOT NULL,
data_id varchar(255) NOT NULL,
group_id varchar(128) NOT NULL,
tenant_id varchar(128) default '',
app_name varchar(128),
content text,
md5 varchar(32) DEFAULT NULL,
gmt_create timestamp NOT NULL DEFAULT '2010-05-05 00:00:00',
gmt_modified timestamp NOT NULL DEFAULT '2010-05-05 00:00:00',
src_user varchar(128) DEFAULT NULL,
src_ip varchar(20) DEFAULT NULL,
c_desc varchar(256) DEFAULT NULL,
c_use varchar(64) DEFAULT NULL,
effect varchar(64) DEFAULT NULL,
type varchar(64) DEFAULT NULL,
c_schema text DEFAULT NULL,
ENCRYPTED_DATA_KEY varchar(100) DEFAULT NULL,
constraint configinfo_id_key PRIMARY KEY (id),
constraint uk_configinfo_datagrouptenant UNIQUE (data_id,group_id,tenant_id));
CREATE INDEX configinfo_dataid_key_idx ON config_info(data_id);
CREATE INDEX configinfo_groupid_key_idx ON config_info(group_id);
CREATE INDEX configinfo_dataid_group_key_idx ON config_info(data_id, group_id);
CREATE SEQUENCE config_info_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
alter table config_info alter column id set default nextval('config_info_id_seq');
CREATE TABLE his_config_info (
id bigint NOT NULL,
nid bigint NOT NULL,
data_id varchar(255) NOT NULL,
group_id varchar(128) NOT NULL,
tenant_id varchar(128) default '',
app_name varchar(128),
content text,
md5 varchar(32) DEFAULT NULL,
gmt_create timestamp NOT NULL DEFAULT '2010-05-05 00:00:00.000',
gmt_modified timestamp NOT NULL DEFAULT '2010-05-05 00:00:00.000',
src_user varchar(128),
src_ip varchar(20) DEFAULT NULL,
op_type char(10) DEFAULT NULL,
ENCRYPTED_DATA_KEY varchar(100) DEFAULT NULL,
constraint hisconfiginfo_nid_key PRIMARY KEY (nid));
CREATE INDEX hisconfiginfo_dataid_key_idx ON his_config_info(data_id);
CREATE INDEX hisconfiginfo_gmt_create_idx ON his_config_info(gmt_create);
CREATE INDEX hisconfiginfo_gmt_modified_idx ON his_config_info(gmt_modified);
CREATE SEQUENCE his_config_info_nid_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
alter table his_config_info alter column nid set default nextval('his_config_info_nid_seq');
CREATE TABLE config_info_beta (
id bigint NOT NULL ,
data_id varchar(255) NOT NULL,
group_id varchar(128) NOT NULL,
tenant_id varchar(128) default '',
app_name varchar(128),
content text,
beta_ips varchar(1024),
md5 varchar(32) DEFAULT NULL,
gmt_create timestamp NOT NULL DEFAULT '2010-05-05 00:00:00',
gmt_modified timestamp NOT NULL DEFAULT '2010-05-05 00:00:00',
src_user varchar(128),
src_ip varchar(20) DEFAULT NULL,
constraint configinfobeta_id_key PRIMARY KEY (id),
constraint uk_configinfobeta_datagrouptenant UNIQUE (data_id,group_id,tenant_id));
CREATE SEQUENCE config_info_beta_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
alter table config_info_beta alter column id set default nextval('config_info_beta_id_seq');
CREATE TABLE config_info_tag (
id bigint NOT NULL ,
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 text,
md5 varchar(32) DEFAULT NULL,
gmt_create timestamp NOT NULL DEFAULT '2010-05-05 00:00:00',
gmt_modified timestamp NOT NULL DEFAULT '2010-05-05 00:00:00',
src_user varchar(128),
src_ip varchar(20) DEFAULT NULL,
constraint configinfotag_id_key PRIMARY KEY (id),
constraint uk_configinfotag_datagrouptenanttag UNIQUE (data_id,group_id,tenant_id,tag_id));
CREATE SEQUENCE config_info_tag_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
alter table config_info_tag alter column id set default nextval('config_info_tag_id_seq');
CREATE TABLE config_info_aggr (
id bigint NOT NULL ,
data_id varchar(255) NOT NULL,
group_id varchar(128) NOT NULL,
tenant_id varchar(128) default '',
datum_id varchar(255) NOT NULL,
app_name varchar(128),
content text,
gmt_modified timestamp NOT NULL DEFAULT '2010-05-05 00:00:00',
constraint configinfoaggr_id_key PRIMARY KEY (id),
constraint uk_configinfoaggr_datagrouptenantdatum UNIQUE (data_id,group_id,tenant_id,datum_id));
CREATE SEQUENCE config_info_aggr_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
alter table config_info_aggr alter column id set default nextval('config_info_aggr_id_seq');
CREATE TABLE app_list (
id bigint NOT NULL ,
app_name varchar(128) NOT NULL,
is_dynamic_collect_disabled smallint DEFAULT 0,
last_sub_info_collected_time timestamp DEFAULT '1970-01-01 08:00:00.0',
sub_info_lock_owner varchar(128),
sub_info_lock_time timestamp DEFAULT '1970-01-01 08:00:00.0',
constraint applist_id_key PRIMARY KEY (id),
constraint uk_appname UNIQUE (app_name));
CREATE SEQUENCE app_list_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
alter table app_list alter column id set default nextval('app_list_id_seq');
CREATE TABLE app_configdata_relation_subs (
id bigint NOT NULL ,
app_name varchar(128) NOT NULL,
data_id varchar(255) NOT NULL,
group_id varchar(128) NOT NULL,
gmt_modified timestamp DEFAULT '2010-05-05 00:00:00',
constraint configdatarelationsubs_id_key PRIMARY KEY (id),
constraint uk_app_sub_config_datagroup UNIQUE (app_name, data_id, group_id));
CREATE SEQUENCE app_configdata_relation_subs_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
alter table app_configdata_relation_subs alter column id set default nextval('app_configdata_relation_subs_id_seq');
CREATE TABLE app_configdata_relation_pubs (
id bigint NOT NULL ,
app_name varchar(128) NOT NULL,
data_id varchar(255) NOT NULL,
group_id varchar(128) NOT NULL,
gmt_modified timestamp DEFAULT '2010-05-05 00:00:00',
constraint configdatarelationpubs_id_key PRIMARY KEY (id),
constraint uk_app_pub_config_datagroup UNIQUE (app_name, data_id, group_id));
CREATE SEQUENCE app_configdata_relation_pubs_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
alter table app_configdata_relation_pubs alter column id set default nextval('app_configdata_relation_pubs_id_seq');
CREATE TABLE config_tags_relation (
id bigint NOT NULL,
tag_name varchar(128) NOT NULL,
tag_type varchar(64) DEFAULT NULL,
data_id varchar(255) NOT NULL,
group_id varchar(128) NOT NULL,
tenant_id varchar(128) DEFAULT '',
nid bigint NOT NULL,
constraint config_tags_id_key PRIMARY KEY (nid),
constraint uk_configtagrelation_configidtag UNIQUE (id, tag_name, tag_type));
CREATE INDEX config_tags_tenant_id_idx ON config_tags_relation(tenant_id);
CREATE SEQUENCE config_tags_relation_pubs_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
alter table config_tags_relation alter column id set default nextval('config_tags_relation_pubs_id_seq');
CREATE TABLE group_capacity (
id bigint NOT NULL ,
group_id varchar(128) DEFAULT '',
quota int DEFAULT 0,
usage int DEFAULT 0,
max_size int DEFAULT 0,
max_aggr_count int DEFAULT 0,
max_aggr_size int DEFAULT 0,
max_history_count int DEFAULT 0,
gmt_create timestamp DEFAULT '2010-05-05 00:00:00',
gmt_modified timestamp DEFAULT '2010-05-05 00:00:00',
constraint group_capacity_id_key PRIMARY KEY (id),
constraint uk_group_id UNIQUE (group_id));
CREATE SEQUENCE group_capacity_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
alter table group_capacity alter column id set default nextval('group_capacity_id_seq');
CREATE TABLE tenant_capacity (
id bigint NOT NULL ,
tenant_id varchar(128) DEFAULT '',
quota int DEFAULT 0,
usage int DEFAULT 0,
max_size int DEFAULT 0,
max_aggr_count int DEFAULT 0,
max_aggr_size int DEFAULT 0,
max_history_count int DEFAULT 0,
gmt_create timestamp DEFAULT '2010-05-05 00:00:00',
gmt_modified timestamp DEFAULT '2010-05-05 00:00:00',
constraint tenant_capacity_id_key PRIMARY KEY (id),
constraint uk_tenant_id UNIQUE (tenant_id));
CREATE SEQUENCE tenant_capacity_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
alter table tenant_capacity alter column id set default nextval('tenant_capacity_id_seq');
CREATE TABLE tenant_info (
id bigint NOT NULL ,
kp varchar(128) NOT NULL,
tenant_id varchar(128) DEFAULT '',
tenant_name varchar(128) DEFAULT '',
tenant_desc varchar(256) DEFAULT NULL,
create_source varchar(32) DEFAULT NULL,
gmt_create bigint NOT NULL,
gmt_modified bigint NOT NULL,
constraint tenant_info_id_key PRIMARY KEY (id),
constraint uk_tenant_info_kptenantid UNIQUE (kp,tenant_id));
CREATE INDEX tenant_info_tenant_id_idx ON tenant_info(tenant_id);
CREATE SEQUENCE tenant_info_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
alter table tenant_info alter column id set default nextval('tenant_info_id_seq');
CREATE TABLE users (
username varchar(50) NOT NULL PRIMARY KEY,
password varchar(500) NOT NULL,
enabled boolean NOT NULL
);
CREATE TABLE roles (
username varchar(50) NOT NULL,
role varchar(50) NOT NULL
);
INSERT INTO users (username, password, enabled) VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', true);
INSERT INTO roles (username, role) VALUES ('nacos', 'ROLE_ADMIN');
三、 构建打包
mvn -Prelease-nacos -Dmaven.test.skip=true -Dpmd.skip=true -Dcheckstyle.skip=true clean install
或者
mvn -Prelease-nacos clean package install -Dmaven.test.skip=true
成功后在distribution的target下生成两个包
nacos-server-2.2.0.tar.gz 是linux环境的
nacos-server-2.2.0.zip 是windows环境的