Nacos introduction, download and configuration persistence to Mysql

scene

What is Nacos

Nacos is dedicated to helping you discover, configure, and manage microservices. Nacos provides a set of easy-to-use feature sets to help you quickly realize dynamic service delivery
Service configuration, service metadata and flow management.
Nacos helps you build, deliver, and manage microservice platforms more quickly and easily. Nacos is to build a modern application architecture centered on "service" (for example)
Such as micro service paradigm and cloud native paradigm).

Nacos panorama

 

Blog:
https://blog.csdn.net/badao_liumang_qizhi
Official account
Domineering procedural ape
Get programming related e-books, tutorial push and free download.

realization

Nacos official documents:

https://nacos.io/zh-cn/docs/quick-start.html

Nacos download address:

https://github.com/alibaba/nacos/releases

Select the specified stable version to download. This is Windows, so select the zip package to download

 

When the download is completed, extract it to a directory on the disk

Nacos persistence

To prevent data loss after Nacos downtime or restart, Nacos supports unified persistence of data to Mysql database (when Nacos persistence to Mysql is not configured,

By default, Nacos has built-in an embedded database derby, which saves some data to the built-in database (multiple built-in databases will appear for multiple Nacos).

Connect to the Mysql database for Nacos persistence and create a new database nacos_config

Why is it called nacos_config? This is because the extracted database is in the nacos-mysql.sql file in the conf directory of Nacos

 

The default database name is nacos_config

 

After creating a new database, execute the above nacos-mysql.sql file in the database to initialize the database.

Then go back to the application.properties in the conf directory under the Nacos decompression directory

 

Remove the comments from the above code to open persistent Mysql, and change the url, user name and password of the connected database to your own.

   
  1. ### If use MySQL as datasource:
  2. spring.datasource.platform=mysql
  3. ### Count of DB:
  4. db.num= 1
  5. ### Connect URL of DB:
  6. db.url. 0= jdbc: mysql:/ /127.0.0.1:3306/nacos_config?characterEncoding=utf8&connectTimeout= 1000&socketTimeout= 3000&autoReconnect= true&useUnicode= true&useSSL= false&serverTimezone=UTC
  7. db.user=root
  8. db.password= 123456

Start Nacos

Then go back to the bin directory after extracting the directory above

 

The startup.cmd and shtudown.cmd here are the startup and shutdown commands under Windows, but an error will be reported if you double-click them directly.

This is because Nacos does not configure the cluster mode, but uses the stand-alone mode, so edit startup.cmd,

Change the MODE to standalone

 

The default MODE value is "cluster"

Therefore, when following the logic below, we will follow the logic of cluster mode

   
  1. if %MODE% == "standalone" (
  2.     echo "nacos is starting with standalone"
  3.    set "NACOS_OPTS=-Dnacos.standalone=true"
  4.     set "NACOS_JVM_OPTS=-Xms512m -Xmx512m -Xmn256m"
  5. )
  6. rem if nacos startup mode is cluster
  7. if %MODE% == "cluster" (
  8.     echo "nacos is starting with cluster"
  9.    if %EMBEDDED_STORAGE% == "embedded" (
  10.        set "NACOS_OPTS=-DembeddedStorage=true"
  11.    )
  12.     set "NACOS_JVM_OPTS=-server -Xms2g -Xmx2g -Xmn1g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m -XX:-OmitStackTraceInFastThrow -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=%BASE_DIR%\logs\java_heapdump.hprof -XX:-UseLargePages"
  13. )

After editing, double-click startup.cmd

 

Then open the browser to access

http://localhost:8848/nacos/

 

The default user name and password are all nacos

After successful login

 

 

Keywords: Java Database MySQL

Added by scnov on Sun, 05 Dec 2021 12:59:45 +0200