1. 配置mysql 数据库
选用mysql5.7表名为nacos_config,附上建表SQL
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 NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `gmt_modified` datetime 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, PRIMARY KEY (`id`) USING BTREE, UNIQUE INDEX `uk_configinfo_datagrouptenant`(`data_id`, `group_id`, `tenant_id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = 'config_info' ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of config_info -- ---------------------------- -- ---------------------------- -- 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 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; -- ---------------------------- -- Records of config_info_aggr -- ---------------------------- -- ---------------------------- -- 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 NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `gmt_modified` datetime 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; -- ---------------------------- -- Records of config_info_beta -- ---------------------------- -- ---------------------------- -- 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 NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `gmt_modified` datetime 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; -- ---------------------------- -- Records of config_info_tag -- ---------------------------- -- ---------------------------- -- 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; -- ---------------------------- -- Records of config_tags_relation -- ---------------------------- -- ---------------------------- -- 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 NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `gmt_modified` datetime 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; -- ---------------------------- -- Records of group_capacity -- ---------------------------- -- ---------------------------- -- Table structure for his_config_info -- ---------------------------- DROP TABLE IF EXISTS `his_config_info`; CREATE TABLE `his_config_info` ( `id` bigint(20) 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 NOT NULL DEFAULT CURRENT_TIMESTAMP, `gmt_modified` datetime 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 '租户字段', 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 = 1 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = '多租户改造' ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of his_config_info -- ---------------------------- -- ---------------------------- -- Table structure for permissions -- ---------------------------- DROP TABLE IF EXISTS `permissions`; CREATE TABLE `permissions` ( `role` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL, `resource` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL, `action` varchar(8) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL, UNIQUE INDEX `uk_role_permission`(`role`, `resource`, `action`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of permissions -- ---------------------------- INSERT INTO `permissions` VALUES ('read_only', ':*:*', 'r'); -- ---------------------------- -- Table structure for roles -- ---------------------------- DROP TABLE IF EXISTS `roles`; CREATE TABLE `roles` ( `username` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL, `role` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL, UNIQUE INDEX `idx_user_role`(`username`, `role`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of roles -- ---------------------------- INSERT INTO `roles` VALUES ('nacos', 'ROLE_ADMIN'); INSERT INTO `roles` VALUES ('read_only', 'read_only'); -- ---------------------------- -- 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 NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `gmt_modified` datetime 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; -- ---------------------------- -- Records of tenant_capacity -- ---------------------------- -- ---------------------------- -- 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 = 1 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = 'tenant_info' ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of tenant_info -- ---------------------------- -- ---------------------------- -- Table structure for users -- ---------------------------- DROP TABLE IF EXISTS `users`; CREATE TABLE `users` ( `username` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL, `password` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL, `enabled` tinyint(1) NOT NULL, PRIMARY KEY (`username`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of users -- ---------------------------- INSERT INTO `users` VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', 1); INSERT INTO `users` VALUES ('read_only', '$2a$10$.E.Kw7GeOyJbQWDTSYMKouGPKCoyOQkoSCoAfVeFApFMkuZ2xgS5y', 1); SET FOREIGN_KEY_CHECKS = 1;
2. 创建nacos 日志挂在路径
mkdir -p /usr/local/software/nacos/logs
3. 执行docker命令
选用nacos 2.0.2
docker run -d \ -e NACOS_AUTH_ENABLE=true \ -e MODE=standalone \ -e JVM_XMS=128m \ -e JVM_XMX=128m \ -e JVM_XMN=128m \ -p 8848:8848 \ -p 9848:9848 \ -e SPRING_DATASOURCE_PLATFORM=mysql \ -e MYSQL_SERVICE_HOST=192.168.0.193 \ -e MYSQL_SERVICE_PORT=3306 \ -e MYSQL_SERVICE_USER=root \ -e MYSQL_SERVICE_PASSWORD=root \ -e MYSQL_SERVICE_DB_NAME=nacos_config \ -e MYSQL_SERVICE_DB_PARAM='characterEncoding=utf8&connectTimeout=10000&socketTimeout=30000&autoReconnect=true&useSSL=false' \ --restart=always \ --privileged=true \ -v /usr/local/software/nacos/logs:/home/nacos/logs \ --name nacos_auth \ nacos/nacos-server:2.0.2
参数说明:
参数 | 说明 |
-d | 以守护进程的方式启动 |
-e NACOS_AUTH_ENABLE=true | 开启 Nacos server 的注册鉴权 |
-e MODE=standalone | 以单机模式启动 |
-e JVM_XMS=128m | 为jvm启动时分配的内存 |
-e JVM_XMX=128m | 为jvm运行过程中分配的最大内存 |
-e JVM_XMN=128m | 为jvm设置年轻代的大小 |
-p 8848:8848 | 把容器内的端口8848挂载到宿主机8848上面 |
-p 9848:9848 | 把容器内的端口9848挂载到宿主机9848上面 |
-e SPRING_DATASOURCE_PLATFORM=mysql | 以mysql为nacos做数据持久化 |
-e MYSQL_SERVICE_HOST=192.168.0.193 | mysql地址,设置成自己的 |
-e MYSQL_SERVICE_PORT=3306 | mysql端口 |
-e MYSQL_SERVICE_USER=root | mysql账号 |
-e MYSQL_SERVICE_PASSWORD=root | mysql密码 |
-e MYSQL_SERVICE_DB_NAME=nacos_config | 使用mysql的哪个库 |
-e MYSQL_SERVICE_DB_PARAM='characterEncoding=utf8&connectTimeout=10000&socketTimeout=30000&autoReconnect=true&useSSL=false' | mysql常用连接参数 |
--restart=always | docker重启时候容器自动重启 |
--privileged=true | 以root权限运行容器 |
-v /usr/local/software/nacos/logs:/home/nacos/logs | 挂在nacos运行日志路径 |
--name nacos_auth | 容器的名字 |
nacos/nacos-server:2.0.2 | 使用的nacos镜像 |
4. 访问浏览器页面
ip:8848/nacos
出现这个页面证明启动成功了
初始账号密码为:nacos/nacos(记得改密码!!!)
5. 捐赠支持
你可以请作者喝杯咖啡表示鼓励
标签:COMMENT,SET,单机版,--,utf8,nacos,mysql,NULL,id From: https://www.cnblogs.com/sunxun001/p/17408817.html