背景:因项目需要信创,需将原本的mysql数据库,改成达梦数据库
一、部署达梦数据库
1.1 部署达梦数据库服务
可参考:Docker安装达梦数据库_达梦数据库docker镜像-CSDN博客
1.2 创建nacos数据库
create user SAFE_NACOS identified by "Safehub@2024";
grant "PUBLIC","SOI","VTI" to "SAFE_NACOS";
grant create table to "SAFE_NACOS";
CREATE SCHEMA "SAFE_NACOS" AUTHORIZATION "SAFE_NACOS";
1.3 适配了达梦的nacos脚本
CREATE TABLE "SAFE_NACOS"."CONFIG_INFO"(
"ID" BIGINT NOT NULL AUTO_INCREMENT COMMENT 'ID',
"DATA_ID" VARCHAR(255) NOT NULL COMMENT 'DATA_ID',
"GROUP_ID" VARCHAR(128) DEFAULT NULL COMMENT 'GROUP_ID',
"CONTENT" CLOB NOT NULL COMMENT 'CONTENT',
"MD5" VARCHAR(32) DEFAULT NULL COMMENT 'MD5',
"GMT_CREATE" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
"GMT_MODIFIED" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
"SRC_USER" TEXT COMMENT 'SOURCE USER',
"SRC_IP" VARCHAR(50) DEFAULT NULL COMMENT 'SOURCE IP',
"APP_NAME" VARCHAR(128) DEFAULT NULL COMMENT 'APP_NAME',
"TENANT_ID" VARCHAR(128) DEFAULT '' COMMENT '租户字段',
"C_DESC" VARCHAR(256) DEFAULT NULL COMMENT 'CONFIGURATION DESCRIPTION',
"C_USE" VARCHAR(64) DEFAULT NULL COMMENT 'CONFIGURATION USAGE',
"EFFECT" VARCHAR(64) DEFAULT NULL COMMENT '配置生效的描述',
"TYPE" VARCHAR(64) DEFAULT NULL COMMENT '配置的类型',
"C_SCHEMA" TEXT COMMENT '配置的模式',
"ENCRYPTED_DATA_KEY" VARCHAR(1024) NOT NULL DEFAULT '' COMMENT '密钥',
NOT CLUSTER PRIMARY KEY("ID")
);
COMMENT ON TABLE "SAFE_NACOS"."CONFIG_INFO" IS '配置表' ;
CREATE UNIQUE INDEX "UK_CONFIGINFO_DATAGROUPTENANT" ON "SAFE_NACOS"."CONFIG_INFO"("DATA_ID","GROUP_ID","TENANT_ID");
/******************************************/
/* 表名称 = CONFIG_INFO_AGGR */
/******************************************/
CREATE TABLE "SAFE_NACOS"."CONFIG_INFO_AGGR" (
"ID" BIGINT NOT NULL AUTO_INCREMENT COMMENT 'ID',
"DATA_ID" VARCHAR(255) NOT NULL COMMENT 'DATA_ID',
"GROUP_ID" VARCHAR(128) NOT NULL COMMENT 'GROUP_ID',
"DATUM_ID" VARCHAR(255) NOT NULL COMMENT 'DATUM_ID',
"CONTENT" Clob NOT NULL COMMENT '内容',
"GMT_MODIFIED" DATETIME NOT NULL COMMENT '修改时间',
"APP_NAME" VARCHAR(128) DEFAULT NULL COMMENT 'APP_NAME',
"TENANT_ID" VARCHAR(128) DEFAULT '' COMMENT '租户字段',
NOT CLUSTER PRIMARY KEY ("ID")
);
COMMENT ON TABLE "SAFE_NACOS"."CONFIG_INFO_AGGR" IS '增加租户字段' ;
CREATE UNIQUE INDEX "UK_CONFIGINFOAGGR_DATAGROUPTENANTDATUM" ON "SAFE_NACOS"."CONFIG_INFO_AGGR"("DATA_ID","GROUP_ID","TENANT_ID");
/******************************************/
/* 表名称 = CONFIG_INFO_BETA */
/******************************************/
CREATE TABLE "SAFE_NACOS"."CONFIG_INFO_BETA" (
"ID" BIGINT NOT NULL AUTO_INCREMENT COMMENT 'ID',
"DATA_ID" VARCHAR(255) NOT NULL COMMENT 'DATA_ID',
"GROUP_ID" VARCHAR(128) NOT NULL COMMENT 'GROUP_ID',
"APP_NAME" VARCHAR(128) DEFAULT NULL COMMENT 'APP_NAME',
"CONTENT" Clob NOT NULL COMMENT 'CONTENT',
"BETA_IPS" VARCHAR(1024) DEFAULT NULL COMMENT 'BETAIPS',
"MD5" VARCHAR(32) DEFAULT NULL COMMENT 'MD5',
"GMT_CREATE" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
"GMT_MODIFIED" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
"SRC_USER" TEXT COMMENT 'SOURCE USER',
"SRC_IP" VARCHAR(50) DEFAULT NULL COMMENT 'SOURCE IP',
"TENANT_ID" VARCHAR(128) DEFAULT '' COMMENT '租户字段',
"ENCRYPTED_DATA_KEY" VARCHAR(1024) NOT NULL DEFAULT '' COMMENT '密钥',
NOT CLUSTER PRIMARY KEY ("ID")
);
COMMENT ON TABLE "SAFE_NACOS"."CONFIG_INFO_BETA" IS 'CONFIG_INFO_BETA' ;
CREATE UNIQUE INDEX "UK_CONFIGINFOBETA_DATAGROUPTENANT" ON "SAFE_NACOS"."CONFIG_INFO_BETA"("DATA_ID","GROUP_ID","TENANT_ID");
/******************************************/
/* 表名称 = CONFIG_INFO_TAG*/
/******************************************/
CREATE TABLE "SAFE_NACOS"."CONFIG_INFO_TAG" (
"ID" BIGINT NOT NULL AUTO_INCREMENT COMMENT 'ID',
"DATA_ID" VARCHAR(255) NOT NULL COMMENT 'DATA_ID',
"GROUP_ID" VARCHAR(128) NOT NULL COMMENT 'GROUP_ID',
"TENANT_ID" VARCHAR(128) DEFAULT '' COMMENT 'TENANT_ID',
"TAG_ID" VARCHAR(128) NOT NULL COMMENT 'TAG_ID',
"APP_NAME" VARCHAR(128) DEFAULT NULL COMMENT 'APP_NAME',
"CONTENT" CLOB NOT NULL COMMENT 'CONTENT',
"MD5" VARCHAR(32) DEFAULT NULL COMMENT 'MD5',
"GMT_CREATE" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
"GMT_MODIFIED" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
"SRC_USER" TEXT COMMENT 'SOURCE USER',
"SRC_IP" VARCHAR(50) DEFAULT NULL COMMENT 'SOURCE IP',
NOT CLUSTER PRIMARY KEY ("ID")
);
COMMENT ON TABLE "SAFE_NACOS"."CONFIG_INFO_TAG" IS 'CONFIG_INFO_TAG' ;
CREATE UNIQUE INDEX "UK_CONFIGINFOTAG_DATAGROUPTENANTTAG" ON "SAFE_NACOS"."CONFIG_INFO_TAG"("DATA_ID","GROUP_ID","TENANT_ID","TAG_ID");
/******************************************/
/* 表名称 = CONFIG_TAGS_RELATION */
/******************************************/
CREATE TABLE "SAFE_NACOS"."CONFIG_TAGS_RELATION" (
"ID" BIGINT NOT NULL COMMENT 'ID',
"TAG_NAME" VARCHAR(128) NOT NULL COMMENT 'TAG_NAME',
"TAG_TYPE" VARCHAR(64) DEFAULT NULL COMMENT 'TAG_TYPE',
"DATA_ID" VARCHAR(255) NOT NULL COMMENT 'DATA_ID',
"GROUP_ID" VARCHAR(128) NOT NULL COMMENT 'GROUP_ID',
"TENANT_ID" VARCHAR(128) DEFAULT '' COMMENT 'TENANT_ID',
"NID" BIGINT NOT NULL AUTO_INCREMENT COMMENT 'NID, 自增长标识',
NOT CLUSTER PRIMARY KEY ("NID")
);
COMMENT ON TABLE "SAFE_NACOS"."CONFIG_TAGS_RELATION" IS 'CONFIG_TAG_RELATION' ;
CREATE UNIQUE INDEX "UK_CONFIGTAGRELATION_CONFIGIDTAG" ON "SAFE_NACOS"."CONFIG_TAGS_RELATION"("ID","TAG_NAME","TAG_TYPE");
CREATE INDEX "IDX_TENANT_ID" ON "SAFE_NACOS"."CONFIG_TAGS_RELATION"("TENANT_ID");
/******************************************/
/* 表名称 = GROUP_CAPACITY */
/******************************************/
CREATE TABLE "SAFE_NACOS"."GROUP_CAPACITY" (
"ID" BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
"GROUP_ID" VARCHAR(128) NOT NULL DEFAULT '' COMMENT 'GROUP ID,空字符表示整个集群',
"QUOTA" INT NOT NULL DEFAULT '0' COMMENT '配额,0表示使用默认值',
"USAGE" INT NOT NULL DEFAULT '0' COMMENT '使用量',
"MAX_SIZE" INT NOT NULL DEFAULT '0' COMMENT '单个配置大小上限,单位为字节,0表示使用默认值',
"MAX_AGGR_COUNT" INT NOT NULL DEFAULT '0' COMMENT '聚合子配置最大个数,,0表示使用默认值',
"MAX_AGGR_SIZE" INT NOT NULL DEFAULT '0' COMMENT '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值',
"MAX_HISTORY_COUNT" INT NOT NULL DEFAULT '0' COMMENT '最大变更历史数量',
"GMT_CREATE" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
"GMT_MODIFIED" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
NOT CLUSTER PRIMARY KEY ("ID")
);
COMMENT ON TABLE "SAFE_NACOS"."GROUP_CAPACITY" IS '集群、各GROUP容量信息表' ;
CREATE UNIQUE INDEX "UK_GROUP_ID" ON "SAFE_NACOS"."GROUP_CAPACITY"("GROUP_ID");
/******************************************/
/* 表名称 = HIS_CONFIG_INFO*/
/******************************************/
CREATE TABLE "SAFE_NACOS"."HIS_CONFIG_INFO" (
"ID" BIGINT NOT NULL COMMENT 'ID',
"NID" BIGINT NOT NULL AUTO_INCREMENT COMMENT 'NID, 自增标识',
"DATA_ID" VARCHAR(255) NOT NULL COMMENT 'DATA_ID',
"GROUP_ID" VARCHAR(128) NOT NULL COMMENT 'GROUP_ID',
"APP_NAME" VARCHAR(128) DEFAULT NULL COMMENT 'APP_NAME',
"CONTENT" CLOB NOT NULL COMMENT 'CONTENT',
"MD5" VARCHAR(32) DEFAULT NULL COMMENT 'MD5',
"GMT_CREATE" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
"GMT_MODIFIED" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
"SRC_USER" TEXT COMMENT 'SOURCE USER',
"SRC_IP" VARCHAR(50) DEFAULT NULL COMMENT 'SOURCE IP',
"OP_TYPE" CHAR(10) DEFAULT NULL COMMENT 'OPERATION TYPE',
"TENANT_ID" VARCHAR(128) DEFAULT '' COMMENT '租户字段',
"ENCRYPTED_DATA_KEY" VARCHAR(1024) NOT NULL DEFAULT '' COMMENT '密钥',
PRIMARY KEY ("NID")
);
COMMENT ON TABLE "SAFE_NACOS"."HIS_CONFIG_INFO" IS '多租户改造' ;
CREATE INDEX "IDX_GMT_CREATE" ON "SAFE_NACOS"."HIS_CONFIG_INFO"("GMT_CREATE");
CREATE INDEX "IDX_GMT_MODIFIED" ON "SAFE_NACOS"."HIS_CONFIG_INFO"("GMT_MODIFIED");
CREATE INDEX "IDX_DID" ON "SAFE_NACOS"."HIS_CONFIG_INFO"("DATA_ID");
/******************************************/
/* 表名称 = TENANT_CAPACITY*/
/******************************************/
CREATE TABLE "SAFE_NACOS"."TENANT_CAPACITY" (
"ID" BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
"TENANT_ID" VARCHAR(128) NOT NULL DEFAULT '' COMMENT 'TENANT ID',
"QUOTA" INT NOT NULL DEFAULT '0' COMMENT '配额,0表示使用默认值',
"USAGE" INT NOT NULL DEFAULT '0' COMMENT '使用量',
"MAX_SIZE" INT NOT NULL DEFAULT '0' COMMENT '单个配置大小上限,单位为字节,0表示使用默认值',
"MAX_AGGR_COUNT" INT NOT NULL DEFAULT '0' COMMENT '聚合子配置最大个数',
"MAX_AGGR_SIZE" INT NOT NULL DEFAULT '0' COMMENT '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值',
"MAX_HISTORY_COUNT" INT NOT NULL DEFAULT '0' COMMENT '最大变更历史数量',
"GMT_CREATE" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
"GMT_MODIFIED" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
PRIMARY KEY ("ID")
);
COMMENT ON TABLE "SAFE_NACOS"."TENANT_CAPACITY" IS '租户容量信息表' ;
CREATE UNIQUE INDEX "UK_TENANT_ID" ON "SAFE_NACOS"."TENANT_CAPACITY"("TENANT_ID");
CREATE TABLE "SAFE_NACOS"."TENANT_INFO" (
"ID" BIGINT NOT NULL AUTO_INCREMENT COMMENT 'ID',
"KP" VARCHAR(128) NOT NULL COMMENT 'KP',
"TENANT_ID" VARCHAR(128) DEFAULT '' COMMENT 'TENANT_ID',
"TENANT_NAME" VARCHAR(128) DEFAULT '' COMMENT 'TENANT_NAME',
"TENANT_DESC" VARCHAR(256) DEFAULT NULL COMMENT 'TENANT_DESC',
"CREATE_SOURCE" VARCHAR(32) DEFAULT NULL COMMENT 'CREATE_SOURCE',
"GMT_CREATE" BIGINT NOT NULL COMMENT '创建时间',
"GMT_MODIFIED" BIGINT NOT NULL COMMENT '修改时间',
PRIMARY KEY ("ID")
);
COMMENT ON TABLE "SAFE_NACOS"."TENANT_INFO" IS 'TENANT_INFO' ;
CREATE UNIQUE INDEX "UK_TENANT_INFO_KPTENANTID" ON "SAFE_NACOS"."TENANT_INFO"("KP","TENANT_ID");
CREATE INDEX "IDX_TENANTIN_ID" ON "SAFE_NACOS"."TENANT_INFO"("TENANT_ID");
CREATE TABLE "SAFE_NACOS"."USERS" (
"ID" BIGINT NOT NULL AUTO_INCREMENT COMMENT 'ID',
"USERNAME" VARCHAR(50) NOT NULL COMMENT 'USERNAME',
"PASSWORD" VARCHAR(500) NOT NULL COMMENT 'PASSWORD',
"ENABLED" int NOT NULL COMMENT 'ENABLED',
PRIMARY KEY ("ID")
);
CREATE TABLE "SAFE_NACOS"."ROLES" (
"ID" BIGINT NOT NULL AUTO_INCREMENT COMMENT 'ID',
"USERNAME" VARCHAR(50) NOT NULL COMMENT 'USERNAME',
"ROLE" VARCHAR(50) NOT NULL COMMENT 'ROLE',
PRIMARY KEY ("ID")
);
CREATE UNIQUE INDEX "IDX_USER_ROLE" ON "SAFE_NACOS"."ROLES" ("USERNAME" ASC, "ROLE" ASC);
CREATE TABLE "SAFE_NACOS"."PERMISSIONS" (
"ID" BIGINT NOT NULL AUTO_INCREMENT COMMENT 'ID',
"ROLE" VARCHAR(50) NOT NULL COMMENT 'ROLE',
"RESOURCE" VARCHAR(128) NOT NULL COMMENT 'RESOURCE',
"ACTION" VARCHAR(8) NOT NULL COMMENT 'ACTION',
PRIMARY KEY ("ID")
);
CREATE UNIQUE INDEX "UK_ROLE_PERMISSION" ON "SAFE_NACOS"."PERMISSIONS" ("ROLE","RESOURCE","ACTION");
INSERT INTO "SAFE_NACOS".users (username, password, enabled) VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', TRUE);
INSERT INTO "SAFE_NACOS".roles (username, role) VALUES ('nacos', 'ROLE_ADMIN');
二、nacos适配达梦数据库
这里以nacos-2.1.0为例子
2.1 下载nacos2.1.0源码
可参考:GitHub - alibaba/nacos at 2.1.0
2.2 修改nacos源码以适配达梦数据库
2.2.1 引入达梦驱动依赖
首先在根目录的pom.xml中引入达梦数据库依赖
<dm-connector-java.version>8.1.1.49</dm-connector-java.version>
<dependency>
<groupId>com.dameng</groupId>
<artifactId>Dm8JdbcDriver18</artifactId>
<version>${dm-connector-java.version}</version>
</dependency>
2.2.2 修改nacos-config模块下的ExternalDataSourceProperties
具体代码如下:
/*
* 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.
*/
package com.alibaba.nacos.config.server.service.datasource;
import com.alibaba.nacos.common.utils.Preconditions;
import com.zaxxer.hikari.HikariDataSource;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.core.env.Environment;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import static com.alibaba.nacos.common.utils.CollectionUtils.getOrDefault;
/**
* Properties of external DataSource.
*
* @author Nacos
*/
public class ExternalDataSourceProperties {
private static final String JDBC_DRIVER_NAME = "com.mysql.cj.jdbc.Driver";
private static final String TEST_QUERY = "SELECT 1";
private Integer num;
private String jdbcDriverName;
private List<String> url = new ArrayList<>();
private List<String> user = new ArrayList<>();
private List<String> password = new ArrayList<>();
public void setNum(Integer num) {
this.num = num;
}
public void setUrl(List<String> url) {
this.url = url;
}
public void setUser(List<String> user) {
this.user = user;
}
public void setPassword(List<String> password) {
this.password = password;
}
public String getJdbcDriverName() {
return jdbcDriverName;
}
public void setJdbcDriverName(String jdbcDriverName) {
this.jdbcDriverName = jdbcDriverName;
}
/**
* 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);
poolProperties.setDriverClassName(JDBC_DRIVER_NAME);
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));
System.out.println("#################################");
System.out.println("jdbcDriverName=" + jdbcDriverName);
if (StringUtils.isNotEmpty(jdbcDriverName)) {
// 增加其他数据库驱动的支持
ds.setDriverClassName(jdbcDriverName);
} else {
//默认使用mysql驱动
ds.setDriverClassName(JDBC_DRIVER_NAME);
}
System.out.println("#################################");
System.out.println("dataSources=" + dataSources);
dataSources.add(ds);
callback.accept(ds);
}
Preconditions.checkArgument(CollectionUtils.isNotEmpty(dataSources), "no datasource available");
return dataSources;
}
interface Callback<D> {
/**
* Perform custom logic.
*
* @param datasource dataSource.
*/
void accept(D datasource);
}
}
2.2.3 修改nacos-console模块下的application.properties
### Count of DB:
db.num=1
db.jdbcDriverName=dm.jdbc.driver.DmDriver
db.url.0=jdbc:dm://10.136.xxx.xxx:5237?schema=SAFE_NACOS&characterEncoding=UTF-8&useUnicode=true&serverTimezone=Asia/Shanghai
db.user=SAFE_NACOS
db.password=Safehub@2024
2.3 重新打包nacos
在nacos项目下打开终端输入以下命令
mvn -Prelease-nacos -Dmaven.test.skip=true -Dpmd.skip=true -Dcheckstyle.skip=true clean install -U
运行成功后会在/nacos/distribution/target目录下生成如下文件
至此,新的nacos已改造完成。
三、制作nacos-dm.tar镜像
3.1 编写Dockerfile文件
vi Dockerfile
FROM java:8
MAINTAINER wx
ENV JAVA_HOME=/usr/lib/jvm/jdk1.8.0_181
ENV PATH=$PATH:$JAVA_HOME/bin
ENV LC_ALL=en_US.utf8
ENV LANG=en_US.utf8
ENV LANGUAGE=en_US.utf8
ADD nacos-server.jar app.jar
EXPOSE 8848
ENTRYPOINT ["java", "-Dfile.encoding=utf-8","-jar", "app.jar"]
PS:docker已有基础镜像java:8
3.2 编写构建镜像脚本
vi nacos_built.sh(PS:Dockerfile和jar包在同一目录下)
app_name='nacos-dm'
docker stop ${app_name}
docker rm -f ${app_name}
sleep 2
docker build -t nacos-dm .
3.3 启动nacos-dm容器
3.3.1 创建/home/nacos/mydata/conf/,/home/nacos/mydata/logs目录
并将下面两个文件copy进/home/nacos/mydata/conf/
3.3.2 修改application.properties文件
application.properties完整内容如下:
# spring
server.servlet.contextPath=${SERVER_SERVLET_CONTEXTPATH:/nacos}
server.contextPath=/nacos
server.port=${NACOS_APPLICATION_PORT:8848}
server.tomcat.accesslog.max-days=30
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i %{Request-Source}i
server.tomcat.accesslog.enabled=${TOMCAT_ACCESSLOG_ENABLED:false}
server.error.include-message=ALWAYS
# default current work dir
server.tomcat.basedir=file:.
#*************** Config Module Related Configurations ***************#
### Deprecated configuration property, it is recommended to use `spring.sql.init.platform` replaced.
#spring.datasource.platform=${SPRING_DATASOURCE_PLATFORM:}
spring.sql.init.platform=${SPRING_DATASOURCE_PLATFORM:dm}
nacos.cmdb.dumpTaskInterval=3600
nacos.cmdb.eventTaskInterval=10
nacos.cmdb.labelTaskInterval=300
nacos.cmdb.loadDataAtStart=false
db,jdbcDriverName=${DM_DRIVER:dm.jdbc.driver.DmDriver}
db.num=${MYSQL_DATABASE_NUM:1}
db.url.0=jdbc:dm://${MYSQL_SERVICE_HOST:10.136.xxx.xx}:${MYSQL_SERVICE_PORT:5237}/${MYSQL_SERVICE_DB_NAME:SAFE_NACOS}?${MYSQL_SERVICE_DB_PARAM:characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false}
db.user.0=${MYSQL_SERVICE_USER:SAFE_NACOS}
db.password.0=${MYSQL_SERVICE_PASSWORD:Safehub@2024}
### The auth system to use, currently only 'nacos' and 'ldap' is supported:
nacos.core.auth.system.type=${NACOS_AUTH_SYSTEM_TYPE:nacos}
### worked when nacos.core.auth.system.type=nacos
### The token expiration in seconds:
nacos.core.auth.plugin.nacos.token.expire.seconds=${NACOS_AUTH_TOKEN_EXPIRE_SECONDS:18000}
### The default token:
nacos.core.auth.plugin.nacos.token.secret.key=${NACOS_AUTH_TOKEN:SecretKey01234567890123456789012345345678999987654901234567890123456789}
### 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.enable=true
nacos.core.auth.caching.enabled=${NACOS_AUTH_CACHE_ENABLE:false}
nacos.core.auth.enable.userAgentAuthWhite=${NACOS_AUTH_USER_AGENT_AUTH_WHITE_ENABLE:false}
nacos.core.auth.server.identity.key=${NACOS_AUTH_IDENTITY_KEY:example}
nacos.core.auth.server.identity.value=${NACOS_AUTH_IDENTITY_VALUE:example}
## spring security config
### turn off security
nacos.security.ignore.urls=${NACOS_SECURITY_IGNORE_URLS:/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**}
# metrics for elastic search
management.metrics.export.elastic.enabled=false
management.metrics.export.influx.enabled=false
nacos.naming.distro.taskDispatchThreadCount=10
nacos.naming.distro.taskDispatchPeriod=200
nacos.naming.distro.batchSyncKeyCount=1000
nacos.naming.distro.initDataRatio=0.9
nacos.naming.distro.syncRetryDelay=5000
nacos.naming.data.warmup=true
3.3.3 编写cluster.conf
目前内容为空
3.4 编写启动脚本
vi docker-startup.sh
app_name='nacos-dm'
docker stop ${app_name}
echo '--------stop container-------------'
docker rm ${app_name}
echo '--------rm container---------------'
docker run -p 8848:8848 --name ${app_name} \
-e MODE=standalone \
-e TZ="Asia/Shanghai"\
--restart always\
-v /etc/localtime:/etc/localtime \
-v /home/nacos/mydata/conf/:/root/nacos/conf/ \
-v /home/nacos/mydata/logs/:/root/nacos/logs \
-d ${app_name}
echo '---------start container---------'
3.5 打成tar包
docker save -o nacos-dm.tar nacos-dm
四、遇到的问题
4.1 出现错误:[Too many errors, abort] [error occurred during error reporting , id 0xb]
可能是docker容器问题,添加docker内存配置:
vi /etc/profile
ulimit -n 65535
vi /etc/systemd/system/docker.service
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=65535
LimitNPROC=65535
LimitCORE=65535
然后重启加载配置并启动
systemctl daemon-reload
systemctl restart docker
4.2 container_linux.go:318 permission denied””: unknown
改写启动脚本,增加:--privileged=true
app_name='nacos-dm'
docker stop ${app_name}
echo '--------stop container-------------'docker rm ${app_name}
echo '--------rm container---------------'docker run -p 8848:8848 --name ${app_name} \
-e MODE=standalone \
-m 3g \
--privileged=true \
-e TZ="Asia/Shanghai" \
--restart always \
-v /etc/localtime:/etc/localtime \
-v /home/nacos/mydata/conf/:/root/nacos/conf/ \
-v /home/nacos/mydata/logs/:/root/nacos/logs \
-d ${app_name}echo '---------start container---------'
五、使用现成的nacos-dm.tar, 部署适配过达梦数据库的nacos服务
5.1 上传nacos-dm.tar镜像
5.2 上传docker-startup.sh启动脚本
5.3 在/home/目录下创建nacos/mydata/conf,nacos/mydata/logs目录
cd /home
mkdir -p {nacos/mydata/conf,nacos/mydata/logs}
5.4 在/home/nacos/mydata/conf目录下上传application.properties、cluster.conf文件
最终如下图:
ps:docker-startup.sh,application.properties,cluster.conf内容见上文(三、制作nacos-dm.tar镜像)
5.5 加载镜像
docker load < nacos-dm.tar
5.6 启动nacos容器
sh docker-startup.sh
5.7 查看nacos服务是否启动成功
docker logs --tail=400 -f nacos-dm
5.8 在浏览器输入地址
http://10.136.xx.xxx:8848/nacos/#
ps: nacos默认用户名nacos/nacos