在这里插入图片描述

软件 版本
nacos 3.1.1
jdk 17
maven 3.6.3

一、克隆源码

1.1. git 克隆源码

git clone https://github.com/alibaba/nacos.git

切换tag到3.1.1

git checkout tags/3.1.1

1.2. 直接点击下载

直接下载也可以
https://github.com/alibaba/nacos/archive/refs/tags/3.1.1.zip

二、修改源码集成PostgreSQL

2.1. 创建postgresql目录

<dependency>
    <groupId>com.sinhy</groupId>
    <artifactId>nacos-postgresql-datasource-plugin-ext</artifactId>
    <version>3.1.1</version>
</dependency>

在这里插入图片描述

三、编译源码

在idea中 执行mvn命令

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

在这里插入图片描述
编译成功的程序
在这里插入图片描述

四、启动本地nacos

修改配置
进入nacos\distribution\target\nacos-server-3.1.1\nacos\conf,修改application.properties,核心配置如下:

nacos.core.auth.server.identity.key=identityNacos
nacos.core.auth.server.identity.value=RTY4+Y4KokLKk9fZigOa3cwzRUzU2Nzs75m9oHHuiQE=
nacos.core.auth.plugin.nacos.token.secret.key=hzMOOvOp6gBXFCgK03caEETxQNF220HuiHALQApnDnQgM2JXgOB1iJrjM70wLTxNYlKxIaeCnKinVW/3KUJ+zA==
#*************** Datasource Related Configurations ***************#
### nacos.plugin.datasource.log.enabled=true

spring.sql.init.platform=postgresql
## Count of DB:
# 数据库连接数量配置
db.num=1
db.url.0=jdbc:postgresql://192.168.0.109:5432/mydatabase?tcpKeepAlive=true&reWriteBatchedInserts=true
db.user.0=myuser
db.password.0=mysecretpassword
# 连接池配置 (使用HikariCP)
db.pool.config.connectionTimeout=30000
db.pool.config.validationTimeout=10000
db.pool.config.maximumPoolSize=20
db.pool.config.minimumIdle=2
db.pool.config.driverClassName=org.postgresql.Driver

数据库脚本

--
-- 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 GENERATED BY DEFAULT AS IDENTITY (START WITH 1 INCREMENT BY 1) PRIMARY KEY,
   data_id varchar(255) NOT NULL,
   group_id varchar(128),
   content text NOT NULL,
   md5 varchar(32),
   gmt_create timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
   gmt_modified timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
   src_user text,
   src_ip varchar(50),
   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,
   encrypted_data_key varchar(1024) NOT NULL DEFAULT ''
);
COMMENT ON TABLE config_info IS 'config_info';
COMMENT ON COLUMN config_info.id IS 'id';
COMMENT ON COLUMN config_info.data_id IS 'data_id';
COMMENT ON COLUMN config_info.group_id IS 'group_id';
COMMENT ON COLUMN config_info.content IS 'content';
COMMENT ON COLUMN config_info.md5 IS 'md5';
COMMENT ON COLUMN config_info.gmt_create IS '创建时间';
COMMENT ON COLUMN config_info.gmt_modified IS '修改时间';
COMMENT ON COLUMN config_info.src_user IS 'source user';
COMMENT ON COLUMN config_info.src_ip IS 'source ip';
COMMENT ON COLUMN config_info.app_name IS 'app_name';
COMMENT ON COLUMN config_info.tenant_id IS '租户字段';
COMMENT ON COLUMN config_info.c_desc IS 'configuration description';
COMMENT ON COLUMN config_info.c_use IS 'configuration usage';
COMMENT ON COLUMN config_info.effect IS '配置生效的描述';
COMMENT ON COLUMN config_info.type IS '配置的类型';
COMMENT ON COLUMN config_info.c_schema IS '配置的模式';
COMMENT ON COLUMN config_info.encrypted_data_key IS '密钥';
CREATE UNIQUE INDEX uk_configinfo_datagrouptenant ON config_info (data_id, group_id, tenant_id);


