"Spring Cloud Alibaba Microservice Architecture" topic (6)-Spring Cloud Alibaba is based on the storage principle of Nacos distributed configuration center

1 Introduction

In the previous article, we implemented the nacosstorage and update of our configuration file data based on the distributed configuration center. When using some of the previous configuration centers, the configuration file data will be lost after the service restarts or the registry restarts. this happens because the data is stored in JVMthe memory of them, when running JVM is no longer available, the corresponding data will be lost, some open source frameworks by default in the data storage JVMmemory pretty much, it nacosis stored in Where is it?

2. Nacos default storage storage method

2.1. Understand the default storage of nacos

It is not difficult to find that whether you are restarting the service or restarting the nacos-serverconfiguration center, the configuration file information you previously stored will not be lost. This is because alibaba nacos-serverstores the data as a distributed configuration center in an embedded database called derby by default. In the Java application, Baidu Encyclopedia understands derby, you will know Derbywhat it is:

Derby is an ideal, open source, 100% Java-written, easy-to-manage relational database management system, which can be delivered with the characteristics of some commercial products. Apache Derby is very small, the core part derby.jar is only 2M, so it can be used as a separate database server or embedded in an application. The Content Store of Cognos 8 BI is the Derby database used by default. You can see a directory called derby 10.1.2.1 in the installation directory of Cognos 8, which is the embedded 10.1.2.1 version of derby.

In addition, in addition to the above-mentioned use of nacos as a distributed configuration center, in addition to storing the data in a derby database embedded in the Java application, nacos officially also provides storage in MySQL, in 1.2.1 and before Version, only Mysql is supported, and other relational databases are not currently supported. The official documents are as follows:

2.2. Stand-alone mode supports mysql

Before version 0.7 nacos, it was inconvenient to observe the basic situation of data storage by using embedded database to realize data storage in stand-alone mode . The 0.7 version adds the ability to support mysql data source. The specific steps are as follows:

1.安装数据库,版本要求:5.6.5+
2.初始化mysql数据库,数据库初始化文件:nacos-mysql.sql
3.修改conf/application.properties文件,增加支持mysql数据源配置(目前只支持mysql),添加mysql数据源的url、用户名和密码。

Then start in stand-alone mode nacos, nacosall the data written to the embedded database have been written mysql, and this content will be explained in the next article.

Document reference Nacos: Nacos supports three deployment modes

3. Nacos default storage method

3.1. Stored in the Derby embedded database by default

Find the datas directory under the nacos directory, you will find a derby-datafile directory, the data is stored here by default, but it cannot be visualized, but it can be seen through the IDEA tool
Insert picture description here

3.2. Use IDEA to connect to Derby to view data

Note: nacos-server must be stopped, do not start, otherwise it will not be connected

  • Download the driver to connect to Derby
  • Account and password: nacos/nacos

Insert picture description here
Insert picture description here

Insert picture description here
This is the stored nacosconfiguration file data of the distributed configuration center.

Guess you like

Origin blog.csdn.net/BruceLiu_code/article/details/113861095