Nacos (eight): Nacos persistence

Reference and thanks

Spring Cloud Alibaba Basic Tutorial: Nacos Data Persistence

Foreword

Prospects Review:

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 Mysqldatabase, 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\confdirectory, initialization files:nacos-mysql.sql

Here I create a file called mynacosdatabase, and then perform the initialization script, after the success will generate 11tables

Initialize the database

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\confdirectory 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\binunder the startup.cmdfile

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

Nchos-Chonsloa

Verify that persisted to the database

Observation database mynacosin database tables config_info, the following

config_info
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.



Guess you like

Origin www.cnblogs.com/larscheng/p/11422909.html