当前位置:网站首页>Building Nacos 2 based on docker compose (using MySQL for persistence)
Building Nacos 2 based on docker compose (using MySQL for persistence)
2022-06-13 05:09:00 【Fried fried dough sticks】
List of articles
summary
I'm putting a SpringBoot Individual projects are migrated to Spring Cloud On the microservice project , First configuration Nacos 2 As the configuration center of the microservice project / Registry Center , And use MySQL Database pair Nacos As a persistence solution .
Installation steps
One 、 install Docker And Docker Compose
Docker Is an open source software , It's an open platform , For developing applications 、 deliver (shipping) application 、 Run the application . Docker Allow users to put infrastructure (Infrastructure) The applications in are separated separately , Form smaller particles ( Containers ), To speed up the delivery of software .
Docker Install the reference :https://docs.docker.com/engine/install/
Compose Is used to define and run multiple containers Docker Application tools . adopt Compose, You can use YML File to configure all the services the application needs . then , Use a command , You can start from YML Create and start all services in the file configuration .
Docker Compose Install the reference :https://docs.docker.com/compose/install/
Two 、 function Docker Compose file
service.nacos.image yes nacos-server Mirror image , Bloggers use M1 Chip MacBook, Therefore, using zhusaidong/nacos-server-m1:2.0.3, be based on x86 Our readers can choose .
pcs-nacos And pcs-nacos-mysql It's my custom Container Name, Readers are free to modify .
version: '3'
services:
nacos:
image: zhusaidong/nacos-server-m1:2.0.3
container_name: pcs-nacos
environment:
- MODE=standalone
ports:
- "8848:8848"
depends_on:
- mysql
mysql:
image: mysql:oracle
container_name: pcs-nacos-mysql
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
3、 ... and 、 stay MySQL In the container , establish Nacos Officially given databases and data tables
Visit website https://github.com/alibaba/nacos/blob/develop/distribution/conf/nacos-mysql.sql, get SQL sentence :
/* * 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. */
/******************************************/
/* Database full name = nacos_config */
/* The name of the table = config_info */
/******************************************/
CREATE TABLE `config_info` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
`data_id` varchar(255) NOT NULL COMMENT 'data_id',
`group_id` varchar(255) DEFAULT NULL,
`content` longtext NOT NULL COMMENT 'content',
`md5` varchar(32) DEFAULT NULL COMMENT 'md5',
`gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ' Creation time ',
`gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ' Modification time ',
`src_user` text COMMENT 'source user',
`src_ip` varchar(50) DEFAULT NULL COMMENT 'source ip',
`app_name` varchar(128) DEFAULT NULL,
`tenant_id` varchar(128) DEFAULT '' COMMENT ' Tenant fields ',
`c_desc` varchar(256) DEFAULT NULL,
`c_use` varchar(64) DEFAULT NULL,
`effect` varchar(64) DEFAULT NULL,
`type` varchar(64) DEFAULT NULL,
`c_schema` text,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_configinfo_datagrouptenant` (`data_id`,`group_id`,`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_info';
/******************************************/
/* Database full name = nacos_config */
/* The name of the table = config_info_aggr */
/******************************************/
CREATE TABLE `config_info_aggr` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
`data_id` varchar(255) NOT NULL COMMENT 'data_id',
`group_id` varchar(255) NOT NULL COMMENT 'group_id',
`datum_id` varchar(255) NOT NULL COMMENT 'datum_id',
`content` longtext NOT NULL COMMENT ' Content ',
`gmt_modified` datetime NOT NULL COMMENT ' Modification time ',
`app_name` varchar(128) DEFAULT NULL,
`tenant_id` varchar(128) DEFAULT '' COMMENT ' Tenant fields ',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_configinfoaggr_datagrouptenantdatum` (`data_id`,`group_id`,`tenant_id`,`datum_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT=' Add tenant field ';
/******************************************/
/* Database full name = nacos_config */
/* The name of the table = config_info_beta */
/******************************************/
CREATE TABLE `config_info_beta` (
`id` bigint(20) 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` longtext 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 ' Creation time ',
`gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ' Modification time ',
`src_user` text COMMENT 'source user',
`src_ip` varchar(50) DEFAULT NULL COMMENT 'source ip',
`tenant_id` varchar(128) DEFAULT '' COMMENT ' Tenant fields ',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_configinfobeta_datagrouptenant` (`data_id`,`group_id`,`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_info_beta';
/******************************************/
/* Database full name = nacos_config */
/* The name of the table = config_info_tag */
/******************************************/
CREATE TABLE `config_info_tag` (
`id` bigint(20) 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` longtext NOT NULL COMMENT 'content',
`md5` varchar(32) DEFAULT NULL COMMENT 'md5',
`gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ' Creation time ',
`gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ' Modification time ',
`src_user` text COMMENT 'source user',
`src_ip` varchar(50) DEFAULT NULL COMMENT 'source ip',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_configinfotag_datagrouptenanttag` (`data_id`,`group_id`,`tenant_id`,`tag_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_info_tag';
/******************************************/
/* Database full name = nacos_config */
/* The name of the table = config_tags_relation */
/******************************************/
CREATE TABLE `config_tags_relation` (
`id` bigint(20) 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(20) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`nid`),
UNIQUE KEY `uk_configtagrelation_configidtag` (`id`,`tag_name`,`tag_type`),
KEY `idx_tenant_id` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_tag_relation';
/******************************************/
/* Database full name = nacos_config */
/* The name of the table = group_capacity */
/******************************************/
CREATE TABLE `group_capacity` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT ' Primary key ID',
`group_id` varchar(128) NOT NULL DEFAULT '' COMMENT 'Group ID, The empty character indicates the entire cluster ',
`quota` int(10) unsigned NOT NULL DEFAULT '0' COMMENT ' The quota ,0 Indicates use default ',
`usage` int(10) unsigned NOT NULL DEFAULT '0' COMMENT ' Usage quantity ',
`max_size` int(10) unsigned NOT NULL DEFAULT '0' COMMENT ' Maximum size of a single configuration , The unit is byte ,0 Indicates use default ',
`max_aggr_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT ' Maximum number of aggregate sub configurations ,,0 Indicates use default ',
`max_aggr_size` int(10) unsigned NOT NULL DEFAULT '0' COMMENT ' The maximum sub configuration size of a single aggregate data , The unit is byte ,0 Indicates use default ',
`max_history_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT ' Maximum number of change history ',
`gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ' Creation time ',
`gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ' Modification time ',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_group_id` (`group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT=' colony 、 various Group Capacity information table ';
/******************************************/
/* Database full name = nacos_config */
/* The name of the table = 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) NOT NULL,
`group_id` varchar(128) NOT NULL,
`app_name` varchar(128) DEFAULT NULL COMMENT 'app_name',
`content` longtext NOT NULL,
`md5` varchar(32) DEFAULT NULL,
`gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`src_user` text,
`src_ip` varchar(50) DEFAULT NULL,
`op_type` char(10) DEFAULT NULL,
`tenant_id` varchar(128) DEFAULT '' COMMENT ' Tenant fields ',
PRIMARY KEY (`nid`),
KEY `idx_gmt_create` (`gmt_create`),
KEY `idx_gmt_modified` (`gmt_modified`),
KEY `idx_did` (`data_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT=' Multi tenant transformation ';
/******************************************/
/* Database full name = nacos_config */
/* The name of the table = tenant_capacity */
/******************************************/
CREATE TABLE `tenant_capacity` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT ' Primary key ID',
`tenant_id` varchar(128) NOT NULL DEFAULT '' COMMENT 'Tenant ID',
`quota` int(10) unsigned NOT NULL DEFAULT '0' COMMENT ' The quota ,0 Indicates use default ',
`usage` int(10) unsigned NOT NULL DEFAULT '0' COMMENT ' Usage quantity ',
`max_size` int(10) unsigned NOT NULL DEFAULT '0' COMMENT ' Maximum size of a single configuration , The unit is byte ,0 Indicates use default ',
`max_aggr_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT ' Maximum number of aggregate sub configurations ',
`max_aggr_size` int(10) unsigned NOT NULL DEFAULT '0' COMMENT ' The maximum sub configuration size of a single aggregate data , The unit is byte ,0 Indicates use default ',
`max_history_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT ' Maximum number of change history ',
`gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ' Creation time ',
`gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ' Modification time ',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_tenant_id` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT=' Tenant capacity information table ';
CREATE TABLE `tenant_info` (
`id` bigint(20) 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(20) NOT NULL COMMENT ' Creation time ',
`gmt_modified` bigint(20) NOT NULL COMMENT ' Modification time ',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_tenant_info_kptenantid` (`kp`,`tenant_id`),
KEY `idx_tenant_id` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='tenant_info';
CREATE TABLE `users` (
`username` varchar(50) NOT NULL PRIMARY KEY,
`password` varchar(500) NOT NULL,
`enabled` boolean NOT NULL
);
CREATE TABLE `roles` (
`username` varchar(50) NOT NULL,
`role` varchar(50) NOT NULL,
UNIQUE INDEX `idx_user_role` (`username` ASC, `role` ASC) USING BTREE
);
CREATE TABLE `permissions` (
`role` varchar(50) NOT NULL,
`resource` varchar(255) NOT NULL,
`action` varchar(8) NOT NULL,
UNIQUE INDEX `uk_role_permission` (`role`,`resource`,`action`) USING BTREE
);
INSERT INTO users (username, password, enabled) VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', TRUE);
INSERT INTO roles (username, role) VALUES ('nacos', 'ROLE_ADMIN');
stay MySQL In the container , Create a database (database/schema), Select database (use command ), Execute the above SQL sentence .
Four 、 stay Nacos Server In a container MySQL Persistent configuration
# Enter the first Nacos Server Containers , edit nacos Under folder conf Under folder application.properties file , And make the following modifications
spring.datasource.platform=mysql
# pcs-nacos-mysql yes Docker Compose The name specified in the file
db.url.0=jdbc:mysql://pcs-nacos-mysql:3306/nacos_mysql
# Comment out db.url.1
db.user=root
db.password=123456
5、 ... and 、 restart Nacos
restart Nacos Service to apply 「 Step four 」 Changes in .
6、 ... and 、 visit Nacos page
visit localhost:8848/nacos/ Log in to the website ( my Nacos Server The port that the container maps to the local machine is 8848):
- Initial username :nacos
- Initial password :nacos
attach : Based on the original Docker build Nacos 2(MySQL)
Reference blog :https://blog.csdn.net/m0_46261993/article/details/120325029?spm=1001.2014.3001.5501
边栏推荐
- Section 6 - pointers
- Simple-SR:Best-Buddy GANs for Highly Detailed Image Super-Resolution論文淺析
- C language learning log 12.14
- QT direction key to move focus
- priority inversion problem
- List collection concurrent modification exception
- Modification and analysis of libcoap source code by Hongmeng device discovery module
- Clause 31: avoid default capture mode
- COAP protocol libcoap API
- Clause 34: lambda is preferred over std:: bind
猜你喜欢

Configuration used by automatic teaching evaluation script

Regular expressions in QT

Metaltc4.0 stable release

Simple sr: Best Buddy Gans for highly detailed image super resolution Paper Analysis

Sampo Lock

Listiterator list iterator

Brick story

Case - traversing the directory (file class & recursive call)

Must know must know -c language keywords

关于匿名内部类
随机推荐
Simple-SR:Best-Buddy GANs for Highly Detailed Image Super-Resolution论文浅析
About anonymous inner classes
行情绘图课程大纲1-基础知识
Chapter 13 abstraction: address space
2021tami/ image processing: exploiting deep generative priority for versatile image restoration and manipulation
OpenCV中的saturate操作(饱和操作)究竟是怎么回事
C language learning log 10.11
C language learning log 1.19
[reprint] complete collection of C language memory and character operation functions
Article 29: assuming that the mobile operation does not exist, is expensive, and is not used
关于匿名内部类
lookup
Clause 32: moving objects into closures using initialization capture objects
Simple-SR:Best-Buddy GANs for Highly Detailed Image Super-Resolution論文淺析
Clause 30: be familiar with the failure of perfect forwarding
QT client development -- driver loading problem of connecting to MySQL database
Force deduction 121 questions
C language learning log 10.19
Logical point
QT realizes message sending and file transmission between client and server