CREATE TABLE config_info_gray (
    id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1 INCREMENT BY 1) PRIMARY KEY,
    data_id varchar(255) NOT NULL,
    group_id varchar(128) NOT NULL,
    content text NOT NULL,
    md5 varchar(32),
    src_user text,
    src_ip varchar(100),
    gmt_create timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    gmt_modified timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    app_name varchar(128),
    tenant_id varchar(128) DEFAULT '',
    gray_name varchar(128) NOT NULL,
    gray_rule text NOT NULL,
    encrypted_data_key varchar(256) NOT NULL DEFAULT ''
);
COMMENT ON TABLE config_info_gray IS 'config_info_gray';
COMMENT ON COLUMN config_info_gray.id IS 'id';
COMMENT ON COLUMN config_info_gray.data_id IS 'data_id';
COMMENT ON COLUMN config_info_gray.group_id IS 'group_id';
COMMENT ON COLUMN config_info_gray.content IS 'content';
COMMENT ON COLUMN config_info_gray.md5 IS 'md5';
COMMENT ON COLUMN config_info_gray.src_user IS 'src_user';
COMMENT ON COLUMN config_info_gray.src_ip IS 'src_ip';
COMMENT ON COLUMN config_info_gray.gmt_create IS 'gmt_create';
COMMENT ON COLUMN config_info_gray.gmt_modified IS 'gmt_modified';
COMMENT ON COLUMN config_info_gray.app_name IS 'app_name';
COMMENT ON COLUMN config_info_gray.tenant_id IS 'tenant_id';
COMMENT ON COLUMN config_info_gray.gray_name IS 'gray_name';
COMMENT ON COLUMN config_info_gray.gray_rule IS 'gray_rule';
COMMENT ON COLUMN config_info_gray.encrypted_data_key IS 'encrypted_data_key';
CREATE UNIQUE INDEX uk_configinfogray_datagrouptenantgray ON config_info_gray (data_id, group_id, tenant_id, gray_name);
CREATE INDEX idx_dataid_gmt_modified ON config_info_gray (data_id, gmt_modified);
CREATE INDEX idx_gmt_modified ON config_info_gray (gmt_modified);


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 GENERATED BY DEFAULT AS IDENTITY (START WITH 1 INCREMENT BY 1) PRIMARY KEY
);
COMMENT ON TABLE config_tags_relation IS 'config_tag_relation';
COMMENT ON COLUMN config_tags_relation.id IS 'id';
COMMENT ON COLUMN config_tags_relation.tag_name IS 'tag_name';
COMMENT ON COLUMN config_tags_relation.tag_type IS 'tag_type';
COMMENT ON COLUMN config_tags_relation.data_id IS 'data_id';
COMMENT ON COLUMN config_tags_relation.group_id IS 'group_id';
COMMENT ON COLUMN config_tags_relation.tenant_id IS 'tenant_id';
COMMENT ON COLUMN config_tags_relation.nid IS 'nid, 自增长标识';
CREATE UNIQUE INDEX uk_configtagrelation_configidtag ON config_tags_relation (id, tag_name, tag_type);
CREATE INDEX idx_tenant_id ON config_tags_relation (tenant_id);


CREATE TABLE group_capacity (
    id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1 INCREMENT BY 1) PRIMARY KEY,
    group_id varchar(128) NOT NULL DEFAULT '',
    quota integer NOT NULL DEFAULT 0,
    usage integer NOT NULL DEFAULT 0,
    max_size integer NOT NULL DEFAULT 0,
    max_aggr_count integer NOT NULL DEFAULT 0,
    max_aggr_size integer NOT NULL DEFAULT 0,
    max_history_count integer NOT NULL DEFAULT 0,
    gmt_create timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    gmt_modified timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
);
COMMENT ON TABLE group_capacity IS '集群、各Group容量信息表';
COMMENT ON COLUMN group_capacity.id IS '主键ID';
COMMENT ON COLUMN group_capacity.group_id IS 'Group ID,空字符表示整个集群';
COMMENT ON COLUMN group_capacity.quota IS '配额,0表示使用默认值';
COMMENT ON COLUMN group_capacity.usage IS '使用量';
COMMENT ON COLUMN group_capacity.max_size IS '单个配置大小上限,单位为字节,0表示使用默认值';
COMMENT ON COLUMN group_capacity.max_aggr_count IS '聚合子配置最大个数,,0表示使用默认值';
COMMENT ON COLUMN group_capacity.max_aggr_size IS '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值';
COMMENT ON COLUMN group_capacity.max_history_count IS '最大变更历史数量';
COMMENT ON COLUMN group_capacity.gmt_create IS '创建时间';
COMMENT ON COLUMN group_capacity.gmt_modified IS '修改时间';
CREATE UNIQUE INDEX uk_group_id ON group_capacity (group_id);


CREATE TABLE his_config_info (
    id bigint NOT NULL,
    nid bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1 INCREMENT BY 1) PRIMARY KEY,
    data_id varchar(255) NOT NULL,
    group_id varchar(128) NOT NULL,
    app_name varchar(128),
    content text NOT NULL,
    md5 varchar(32),
    gmt_create timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    gmt_modified timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    src_user text,
    src_ip varchar(50),
    op_type char(10),
    tenant_id varchar(128) DEFAULT '',
    encrypted_data_key varchar(1024) NOT NULL DEFAULT '',
    publish_type varchar(50) DEFAULT 'formal',
    gray_name varchar(50),
    ext_info text
);
COMMENT ON TABLE his_config_info IS '多租户改造';
COMMENT ON COLUMN his_config_info.id IS 'id';
COMMENT ON COLUMN his_config_info.nid IS 'nid, 自增标识';
COMMENT ON COLUMN his_config_info.data_id IS 'data_id';
COMMENT ON COLUMN his_config_info.group_id IS 'group_id';
COMMENT ON COLUMN his_config_info.app_name IS 'app_name';
COMMENT ON COLUMN his_config_info.content IS 'content';
COMMENT ON COLUMN his_config_info.md5 IS 'md5';
COMMENT ON COLUMN his_config_info.gmt_create IS '创建时间';
COMMENT ON COLUMN his_config_info.gmt_modified IS '修改时间';
COMMENT ON COLUMN his_config_info.src_user IS 'source user';
COMMENT ON COLUMN his_config_info.src_ip IS 'source ip';
COMMENT ON COLUMN his_config_info.op_type IS 'operation type';
COMMENT ON COLUMN his_config_info.tenant_id IS '租户字段';
COMMENT ON COLUMN his_config_info.encrypted_data_key IS '密钥';
COMMENT ON COLUMN his_config_info.publish_type IS 'publish type gray or formal';
COMMENT ON COLUMN his_config_info.gray_name IS 'gray name';
COMMENT ON COLUMN his_config_info.ext_info IS 'ext info';
CREATE INDEX idx_gmt_create ON his_config_info (gmt_create);
CREATE INDEX idx_did ON his_config_info (data_id);


