部署 Nacos ( Docker )
[Step 1] : 拉取 Nacos 镜像
docker pull nacos/nacos-server:v2.1.1
[Step 2] : 创建目录 ➡️ 创建容器 ➡️ 拷贝文件 ➡️ 授权文件 ➡️ 删除容器
# 创建目录mkdir -p /data/nacos/{conf,logs,data}# 创建容器
docker run -p 8848:8848 --name nacos -d nacos/nacos-server:v2.1.1
# 拷贝文件
docker cp nacos:/home/nacos/conf /data/nacos
docker cp nacos:/home/nacos/data /data/nacos
docker cp nacos:/home/nacos/logs /data/nacos
# 授权文件chmod777 /data/nacos/{conf,logs,data}# 删除容器
docker rm -f nacos
[Step 3] : 创建 Nacos 数据持久化数据库
SQL语句如下:
/*
Navicat Premium Data Transfer
Source Server : 159.75.111.41
Source Server Type : MySQL
Source Server Version : 80033
Source Host : 159.75.111.41:3306
Source Schema : nacos
Target Server Type : MySQL
Target Server Version : 80033
File Encoding : 65001
Date: 30/03/2024 21:32:58
*/SET NAMES utf8mb4;SET FOREIGN_KEY_CHECKS =0;-- ------------------------------ Table structure for config_info-- ----------------------------DROPTABLEIFEXISTS`config_info`;CREATETABLE`config_info`(`id`bigint(0)NOTNULLAUTO_INCREMENTCOMMENT'id',`data_id`varchar(255)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NOTNULLCOMMENT'data_id',`group_id`varchar(128)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLDEFAULTNULL,`content`longtextCHARACTERSET utf8mb3 COLLATE utf8mb3_bin NOTNULLCOMMENT'content',`md5`varchar(32)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLDEFAULTNULLCOMMENT'md5',`gmt_create`datetime(0)NULLDEFAULTCURRENT_TIMESTAMP(0)COMMENT'创建时间',`gmt_modified`datetime(0)NULLDEFAULTCURRENT_TIMESTAMP(0)COMMENT'修改时间',`src_user`textCHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLCOMMENT'source user',`src_ip`varchar(50)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLDEFAULTNULLCOMMENT'source ip',`app_name`varchar(128)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLDEFAULTNULL,`tenant_id`varchar(128)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLDEFAULT''COMMENT'租户字段',`c_desc`varchar(256)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLDEFAULTNULL,`c_use`varchar(64)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLDEFAULTNULL,`effect`varchar(64)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLDEFAULTNULL,`type`varchar(64)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLDEFAULTNULL,`c_schema`textCHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULL,`encrypted_data_key`textCHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLCOMMENT'秘钥',PRIMARYKEY(`id`)USINGBTREE,UNIQUEINDEX`uk_configinfo_datagrouptenant`(`data_id`,`group_id`,`tenant_id`)USINGBTREE)ENGINE=InnoDBAUTO_INCREMENT=1CHARACTERSET= utf8mb3 COLLATE= utf8mb3_bin COMMENT='config_info' ROW_FORMAT = Dynamic;-- ------------------------------ Records of config_info-- ------------------------------ ------------------------------ Table structure for config_info_aggr-- ----------------------------DROPTABLEIFEXISTS`config_info_aggr`;CREATETABLE`config_info_aggr`(`id`bigint(0)NOTNULLAUTO_INCREMENTCOMMENT'id',`data_id`varchar(255)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NOTNULLCOMMENT'data_id',`group_id`varchar(128)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NOTNULLCOMMENT'group_id',`datum_id`varchar(255)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NOTNULLCOMMENT'datum_id',`content`longtextCHARACTERSET utf8mb3 COLLATE utf8mb3_bin NOTNULLCOMMENT'内容',`gmt_modified`datetime(0)NULLDEFAULTNULLCOMMENT'修改时间',`app_name`varchar(128)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLDEFAULTNULL,`tenant_id`varchar(128)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLDEFAULT''COMMENT'租户字段',PRIMARYKEY(`id`)USINGBTREE,UNIQUEINDEX`uk_configinfoaggr_datagrouptenantdatum`(`data_id`,`group_id`,`tenant_id`,`datum_id`)USINGBTREE)ENGINE=InnoDBAUTO_INCREMENT=1CHARACTERSET= utf8mb3 COLLATE= utf8mb3_bin COMMENT='增加租户字段' ROW_FORMAT = Dynamic;-- ------------------------------ Records of config_info_aggr-- ------------------------------ ------------------------------ Table structure for config_info_beta-- ----------------------------DROPTABLEIFEXISTS`config_info_beta`;CREATETABLE`config_info_beta`(`id`bigint(0)NOTNULLAUTO_INCREMENTCOMMENT'id',`data_id`varchar(255)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NOTNULLCOMMENT'data_id',`group_id`varchar(128)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NOTNULLCOMMENT'group_id',`app_name`varchar(128)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLDEFAULTNULLCOMMENT'app_name',`content`longtextCHARACTERSET utf8mb3 COLLATE utf8mb3_bin NOTNULLCOMMENT'content',`beta_ips`varchar(1024)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLDEFAULTNULLCOMMENT'betaIps',`md5`varchar(32)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLDEFAULTNULLCOMMENT'md5',`gmt_create`datetime(0)NULLDEFAULTCURRENT_TIMESTAMP(0)COMMENT'创建时间',`gmt_modified`datetime(0)NULLDEFAULTCURRENT_TIMESTAMP(0)COMMENT'修改时间',`src_user`textCHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLCOMMENT'source user',`src_ip`varchar(50)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLDEFAULTNULLCOMMENT'source ip',`tenant_id`varchar(128)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLDEFAULT''COMMENT'租户字段',`encrypted_data_key`textCHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLCOMMENT'秘钥',PRIMARYKEY(`id`)USINGBTREE,UNIQUEINDEX`uk_configinfobeta_datagrouptenant`(`data_id`,`group_id`,`tenant_id`)USINGBTREE)ENGINE=InnoDBAUTO_INCREMENT=1CHARACTERSET= utf8mb3 COLLATE= utf8mb3_bin COMMENT='config_info_beta' ROW_FORMAT = Dynamic;-- ------------------------------ Records of config_info_beta-- ------------------------------ ------------------------------ Table structure for config_info_tag-- ----------------------------DROPTABLEIFEXISTS`config_info_tag`;CREATETABLE`config_info_tag`(`id`bigint(0)NOTNULLAUTO_INCREMENTCOMMENT'id',`data_id`varchar(255)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NOTNULLCOMMENT'data_id',`group_id`varchar(128)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NOTNULLCOMMENT'group_id',`tenant_id`varchar(128)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLDEFAULT''COMMENT'tenant_id',`tag_id`varchar(128)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NOTNULLCOMMENT'tag_id',`app_name`varchar(128)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLDEFAULTNULLCOMMENT'app_name',`content`longtextCHARACTERSET utf8mb3 COLLATE utf8mb3_bin NOTNULLCOMMENT'content',`md5`varchar(32)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLDEFAULTNULLCOMMENT'md5',`gmt_create`datetime(0)NULLDEFAULTCURRENT_TIMESTAMP(0)COMMENT'创建时间',`gmt_modified`datetime(0)NULLDEFAULTCURRENT_TIMESTAMP(0)COMMENT'修改时间',`src_user`textCHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLCOMMENT'source user',`src_ip`varchar(50)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLDEFAULTNULLCOMMENT'source ip',PRIMARYKEY(`id`)USINGBTREE,UNIQUEINDEX`uk_configinfotag_datagrouptenanttag`(`data_id`,`group_id`,`tenant_id`,`tag_id`)USINGBTREE)ENGINE=InnoDBAUTO_INCREMENT=1CHARACTERSET= utf8mb3 COLLATE= utf8mb3_bin COMMENT='config_info_tag' ROW_FORMAT = Dynamic;-- ------------------------------ Records of config_info_tag-- ------------------------------ ------------------------------ Table structure for config_tags_relation-- ----------------------------DROPTABLEIFEXISTS`config_tags_relation`;CREATETABLE`config_tags_relation`(`id`bigint(0)NOTNULLCOMMENT'id',`tag_name`varchar(128)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NOTNULLCOMMENT'tag_name',`tag_type`varchar(64)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLDEFAULTNULLCOMMENT'tag_type',`data_id`varchar(255)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NOTNULLCOMMENT'data_id',`group_id`varchar(128)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NOTNULLCOMMENT'group_id',`tenant_id`varchar(128)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLDEFAULT''COMMENT'tenant_id',`nid`bigint(0)NOTNULLAUTO_INCREMENT,PRIMARYKEY(`nid`)USINGBTREE,UNIQUEINDEX`uk_configtagrelation_configidtag`(`id`,`tag_name`,`tag_type`)USINGBTREE,INDEX`idx_tenant_id`(`tenant_id`)USINGBTREE)ENGINE=InnoDBAUTO_INCREMENT=1CHARACTERSET= utf8mb3 COLLATE= utf8mb3_bin COMMENT='config_tag_relation' ROW_FORMAT = Dynamic;-- ------------------------------ Records of config_tags_relation-- ------------------------------ ------------------------------ Table structure for group_capacity-- ----------------------------DROPTABLEIFEXISTS`group_capacity`;CREATETABLE`group_capacity`(`id`bigint(0)UNSIGNEDNOTNULLAUTO_INCREMENTCOMMENT'主键ID',`group_id`varchar(128)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NOTNULLDEFAULT''COMMENT'Group ID,空字符表示整个集群',`quota`int(0)UNSIGNEDNOTNULLDEFAULT0COMMENT'配额,0表示使用默认值',`usage`int(0)UNSIGNEDNOTNULLDEFAULT0COMMENT'使用量',`max_size`int(0)UNSIGNEDNOTNULLDEFAULT0COMMENT'单个配置大小上限,单位为字节,0表示使用默认值',`max_aggr_count`int(0)UNSIGNEDNOTNULLDEFAULT0COMMENT'聚合子配置最大个数,,0表示使用默认值',`max_aggr_size`int(0)UNSIGNEDNOTNULLDEFAULT0COMMENT'单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值',`max_history_count`int(0)UNSIGNEDNOTNULLDEFAULT0COMMENT'最大变更历史数量',`gmt_create`datetime(0)NULLDEFAULTCURRENT_TIMESTAMP(0)COMMENT'创建时间',`gmt_modified`datetime(0)NULLDEFAULTCURRENT_TIMESTAMP(0)COMMENT'修改时间',PRIMARYKEY(`id`)USINGBTREE,UNIQUEINDEX`uk_group_id`(`group_id`)USINGBTREE)ENGINE=InnoDBAUTO_INCREMENT=1CHARACTERSET= utf8mb3 COLLATE= utf8mb3_bin COMMENT='集群、各Group容量信息表' ROW_FORMAT = Dynamic;-- ------------------------------ Records of group_capacity-- ------------------------------ ------------------------------ Table structure for his_config_info-- ----------------------------DROPTABLEIFEXISTS`his_config_info`;CREATETABLE`his_config_info`(`id`bigint(0)UNSIGNEDNOTNULL,`nid`bigint(0)UNSIGNEDNOTNULLAUTO_INCREMENT,`data_id`varchar(255)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NOTNULL,`group_id`varchar(128)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NOTNULL,`app_name`varchar(128)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLDEFAULTNULLCOMMENT'app_name',`content`longtextCHARACTERSET utf8mb3 COLLATE utf8mb3_bin NOTNULL,`md5`varchar(32)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLDEFAULTNULL,`gmt_create`datetime(0)NULLDEFAULTCURRENT_TIMESTAMP(0),`gmt_modified`datetime(0)NULLDEFAULTCURRENT_TIMESTAMP(0),`src_user`textCHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULL,`src_ip`varchar(50)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLDEFAULTNULL,`op_type`char(10)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLDEFAULTNULL,`tenant_id`varchar(128)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLDEFAULT''COMMENT'租户字段',`encrypted_data_key`textCHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLCOMMENT'秘钥',PRIMARYKEY(`nid`)USINGBTREE,INDEX`idx_gmt_create`(`gmt_create`)USINGBTREE,INDEX`idx_gmt_modified`(`gmt_modified`)USINGBTREE,INDEX`idx_did`(`data_id`)USINGBTREE)ENGINE=InnoDBAUTO_INCREMENT=1CHARACTERSET= utf8mb3 COLLATE= utf8mb3_bin COMMENT='多租户改造' ROW_FORMAT = Dynamic;-- ------------------------------ Records of his_config_info-- ----------------------------INSERTINTO`his_config_info`VALUES(0,1,'132','DEFAULT_GROUP','','123','202cb962ac59075b964b07152d234b70','2024-03-30 21:32:28','2024-03-30 21:32:28',NULL,'212.87.195.237','I','',NULL);INSERTINTO`his_config_info`VALUES(1,2,'132','DEFAULT_GROUP','','123','202cb962ac59075b964b07152d234b70','2024-03-30 21:32:36','2024-03-30 21:32:36',NULL,'212.87.195.237','D','',NULL);-- ------------------------------ Table structure for permissions-- ----------------------------DROPTABLEIFEXISTS`permissions`;CREATETABLE`permissions`(`role`varchar(50)CHARACTERSET utf8mb4 COLLATE utf8mb4_general_ci NOTNULL,`resource`varchar(255)CHARACTERSET utf8mb4 COLLATE utf8mb4_general_ci NOTNULL,`action`varchar(8)CHARACTERSET utf8mb4 COLLATE utf8mb4_general_ci NOTNULL,UNIQUEINDEX`uk_role_permission`(`role`,`resource`,`action`)USINGBTREE)ENGINE=InnoDBCHARACTERSET= utf8mb4 COLLATE= utf8mb4_general_ci ROW_FORMAT = Dynamic;-- ------------------------------ Records of permissions-- ------------------------------ ------------------------------ Table structure for roles-- ----------------------------DROPTABLEIFEXISTS`roles`;CREATETABLE`roles`(`username`varchar(50)CHARACTERSET utf8mb4 COLLATE utf8mb4_general_ci NOTNULL,`role`varchar(50)CHARACTERSET utf8mb4 COLLATE utf8mb4_general_ci NOTNULL,UNIQUEINDEX`idx_user_role`(`username`,`role`)USINGBTREE)ENGINE=InnoDBCHARACTERSET= utf8mb4 COLLATE= utf8mb4_general_ci ROW_FORMAT = Dynamic;-- ------------------------------ Records of roles-- ----------------------------INSERTINTO`roles`VALUES('nacos','ROLE_ADMIN');-- ------------------------------ Table structure for tenant_capacity-- ----------------------------DROPTABLEIFEXISTS`tenant_capacity`;CREATETABLE`tenant_capacity`(`id`bigint(0)UNSIGNEDNOTNULLAUTO_INCREMENTCOMMENT'主键ID',`tenant_id`varchar(128)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NOTNULLDEFAULT''COMMENT'Tenant ID',`quota`int(0)UNSIGNEDNOTNULLDEFAULT0COMMENT'配额,0表示使用默认值',`usage`int(0)UNSIGNEDNOTNULLDEFAULT0COMMENT'使用量',`max_size`int(0)UNSIGNEDNOTNULLDEFAULT0COMMENT'单个配置大小上限,单位为字节,0表示使用默认值',`max_aggr_count`int(0)UNSIGNEDNOTNULLDEFAULT0COMMENT'聚合子配置最大个数',`max_aggr_size`int(0)UNSIGNEDNOTNULLDEFAULT0COMMENT'单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值',`max_history_count`int(0)UNSIGNEDNOTNULLDEFAULT0COMMENT'最大变更历史数量',`gmt_create`datetime(0)NULLDEFAULTCURRENT_TIMESTAMP(0)COMMENT'创建时间',`gmt_modified`datetime(0)NULLDEFAULTCURRENT_TIMESTAMP(0)COMMENT'修改时间',PRIMARYKEY(`id`)USINGBTREE,UNIQUEINDEX`uk_tenant_id`(`tenant_id`)USINGBTREE)ENGINE=InnoDBAUTO_INCREMENT=1CHARACTERSET= utf8mb3 COLLATE= utf8mb3_bin COMMENT='租户容量信息表' ROW_FORMAT = Dynamic;-- ------------------------------ Records of tenant_capacity-- ------------------------------ ------------------------------ Table structure for tenant_info-- ----------------------------DROPTABLEIFEXISTS`tenant_info`;CREATETABLE`tenant_info`(`id`bigint(0)NOTNULLAUTO_INCREMENTCOMMENT'id',`kp`varchar(128)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NOTNULLCOMMENT'kp',`tenant_id`varchar(128)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLDEFAULT''COMMENT'tenant_id',`tenant_name`varchar(128)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLDEFAULT''COMMENT'tenant_name',`tenant_desc`varchar(256)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLDEFAULTNULLCOMMENT'tenant_desc',`create_source`varchar(32)CHARACTERSET utf8mb3 COLLATE utf8mb3_bin NULLDEFAULTNULLCOMMENT'create_source',`gmt_create`bigint(0)NULLDEFAULTNULLCOMMENT'创建时间',`gmt_modified`bigint(0)NULLDEFAULTNULLCOMMENT'修改时间',PRIMARYKEY(`id`)USINGBTREE,UNIQUEINDEX`uk_tenant_info_kptenantid`(`kp`,`tenant_id`)USINGBTREE,INDEX`idx_tenant_id`(`tenant_id`)USINGBTREE)ENGINE=InnoDBAUTO_INCREMENT=1CHARACTERSET= utf8mb3 COLLATE= utf8mb3_bin COMMENT='tenant_info' ROW_FORMAT = Dynamic;-- ------------------------------ Records of tenant_info-- ------------------------------ ------------------------------ Table structure for users-- ----------------------------DROPTABLEIFEXISTS`users`;CREATETABLE`users`(`username`varchar(50)CHARACTERSET utf8mb4 COLLATE utf8mb4_general_ci NOTNULL,`password`varchar(500)CHARACTERSET utf8mb4 COLLATE utf8mb4_general_ci NOTNULL,`enabled`tinyint(1)NOTNULL,PRIMARYKEY(`username`)USINGBTREE)ENGINE=InnoDBCHARACTERSET= utf8mb4 COLLATE= utf8mb4_general_ci ROW_FORMAT = Dynamic;-- ------------------------------ Records of users-- ----------------------------INSERTINTO`users`VALUES('nacos','$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu',1);SET FOREIGN_KEY_CHECKS =1;
[Step 4] : 启动 Nacos 容器
**MYSQL_SERVICE_HOST=192.168.100.233**
: 修改为自己的MYSQL的IP**MYSQL_SERVICE_PASSWORD=123456**
** : 修改为自己的MYSQL密码****MYSQL_SERVICE_DB_NAME**
** : 换成自己Nacos对应数据库名称**docker run -d \
-e MODE=standalone \
--privileged=true \
-e SPRING_DATASOURCE_PLATFORM=mysql \
-e MYSQL_SERVICE_HOST=192.168.100.233 \
-e MYSQL_SERVICE_PORT=3306\
-e MYSQL_SERVICE_USER=root \
-e MYSQL_SERVICE_PASSWORD=123456\
-e MYSQL_SERVICE_DB_NAME=nacos \
-e TIME_ZONE='Asia/Shanghai'\
-e NACOS_AUTH_ENABLE=true \
-v /data/nacos/logs:/home/nacos/logs \
-v /data/nacos/data:/home/nacos/data \
-v /data/nacos/conf:/home/nacos/conf \
-p 8848:8848 -p 9848:9848 -p 9849:9849 \
--name nacos --restart=always nacos/nacos-server:v2.1.1
[Step 5] : 查看 Nacos 启动日志
docker logs -f nacos
[Step 6] : 访问 Nacos 控制台
# 换成自己的IP
http://192.168.100.233:8848/nacos/#/login
[Step 7] : 登录进入 Nacos 控制台
默认账号密码均为 nacos
提示:请勿发布广告垃圾评论,否则封号处理!!