下载Mysql
//下载mysql
docker pull mysql:5.7
//运行容器
docker run -p 3306:3306 --name mysql -v /home/mysql/log:/var/log/mysql -v /home/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD='xx' -d mysql:5.7
将导入数据库
1.新建数据库 nacos
/*
Navicat Premium Data Transfer
Source Server : localhost_3306
Source Server Type : MySQL
Source Server Version : 50735
Source Host : localhost:3306
Source Schema : nacos
Target Server Type : MySQL
Target Server Version : 50735
File Encoding : 65001
Date: 08/12/2022 10:03:24
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for config_info
-- ----------------------------
DROP TABLE IF EXISTS `config_info`;
CREATE TABLE `config_info` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
`data_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'data_id',
`group_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
`content` longtext CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'content',
`md5` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'md5',
`gmt_create` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`gmt_modified` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
`src_user` text CHARACTER SET utf8 COLLATE utf8_bin NULL COMMENT 'source user',
`src_ip` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'source ip',
`app_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
`tenant_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT '' COMMENT '租户字段',
`c_desc` varchar(256) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
`c_use` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
`effect` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
`type` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
`c_schema` text CHARACTER SET utf8 COLLATE utf8_bin NULL,
`encrypted_data_key` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `uk_configinfo_datagrouptenant`(`data_id`, `group_id`, `tenant_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 11 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = 'config_info' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of config_info
-- ----------------------------
INSERT INTO `config_info` VALUES (2, 'cloudalibaba-config-service-dev.yaml', 'devGroup', 'server:\r\n port: 8002\r\n servlet:\r\n context-path: /api\r\n \r\n#日志\r\n#logging:\r\n# level:\r\n# com.home: info\r\n# file:\r\n# name: test.log\r\n \r\n#nacos配置\r\nspring:\r\n application:\r\n #应用名称\r\n name: cloudalibaba-config-service\r\n profiles:\r\n #配置环境\r\n active: dev\r\n cloud:\r\n nacos:\r\n discovery: \r\n # 服务注册地址\r\n server-addr: 127.0.0.1:8848\r\n config: \r\n # 配置中心地址\r\n server-addr: 127.0.0.1:8848\r\n # 配置文件格式\r\n file-extension: yaml #后缀名\r\n group: devGroup #分组\r\n namespace: 6c0d1238-2c4a-4c1c-b790-8a5783d3acb1 #命名空间的id\r\n info: 111\r\n\r\n\r\n', '04aaac5d4d69c8f45f648d15cde9a6a7', '2022-12-08 01:39:26', '2022-12-08 01:39:26', NULL, '0:0:0:0:0:0:0:1', '', '6c0d1238-2c4a-4c1c-b790-8a5783d3acb1', NULL, NULL, NULL, 'yaml', NULL, '');
INSERT INTO `config_info` VALUES (4, 'cloudalibaba-config-service-dev.yaml', 'devGroup', 'server:\n port: 8002\n servlet:\n context-path: /api\n \n#日志\n#logging:\n# level:\n# com.home: info\n# file:\n# name: test.log\n \n#nacos配置\nspring:\n application:\n #应用名称\n name: cloudalibaba-config-service\n profiles:\n #配置环境\n active: dev\n cloud:\n nacos:\n discovery: \n # 服务注册地址\n server-addr: 127.0.0.1:8848\n config: \n # 配置中心地址\n server-addr: 127.0.0.1:8848\n # 配置文件格式\n file-extension: yaml #后缀名\n group: devGroup #分组\n namespace: a298fe41-a0c0-4c3d-9e8a-91788bc646e4 #命名空间的id\nconfig:\n info: 111112332\n\n\n', '7057d3875104bad8dba3da2484963a17', '2022-12-08 01:41:30', '2022-12-08 01:52:03', 'nacos', '0:0:0:0:0:0:0:1', '', 'a298fe41-a0c0-4c3d-9e8a-91788bc646e4', '', '', '', 'yaml', '', '');
-- ----------------------------
-- Table structure for config_info_aggr
-- ----------------------------
DROP TABLE IF EXISTS `config_info_aggr`;
CREATE TABLE `config_info_aggr` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
`data_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'data_id',
`group_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'group_id',
`datum_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'datum_id',
`content` longtext CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '内容',
`gmt_modified` datetime(0) NOT NULL COMMENT '修改时间',
`app_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
`tenant_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT '' COMMENT '租户字段',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `uk_configinfoaggr_datagrouptenantdatum`(`data_id`, `group_id`, `tenant_id`, `datum_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = '增加租户字段' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for config_info_beta
-- ----------------------------
DROP TABLE IF EXISTS `config_info_beta`;
CREATE TABLE `config_info_beta` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
`data_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'data_id',
`group_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'group_id',
`app_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'app_name',
`content` longtext CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'content',
`beta_ips` varchar(1024) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'betaIps',
`md5` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'md5',
`gmt_create` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`gmt_modified` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
`src_user` text CHARACTER SET utf8 COLLATE utf8_bin NULL COMMENT 'source user',
`src_ip` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'source ip',
`tenant_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT '' COMMENT '租户字段',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `uk_configinfobeta_datagrouptenant`(`data_id`, `group_id`, `tenant_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = 'config_info_beta' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for config_info_tag
-- ----------------------------
DROP TABLE IF EXISTS `config_info_tag`;
CREATE TABLE `config_info_tag` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
`data_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'data_id',
`group_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'group_id',
`tenant_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT '' COMMENT 'tenant_id',
`tag_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'tag_id',
`app_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'app_name',
`content` longtext CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'content',
`md5` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'md5',
`gmt_create` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`gmt_modified` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
`src_user` text CHARACTER SET utf8 COLLATE utf8_bin NULL COMMENT 'source user',
`src_ip` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'source ip',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `uk_configinfotag_datagrouptenanttag`(`data_id`, `group_id`, `tenant_id`, `tag_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = 'config_info_tag' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for config_tags_relation
-- ----------------------------
DROP TABLE IF EXISTS `config_tags_relation`;
CREATE TABLE `config_tags_relation` (
`id` bigint(20) NOT NULL COMMENT 'id',
`tag_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'tag_name',
`tag_type` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'tag_type',
`data_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'data_id',
`group_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'group_id',
`tenant_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT '' COMMENT 'tenant_id',
`nid` bigint(20) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`nid`) USING BTREE,
UNIQUE INDEX `uk_configtagrelation_configidtag`(`id`, `tag_name`, `tag_type`) USING BTREE,
INDEX `idx_tenant_id`(`tenant_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = 'config_tag_relation' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for group_capacity
-- ----------------------------
DROP TABLE IF EXISTS `group_capacity`;
CREATE TABLE `group_capacity` (
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`group_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '' COMMENT 'Group ID,空字符表示整个集群',
`quota` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '配额,0表示使用默认值',
`usage` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '使用量',
`max_size` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '单个配置大小上限,单位为字节,0表示使用默认值',
`max_aggr_count` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '聚合子配置最大个数,,0表示使用默认值',
`max_aggr_size` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值',
`max_history_count` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最大变更历史数量',
`gmt_create` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`gmt_modified` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `uk_group_id`(`group_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = '集群、各Group容量信息表' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for his_config_info
-- ----------------------------
DROP TABLE IF EXISTS `his_config_info`;
CREATE TABLE `his_config_info` (
`id` bigint(64) UNSIGNED NOT NULL,
`nid` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`data_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`group_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`app_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'app_name',
`content` longtext CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`md5` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
`gmt_create` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
`gmt_modified` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
`src_user` text CHARACTER SET utf8 COLLATE utf8_bin NULL,
`src_ip` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
`op_type` char(10) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
`tenant_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT '' COMMENT '租户字段',
`encrypted_data_key` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
PRIMARY KEY (`nid`) USING BTREE,
INDEX `idx_gmt_create`(`gmt_create`) USING BTREE,
INDEX `idx_gmt_modified`(`gmt_modified`) USING BTREE,
INDEX `idx_did`(`data_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 13 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = '多租户改造' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of his_config_info
-- ----------------------------
INSERT INTO `his_config_info` VALUES (0, 1, '1111', 'DEFAULT_GROUP', '', '111', '698d51a19d8a121ce581499d7b701668', '2022-12-08 09:38:33', '2022-12-08 01:38:33', NULL, '0:0:0:0:0:0:0:1', 'I', '6c0d1238-2c4a-4c1c-b790-8a5783d3acb1', '');
INSERT INTO `his_config_info` VALUES (1, 2, '1111', 'DEFAULT_GROUP', '', '111', '698d51a19d8a121ce581499d7b701668', '2022-12-08 09:38:46', '2022-12-08 01:38:47', NULL, '0:0:0:0:0:0:0:1', 'D', '6c0d1238-2c4a-4c1c-b790-8a5783d3acb1', '');
INSERT INTO `his_config_info` VALUES (0, 3, 'cloudalibaba-config-service-dev.yaml', 'devGroup', '', 'server:\r\n port: 8002\r\n servlet:\r\n context-path: /api\r\n \r\n#日志\r\n#logging:\r\n# level:\r\n# com.home: info\r\n# file:\r\n# name: test.log\r\n \r\n#nacos配置\r\nspring:\r\n application:\r\n #应用名称\r\n name: cloudalibaba-config-service\r\n profiles:\r\n #配置环境\r\n active: dev\r\n cloud:\r\n nacos:\r\n discovery: \r\n # 服务注册地址\r\n server-addr: 127.0.0.1:8848\r\n config: \r\n # 配置中心地址\r\n server-addr: 127.0.0.1:8848\r\n # 配置文件格式\r\n file-extension: yaml #后缀名\r\n group: devGroup #分组\r\n namespace: 6c0d1238-2c4a-4c1c-b790-8a5783d3acb1 #命名空间的id\r\n info: 111\r\n\r\n\r\n', '04aaac5d4d69c8f45f648d15cde9a6a7', '2022-12-08 09:39:25', '2022-12-08 01:39:26', NULL, '0:0:0:0:0:0:0:1', 'I', '6c0d1238-2c4a-4c1c-b790-8a5783d3acb1', '');
INSERT INTO `his_config_info` VALUES (0, 4, 'cloudalibaba-config-service-dev.yaml', 'devGroup', '', 'server:\r\n port: 8002\r\n servlet:\r\n context-path: /api\r\n \r\n#日志\r\n#logging:\r\n# level:\r\n# com.home: info\r\n# file:\r\n# name: test.log\r\n \r\n#nacos配置\r\nspring:\r\n application:\r\n #应用名称\r\n name: cloudalibaba-config-service\r\n profiles:\r\n #配置环境\r\n active: dev\r\n cloud:\r\n nacos:\r\n discovery: \r\n # 服务注册地址\r\n server-addr: 127.0.0.1:8848\r\n config: \r\n # 配置中心地址\r\n server-addr: 127.0.0.1:8848\r\n # 配置文件格式\r\n file-extension: yaml #后缀名\r\n group: devGroup #分组\r\n namespace: a298fe41-a0c0-4c3d-9e8a-91788bc646e4 #命名空间的id\r\n info: 111\r\n\r\n\r\n', '0a343a4d8485b11ecc705da1cb120a4f', '2022-12-08 09:40:59', '2022-12-08 01:41:00', NULL, '0:0:0:0:0:0:0:1', 'I', '', '');
INSERT INTO `his_config_info` VALUES (0, 5, 'cloudalibaba-config-service-dev.yaml', 'devGroup', '', 'server:\r\n port: 8002\r\n servlet:\r\n context-path: /api\r\n \r\n#日志\r\n#logging:\r\n# level:\r\n# com.home: info\r\n# file:\r\n# name: test.log\r\n \r\n#nacos配置\r\nspring:\r\n application:\r\n #应用名称\r\n name: cloudalibaba-config-service\r\n profiles:\r\n #配置环境\r\n active: dev\r\n cloud:\r\n nacos:\r\n discovery: \r\n # 服务注册地址\r\n server-addr: 127.0.0.1:8848\r\n config: \r\n # 配置中心地址\r\n server-addr: 127.0.0.1:8848\r\n # 配置文件格式\r\n file-extension: yaml #后缀名\r\n group: devGroup #分组\r\n namespace: a298fe41-a0c0-4c3d-9e8a-91788bc646e4 #命名空间的id\r\n info: 111\r\n\r\n\r\n', '0a343a4d8485b11ecc705da1cb120a4f', '2022-12-08 09:41:30', '2022-12-08 01:41:30', NULL, '0:0:0:0:0:0:0:1', 'I', 'a298fe41-a0c0-4c3d-9e8a-91788bc646e4', '');
INSERT INTO `his_config_info` VALUES (3, 6, 'cloudalibaba-config-service-dev.yaml', 'devGroup', '', 'server:\r\n port: 8002\r\n servlet:\r\n context-path: /api\r\n \r\n#日志\r\n#logging:\r\n# level:\r\n# com.home: info\r\n# file:\r\n# name: test.log\r\n \r\n#nacos配置\r\nspring:\r\n application:\r\n #应用名称\r\n name: cloudalibaba-config-service\r\n profiles:\r\n #配置环境\r\n active: dev\r\n cloud:\r\n nacos:\r\n discovery: \r\n # 服务注册地址\r\n server-addr: 127.0.0.1:8848\r\n config: \r\n # 配置中心地址\r\n server-addr: 127.0.0.1:8848\r\n # 配置文件格式\r\n file-extension: yaml #后缀名\r\n group: devGroup #分组\r\n namespace: a298fe41-a0c0-4c3d-9e8a-91788bc646e4 #命名空间的id\r\n info: 111\r\n\r\n\r\n', '0a343a4d8485b11ecc705da1cb120a4f', '2022-12-08 09:41:34', '2022-12-08 01:41:34', NULL, '0:0:0:0:0:0:0:1', 'D', '', '');
INSERT INTO `his_config_info` VALUES (4, 7, 'cloudalibaba-config-service-dev.yaml', 'devGroup', '', 'server:\r\n port: 8002\r\n servlet:\r\n context-path: /api\r\n \r\n#日志\r\n#logging:\r\n# level:\r\n# com.home: info\r\n# file:\r\n# name: test.log\r\n \r\n#nacos配置\r\nspring:\r\n application:\r\n #应用名称\r\n name: cloudalibaba-config-service\r\n profiles:\r\n #配置环境\r\n active: dev\r\n cloud:\r\n nacos:\r\n discovery: \r\n # 服务注册地址\r\n server-addr: 127.0.0.1:8848\r\n config: \r\n # 配置中心地址\r\n server-addr: 127.0.0.1:8848\r\n # 配置文件格式\r\n file-extension: yaml #后缀名\r\n group: devGroup #分组\r\n namespace: a298fe41-a0c0-4c3d-9e8a-91788bc646e4 #命名空间的id\r\n info: 111\r\n\r\n\r\n', '0a343a4d8485b11ecc705da1cb120a4f', '2022-12-08 09:43:02', '2022-12-08 01:43:03', 'nacos', '0:0:0:0:0:0:0:1', 'U', 'a298fe41-a0c0-4c3d-9e8a-91788bc646e4', '');
INSERT INTO `his_config_info` VALUES (4, 8, 'cloudalibaba-config-service-dev.yaml', 'devGroup', '', 'server:\n port: 8002\n servlet:\n context-path: /api\n \n#日志\n#logging:\n# level:\n# com.home: info\n# file:\n# name: test.log\n \n#nacos配置\nspring:\n application:\n #应用名称\n name: cloudalibaba-config-service\n profiles:\n #配置环境\n active: dev\n cloud:\n nacos:\n discovery: \n # 服务注册地址\n server-addr: 127.0.0.1:8848\n config: \n # 配置中心地址\n server-addr: 127.0.0.1:8848\n # 配置文件格式\n file-extension: yaml #后缀名\n group: devGroup #分组\n namespace: a298fe41-a0c0-4c3d-9e8a-91788bc646e4 #命名空间的id\nconfig:\n info: 222\n\n\n', '95c16f98f68c074d198b5dcdfe436adc', '2022-12-08 09:44:35', '2022-12-08 01:44:35', 'nacos', '0:0:0:0:0:0:0:1', 'U', 'a298fe41-a0c0-4c3d-9e8a-91788bc646e4', '');
INSERT INTO `his_config_info` VALUES (4, 9, 'cloudalibaba-config-service-dev.yaml', 'devGroup', '', 'server:\n port: 8002\n servlet:\n context-path: /api\n \n#日志\n#logging:\n# level:\n# com.home: info\n# file:\n# name: test.log\n \n#nacos配置\nspring:\n application:\n #应用名称\n name: cloudalibaba-config-service\n profiles:\n #配置环境\n active: dev\n cloud:\n nacos:\n discovery: \n # 服务注册地址\n server-addr: 127.0.0.1:8848\n config: \n # 配置中心地址\n server-addr: 127.0.0.1:8848\n # 配置文件格式\n file-extension: yaml #后缀名\n group: devGroup #分组\n namespace: a298fe41-a0c0-4c3d-9e8a-91788bc646e4 #命名空间的id\nconfig:\n info: 222\n\n\n', '95c16f98f68c074d198b5dcdfe436adc', '2022-12-08 09:46:48', '2022-12-08 01:46:49', 'nacos', '0:0:0:0:0:0:0:1', 'U', 'a298fe41-a0c0-4c3d-9e8a-91788bc646e4', '');
INSERT INTO `his_config_info` VALUES (4, 10, 'cloudalibaba-config-service-dev.yaml', 'devGroup', '', 'server:\n port: 8002\n servlet:\n context-path: /api\n \n#日志\n#logging:\n# level:\n# com.home: info\n# file:\n# name: test.log\n \n#nacos配置\nspring:\n application:\n #应用名称\n name: cloudalibaba-config-service\n profiles:\n #配置环境\n active: dev\n cloud:\n nacos:\n discovery: \n # 服务注册地址\n server-addr: 127.0.0.1:8848\n config: \n # 配置中心地址\n server-addr: 127.0.0.1:8848\n # 配置文件格式\n file-extension: yaml #后缀名\n group: devGroup #分组\n namespace: a298fe41-a0c0-4c3d-9e8a-91788bc646e4 #命名空间的id\nconfig:\n info: 333\n\n\n', 'c0456765a82f826585ab72406214f6aa', '2022-12-08 09:50:58', '2022-12-08 01:50:59', 'nacos', '0:0:0:0:0:0:0:1', 'U', 'a298fe41-a0c0-4c3d-9e8a-91788bc646e4', '');
INSERT INTO `his_config_info` VALUES (4, 11, 'cloudalibaba-config-service-dev.yaml', 'devGroup', '', 'server:\n port: 8002\n servlet:\n context-path: /api\n \n#日志\n#logging:\n# level:\n# com.home: info\n# file:\n# name: test.log\n \n#nacos配置\nspring:\n application:\n #应用名称\n name: cloudalibaba-config-service\n profiles:\n #配置环境\n active: dev\n cloud:\n nacos:\n discovery: \n # 服务注册地址\n server-addr: 127.0.0.1:8848\n config: \n # 配置中心地址\n server-addr: 127.0.0.1:8848\n # 配置文件格式\n file-extension: yaml #后缀名\n group: devGroup #分组\n namespace: a298fe41-a0c0-4c3d-9e8a-91788bc646e4 #命名空间的id\nconfig:\n info: 555\n\n\n', '581d859118e82478112337febc2d637d', '2022-12-08 09:51:51', '2022-12-08 01:51:51', 'nacos', '0:0:0:0:0:0:0:1', 'U', 'a298fe41-a0c0-4c3d-9e8a-91788bc646e4', '');
INSERT INTO `his_config_info` VALUES (4, 12, 'cloudalibaba-config-service-dev.yaml', 'devGroup', '', 'server:\n port: 8002\n servlet:\n context-path: /api\n \n#日志\n#logging:\n# level:\n# com.home: info\n# file:\n# name: test.log\n \n#nacos配置\nspring:\n application:\n #应用名称\n name: cloudalibaba-config-service\n profiles:\n #配置环境\n active: dev\n cloud:\n nacos:\n discovery: \n # 服务注册地址\n server-addr: 127.0.0.1:8848\n config: \n # 配置中心地址\n server-addr: 127.0.0.1:8848\n # 配置文件格式\n file-extension: yaml #后缀名\n group: devGroup #分组\n namespace: a298fe41-a0c0-4c3d-9e8a-91788bc646e4 #命名空间的id\nconfig:\n info: 666\n\n\n', 'd9ee02a94ef6c667598be3aec08cbebe', '2022-12-08 09:52:02', '2022-12-08 01:52:03', 'nacos', '0:0:0:0:0:0:0:1', 'U', 'a298fe41-a0c0-4c3d-9e8a-91788bc646e4', '');
-- ----------------------------
-- Table structure for permissions
-- ----------------------------
DROP TABLE IF EXISTS `permissions`;
CREATE TABLE `permissions` (
`role` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`resource` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`action` varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
UNIQUE INDEX `uk_role_permission`(`role`, `resource`, `action`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for roles
-- ----------------------------
DROP TABLE IF EXISTS `roles`;
CREATE TABLE `roles` (
`username` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`role` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
UNIQUE INDEX `idx_user_role`(`username`, `role`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of roles
-- ----------------------------
INSERT INTO `roles` VALUES ('nacos', 'ROLE_ADMIN');
-- ----------------------------
-- Table structure for tenant_capacity
-- ----------------------------
DROP TABLE IF EXISTS `tenant_capacity`;
CREATE TABLE `tenant_capacity` (
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`tenant_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '' COMMENT 'Tenant ID',
`quota` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '配额,0表示使用默认值',
`usage` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '使用量',
`max_size` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '单个配置大小上限,单位为字节,0表示使用默认值',
`max_aggr_count` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '聚合子配置最大个数',
`max_aggr_size` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值',
`max_history_count` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最大变更历史数量',
`gmt_create` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`gmt_modified` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `uk_tenant_id`(`tenant_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = '租户容量信息表' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for tenant_info
-- ----------------------------
DROP TABLE IF EXISTS `tenant_info`;
CREATE TABLE `tenant_info` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
`kp` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'kp',
`tenant_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT '' COMMENT 'tenant_id',
`tenant_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT '' COMMENT 'tenant_name',
`tenant_desc` varchar(256) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'tenant_desc',
`create_source` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'create_source',
`gmt_create` bigint(20) NOT NULL COMMENT '创建时间',
`gmt_modified` bigint(20) NOT NULL COMMENT '修改时间',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `uk_tenant_info_kptenantid`(`kp`, `tenant_id`) USING BTREE,
INDEX `idx_tenant_id`(`tenant_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = 'tenant_info' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of tenant_info
-- ----------------------------
INSERT INTO `tenant_info` VALUES (1, '1', 'a298fe41-a0c0-4c3d-9e8a-91788bc646e4', 'dazhi', '123456', 'nacos', 1670463623444, 1670463623444);
-- ----------------------------
-- Table structure for users
-- ----------------------------
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`username` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`password` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`enabled` tinyint(1) NOT NULL,
PRIMARY KEY (`username`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of users
-- ----------------------------
INSERT INTO `users` VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', 1);
SET FOREIGN_KEY_CHECKS = 1;
linux下安装
1.下载
docker pull nacos/nacos-server
#推荐使用这种方式,可以连接自己的数据库
# 创建 nacos 配置存放目录
mkdir -p /home/nacos/conf && chown -R 200 /home/nacos/conf
# 创建 nacos 日志存放目录
mkdir -p /home/nacos/logs && chown -R 200 /home/nacos/logs
# 创建 nacos 数据存放目录
mkdir -p /home/nacos/data && chown -R 200 /home/nacos/data
--------------------启动一个最初级的---------
docker run -d -p 8848:8848 \
--name nacos \
--env MODE=standalone \
--env SPRING_DATASOURCE_PLATFORM=mysql \
--env MYSQL_SERVICE_HOST=152.136.145.72 \
--env MYSQL_SERVICE_PORT=3306 \
--env MYSQL_SERVICE_DB_NAME=nacos_config \
--env MYSQL_SERVICE_USER=root \
--env MYSQL_SERVICE_PASSWORD=171226zxY \
nacos/nacos-server:latest
//复制相关文件
# 把容器中的 nacos 文件复制出来
docker cp -a nacos:/home/nacos /home/docker/
# 删除 nacos 容器
docker rm -f nacos
//启动新的nacos,可以自定义配置
docker run -d -p 8848:8848 \
--name nacos \
--env MODE=standalone \
--env SPRING_DATASOURCE_PLATFORM=mysql \
--env MYSQL_SERVICE_HOST=152.136.145.72 \
--env MYSQL_SERVICE_PORT=3306 \
--env MYSQL_SERVICE_DB_NAME=nacos_config \
--env MYSQL_SERVICE_USER=root \
--env MYSQL_SERVICE_PASSWORD=171226zxY \
-v /home/docker/nacos/conf:/home/nacos/conf \
-v /home/docker/nacos/logs:/home/nacos/logs \
-v /home/docker/nacos/data:/home/nacos/data \
nacos/nacos-server:latest
//启动 内存2G的设备启动不起来
http://17.94.194.88:8848/nacos
windows下安装
修改数据库的配置
修改启动配置standalone
启动nacos成功!进入http://localhost:8848/nacos账号密码都是nacos
新建命名空间
作为配置中心
回滚,将配置文件回滚到这个版本
添加配置,要注意Data ID和Group
代码中的组合获取到
如果想nocas修改完立即生效,Controller要加@RefreshScope
JAVA项目中的配置
pom
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.home</groupId>
<artifactId>Home</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>home-first</artifactId>
<packaging>jar</packaging>
<properties>
<java.version>8</java.version>
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
<!--阿里json-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.46</version>
</dependency>
<!-- SpringCloud Ailibaba Nacos client -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- SpringCloud Ailibaba Nacos Config -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<dependency>
<groupId>com.home</groupId>
<artifactId>home-common</artifactId>
<version>${home.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
yml
bootstrap.yml
spring:
profiles:
active: dev
bootstrap-dev.yml
server:
port: 8002
servlet:
context-path: /api
#日志
#logging:
# level:
# com.home: info
# file:
# name: test.log
#nacos配置
spring:
application:
#应用名称
name: cloudalibaba-config-service
profiles:
#配置环境
active: dev
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 192.168.60.246:8848
namespace: a298fe41-a0c0-4c3d-9e8a-91788bc646e4 #命名空间的id
group: devGroup #分组
config:
# 配置中心地址
server-addr: 192.168.60.246:8848
# 配置文件格式
file-extension: yaml #后缀名
group: devGroup #分组
namespace: a298fe41-a0c0-4c3d-9e8a-91788bc646e4 #命名空间的id
config:
info: 111
共享多个配置-shared-configs
server:
port: 8099
servlet:
context-path: /bjjuli
#日志
#logging:
# level:
# com.home: info
# file:
# name: test.log
#nacos配置
spring:
application:
#应用名称
name: order-server
profiles:
#配置环境
active: dev
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 192.168.60.114:8848
namespace: ef6fb30c-43a9-4292-b9a2-09eb500e73ab #命名空间的id
group: devGroup #分组
config:
# 配置中心地址
server-addr: 192.168.60.114:8848
prefix: ${spring.application.name}
# 配置文件格式
file-extension: yaml #后缀名
group: devGroup #分组
namespace: ef6fb30c-43a9-4292-b9a2-09eb500e73ab #命名空间的id
shared-configs: #共享多个配置
- data-id: server-all.yaml
group: devGroup
refresh: true #动态刷新配置开启
- data-id: server-all2.yaml
group: devGroup
refresh: false #动态刷新配置关闭
代码
@RefreshScope 加这个配置会实时刷新nacos更新后的数据
nacos更新后,项目就会收到更新的通知
@RestController
@RequestMapping("/test")
@RefreshScope
public class Test {
public final static Logger Log = LoggerFactory.getLogger(Test.class);
@Value("${config.info}")
private String info; //该属性值是从nacos配置中心拉取到的配置
@GetMapping("/testConfig")
public String testConfig(){
return info;
}
}