CREATE TABLE tenant_capacity (
    id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1 INCREMENT BY 1) PRIMARY KEY,
    tenant_id varchar(128) NOT NULL DEFAULT '',
    quota integer NOT NULL DEFAULT 0,
    usage integer NOT NULL DEFAULT 0,
    max_size integer NOT NULL DEFAULT 0,
    max_aggr_count integer NOT NULL DEFAULT 0,
    max_aggr_size integer NOT NULL DEFAULT 0,
    max_history_count integer NOT NULL DEFAULT 0,
    gmt_create timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    gmt_modified timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
);
COMMENT ON TABLE tenant_capacity IS '租户容量信息表';
COMMENT ON COLUMN tenant_capacity.id IS '主键ID';
COMMENT ON COLUMN tenant_capacity.tenant_id IS 'Tenant ID';
COMMENT ON COLUMN tenant_capacity.quota IS '配额,0表示使用默认值';
COMMENT ON COLUMN tenant_capacity.usage IS '使用量';
COMMENT ON COLUMN tenant_capacity.max_size IS '单个配置大小上限,单位为字节,0表示使用默认值';
COMMENT ON COLUMN tenant_capacity.max_aggr_count IS '聚合子配置最大个数';
COMMENT ON COLUMN tenant_capacity.max_aggr_size IS '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值';
COMMENT ON COLUMN tenant_capacity.max_history_count IS '最大变更历史数量';
COMMENT ON COLUMN tenant_capacity.gmt_create IS '创建时间';
COMMENT ON COLUMN tenant_capacity.gmt_modified IS '修改时间';
CREATE UNIQUE INDEX uk_tenant_id ON tenant_capacity (tenant_id);

CREATE TABLE tenant_info (
    id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1 INCREMENT BY 1) PRIMARY KEY,
    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
);
COMMENT ON TABLE tenant_info IS 'tenant_info';
COMMENT ON COLUMN tenant_info.id IS 'id';
COMMENT ON COLUMN tenant_info.kp IS 'kp';
COMMENT ON COLUMN tenant_info.tenant_id IS 'tenant_id';
COMMENT ON COLUMN tenant_info.tenant_name IS 'tenant_name';
COMMENT ON COLUMN tenant_info.tenant_desc IS 'tenant_desc';
COMMENT ON COLUMN tenant_info.create_source IS 'create_source';
COMMENT ON COLUMN tenant_info.gmt_create IS '创建时间';
COMMENT ON COLUMN tenant_info.gmt_modified IS '修改时间';
CREATE UNIQUE INDEX uk_tenant_info_kptenantid ON tenant_info (kp, tenant_id);

CREATE TABLE users (
    username varchar(50) NOT NULL PRIMARY KEY,
    password varchar(500) NOT NULL,
    enabled boolean NOT NULL
);
COMMENT ON TABLE users IS 'users';
COMMENT ON COLUMN users.username IS 'username';
COMMENT ON COLUMN users.password IS 'password';
COMMENT ON COLUMN users.enabled IS 'enabled';

CREATE TABLE roles (
    username varchar(50) NOT NULL,
    role varchar(50) NOT NULL
);
COMMENT ON TABLE roles IS 'roles';
COMMENT ON COLUMN roles.username IS 'username';
COMMENT ON COLUMN roles.role IS 'role';
CREATE UNIQUE INDEX idx_user_role ON roles (username, role);

CREATE TABLE permissions (
    role varchar(50) NOT NULL,
    resource varchar(128) NOT NULL,
    action varchar(8) NOT NULL
);
COMMENT ON TABLE permissions IS 'permissions';
COMMENT ON COLUMN permissions.role IS 'role';
COMMENT ON COLUMN permissions.resource IS 'resource';
COMMENT ON COLUMN permissions.action IS 'action';
CREATE UNIQUE INDEX uk_role_permission ON permissions (role, resource, action);

五、启动nacos服务

进入nacos\distribution\target\nacos-server-3.1.1\nacos\bin目录,
执行startup.cmd -m=standalone,如下:
在这里插入图片描述

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