Reference and thanks
Spring Cloud Alibaba Basic Tutorial: Nacos Data Persistence
Foreword
Prospects Review:
- Nacos (seven): Nacos share configuration
- Nacos (f): Multiple Environments how to "manage" and "isolation" configuration and service
- Nacos (V): in multiple environments how to "read" the environment of the corresponding configuration Nacos
- Nacos (four): SpringCloud project as a configuration access center Nacos
Previous seven articles from Nacos introduced to Nacos do registry, do the configuration center, there has been no mention persistent problem.
Information about our services, information on the configuration of which are placed?
When we use the default configuration starts Nacos, all configuration files are saved Nacos in the built-in database.
Prior to version 0.7, when using the stand-alone mode nacos embedded database for data storage, and convenient to observe the basic situation of data storage. Version 0.7 adds support for mysql data source capabilities
If you use an embedded database, destined to be the upper limit of storage, it will take you out of Nacos data for persistence
My environment
- Windows10
- JDK8
- SpringCloud:Finchley.RELEASE
- SpringBoot:2.0.4.RELEASE
- spring-cloud-alibaba-dependencies:0.2.2.RELEASE
- Nacos-server:1.0.1
Demo of this project continue to be used before the polymerization engineering article Nacos
, before the junior partner if not the environment, to be the source address download
This article is the presentation environment: windows platform
Project Preparation
As used herein, Nacos (iv) project code as a demonstration
Project content without modification
Install Database
Nacos currently only supports Mysql
database, and Version:5.6.5+
Initialize the database
Nacos database script files when there is in our archive download Nacos-server in
Enter the nacos-server-1.0.1\nacos\conf
directory, initialization files:nacos-mysql.sql
Here I create a file called mynacos
database, and then perform the initialization script, after the success will generate 11
tables
Modify the configuration file
Here is the need to modify the Nacos-server configuration file
Nacos-server is actually a Java project or a project Springboot, his profile in the nacos-server-1.0.1\nacos\conf
directory named application.properties
, add a data source configuration at the bottom of the file:
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://127.0.0.1:3306/mynacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=root
db.password=123456
Start Nacos-server and Nacos-config
First start Nacos-server, start the same way, simply double-click to perform nacos-server-1.0.1\nacos\bin
under the startup.cmd
file
After a successful start into the Nacos console, this time Nacos console a new look, before the data are gone
Because adding a new data source, Nacos mysql read from all of the configuration files, and we just initialize the database is clean, naturally will not have any data and information display.
New public spaces (public) a profile DataID: nacos-config.yml
, arranged as follows:
server:
port: 9989
nacos:
config: 配置文件已持久化到数据库中...
Restart Nacos (four) Demo project. After the service starts successfully, the following observation Nacos console
Verify that persisted to the database
Observation database mynacos
in database tables config_info
, the following
Request that the joints http://127.0.0.1:9989/getValue returns the result:
Profile has persisted to the database ...
to sum up
Nacos through centralized storage to ensure data persistence, but also laid the foundation for the deployment of cluster Nacos
Imagine if we start Nacos to the previous way, if you want to set up Nacos cluster, each node in the data that uniqueness is the biggest problem
Nacos uses a single data source, directly address the consistency of distributed and clustered deployments.
- Author of the article: LarsCheng
- Article link: This article first appeared personal blog: https://www.larscheng.com/nacos-namespace/
- Publishing: OpenWrite most understand your technology from media management platform
- Disclaimer: This blog All articles unless otherwise specified, are used CC BY-NC-SA 4.0 license. Reproduced please specify from LarsCheng's Blog!