Source: 02-Nacos Configuration Management - What is Configuration Center_哔哩哔哩_bilibili
Remember to download version 2.x of nacos, and you will be responsible for the "publishing error, please check whether the parameters are correct" error when you create a new configuration in the future! ! ! !
Table of contents
2.2 What is Configuration Center
3.2 Start the server (Windos mode)
3.3 OPEN API configuration management test
3.3.4 Shut down the server (windows mode)
3.3.5 External MySQL database support
1. Introduction to Nacos
Nacos is an open source product of Ali, a comprehensive solution for service discovery, configuration management, and service governance in the microservice architecture .
1.1 Four major functions:
① Service discovery and service health check
②Dynamic configuration management
③Dynamic DNS service
1.2 Comparison
From the perspective of the configuration center, in terms of performance, Nacos has the highest read and write performance, followed by Apollo . The scenario where Spring CloudConfig relies on Git is not suitable for open large-scale automated operation and maintenance APIs . In terms of functions , Apollo is the most complete. Nacos has most of the configuration management functions of Apollo , while SpringCloud Config does not have an operation and maintenance management interface and needs to be developed by itself. A major advantage of Nacos is that it integrates the registration center and configuration center functions, compared with deployment and operation
2. Configuration Center
2.1 What is configuration
2.1.1 Features
2.2 What is Configuration Center
3. Nacos Server installation
3.1 File download
3.2 Start the server (Windos mode)
The default port of Nacos is 8848, so we need to ensure that this port is not occupied by other processes.
Start command:
cmd startup.cmd
If the cmd running window flashes back after we double-click, you can refer to the article of the following person, which is really great
After entering the address and pressing Enter, the following page will appear
Default username: nacos Default password: nacos
3.3 OPEN API configuration management test
3.3.1 curl tool installation
3.3.2 Publish configuration
Look carefully, this is a POST request
curl -X POST "http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=nacos.cfg.dataId&group=test&content=HelloWorld"
Run the above command in the cmd window, if successful, the word "true" will appear
After true appears at this time, we open the Nacos page again, configuration list -> query -> the following configuration will appear, this is our configuration information
Click on the right for details
The content of the configuration will appear on the following page. The content of the configuration corresponds to the command we just ran.
Corresponds to the content after "content="
3.3.3 Get configuration
Our computer is a client, we want to get data from nacos
curl -X GET "http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=nacos.cfg.dataId&group=test"
When we released the configuration, we specified a dataId, group, content
So when we get the configuration, we need to specify the dataId and group, and then we can get the content of the content, as shown in the figure below
3.3.4 Shut down the server (windows mode)
cmd shutdown.cmd
Or a more direct way is to close the window directly
Or double-click shutdown.cmd to run the file
3.3.5 Change to external MySQL database support
As shown in the figure below, there will be some data in nacos. In stand-alone mode, nacos uses an embedded database to store data by default.
MySQL and SQL Server These databases belong to the database server
SQLite , Berkeley DB, etc. are embedded databases
The biggest difference between embedded databases and database servers is that they operate in different address spaces .
Typically, the database server runs a daemon independently, while the embedded database runs in the same process as the application.
The following is the table required by nacos
Copy the following statement into the above file
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://127.0.0.1:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=nacos_devtest
db.password=youdontknow
If the above statement does not work, we can use the following one, which has one more time zone serverTimezone=UTC than the above configuration. In addition, I also changed the database name to nacos. Both this file and the database in MySQL have been changed, because When I used the above, it kept giving me an error "com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'nacos_config'", but after I modified it, I found that there was no such problem. I don't know the reason.
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?characterEncoding=utf8&connectTimeout=1000&serverTimezone=UTC&socketTimeout=3000&autoReconnect=true
db.user=root
db.password=root
127.0.0.1:3306 Because it is on my local machine, it is 127.0.0.1, and the port number of MySQL is 3306
nacos_config indicates the database name (I later changed it to nacos)
db.user , db.password represent the user name and password of the database
restart nacos
Re-enter the webpage and find that there is no data, because there is an empty table in our database, it shows that there is no data, this is normal