当前位置:网站首页>Nacos - Configuration Management
Nacos - Configuration Management
2022-07-01 08:40:00 【SXHENIGA】
Translation source of notes : Dark horse Nacos
https://www.bilibili.com/video/BV1VJ411X7xX?p=17&spm_id_from=333.880.my_history.page.click&vd_source=3c0d9a4d48df5bf76352d1653111b1d7
One 、 Configuration center
1、 sketch
The configuration center is generally used in microservices , When a single system is split into service nodes on a distributed system , The configuration file of the system also needs to be split . Configuration center is to separate configuration files from the system , Unified management of system configuration , And the system configuration is modified remotely , The application can also actively obtain the modified configuration content , The application itself does not need to manage the system configuration .
Simply speaking , Is to put Springboot Of yml And other configuration files are placed in remote management , from Springboot Actively seek .

2、 characteristic
1) Configuration features
| Configuration features | describe | |
| 1 | Configuration is a read-only variable independent of the program | Read the configuration to change your behavior |
| 2 | Configuration accompanies the entire life cycle of the application | Configuration runs through the entire application lifecycle |
| 3 | Configuration can be loaded in many ways | Configuration files are available 、 environment variable 、 Launch parameters 、 Database, etc |
| 4 | Configuration needs governance | Differentiate development 、 test 、 production ; Distinguish between different clusters |
2) Configure central properties
| Configure central properties | |
| 1 | Configuration items are easy to read and modify |
| 2 | Manageability of application configuration in distributed environment , That is, the ability to remotely manage configuration |
| 3 | Address the review of configuration changes to control risks |
| 4 | You can view the history of configuration changes |
| 5 | Isolation of application configuration in different deployment environments |
Two 、Nacos
1、Nacos brief introduction
Nacos Dedicated to helping you discover 、 Configure and manage microservices . It is an open source product of Alibaba , It is aimed at service discovery in micro service architecture , Configuration Management , Integrated solutions for service governance , Can help you build more quickly and easily 、 Deliver and manage microservice platforms .
2、Nacos characteristic
| Nacos characteristic | describe | |
| 1 | Service discovery and service health check | Easier to register , adopt DNS or HTTP Interface discovery service ; Health check the service in real time |
| 2 | Dynamic configuration management | Eliminates the need to redeploy applications when updating configurations , This makes configuration updates more efficient and flexible |
| 3 | dynamic DNS service | Offer based on DNS Service discovery capability of protocol , Service discovery designed to support heterogeneous languages |
| 4 | Services and metadata management | From the perspective of micro service platform , Manage all services and metadata in the data center |
3、 Configuration center comparison
| Comparison items | Spring Cloud Config | Apollo | Nacos |
| Delivery real-time push | Support (Spring Cloud Bus) | Support (HTTP Long polling 1S Inside ) | Support (HTTP Long polling 1S Inside ) |
| version management | Support (Git) | Support | Support |
| Configure rollback | Support (Git) | Support | Support |
| Grayscale Publishing | Support | Support | I won't support it |
| Rights management | Support ( rely on Git) | Support | I won't support it |
| Multi cluster | Support | Support | Support |
| Multiple environments | Support | Support | Support |
| Monitor query | Support | Support | Support |
| Multilingual | Support Java | The mainstream language ,Open API | The mainstream language ,Open API |
| Configuration format verification | I won't support it | Support | Support |
| Stand alone reading (QPS) | 7( Due to current restriction ) | 9000 | 15000 |
| Write alone (QPS) | 5( Due to current restriction ) | 1100 | 1800 |
| 3 Node reading (QPS) | 21( Due to current restriction ) | 27000 | 45000 |
| 3 Node write (QPS) | 5( Due to current restriction ) | 3300 | 5600 |
3、 ... and 、Nacos Quick start
1、 Installation package
nacos-server-1.1.4
https://www.aliyundrive.com/s/2cUubQYMSX9
2、 Start the server
![]() |
3、 Interface access
| Local address | http://127.0.0.1:8848/nacos/index.html |
| Account and password | account number :nacos password :nacos |
![]() |
4、OPEN API Configuration management test
1) use ApiPost perhaps Postman Issue configuration request
| 127.0.0.1:8848/nacos/v1/cs/configs?dataId=nacos.cfg.dataId&group=test&content=HelloWorld |
![]() |
2) Interface to view configuration
![]() |
5、Nacos Connect external Mysql Storage
In stand-alone mode ,Nacos By default, embedded database is used to store data , If you want to use external Mysql Storage Nacos data , The following steps are required :
1) mount this database
MySQL:5.6.5+,MySQL 8 following
2) Initialize database
initialization MySQL Database name , take nacos-mysql.sql Import
|
3) Modify the configuration file application.properties
spring.datasource.platform=mysql
|
Four 、Nacos Getting started with configuration
1、 Release configuration [ interface ]


2、Nacos Client get configuration [ introduction ]
1) newly build Maven project

2)pom file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dgs</groupId>
<artifactId>Nacos01</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
<version>1.1.3</version>
</dependency>
</dependencies>
</project>5、 ... and 、Nacos Configuration management model
about Nacos Configuration Management , adopt Namespace、group、Data ID Be able to locate a configuration set

config set (Data ID)
In the system , A configuration file is usually a config set , A configuration set can contain all kinds of configuration information of the system , for example , A configuration set may contain data sources 、 Thread pool 、 Log level and other configuration items . Each configuration set can define a meaningful name , It's the configuration set ID, namely Data ID.
Configuration item ( Configure the content )
One by one in the configuration set Configure the content Configuration items . It represents a specific configurable parameter and its range , Usually, the key=value There is a form of . For example, we often configure the log output level of the system (logLevel=INFO|WARN|ERROR) It's a configuration item .
Configure grouping (Group)
Configuration grouping is the grouping of configuration sets , Through a meaningful string ( Such as Buy or Trade) To express , Different configuration groups can have the same configuration set (Data ID). When you Nacos When you create a configuration on , If the name of the configuration group is not filled in , Then the name of the configuration group is used by default DEFAULT_GROUP. Common scenarios for configuring grouping : Can be used to distinguish between different projects or applications .
Namespace (Namespace)
Namespace (namespace) It can be used for configuration isolation of different environments . For example, you can isolate the development environment 、 Test environment and production environment , Because they may have different configurations , Or isolate different users , Different developers use the same Nacos Manage your own configuration , It can be passed namespace Isolation , Under different namespaces , There can be configuration groups with the same name (Group) Or configuration set .
6、 ... and 、Nacos Configuration management is applied to distributed systems
1、 Microservice architecture
Decompose the application into small 、 Interconnected microservices , It avoids developing a huge single application , It's about breaking down the application into smaller ones 、 Interconnected microservices .
A microservice generally performs a specific function , Like order service 、 User service and so on . Every microservice is a complete application , Each has its own business logic and services
2、 Distributed application configuration management

- User pass Nacos Server The console manages the configuration of multiple services .
- All services are unified from Nacos Server Get the respective configurations in the , And monitor configuration changes .
3、Nacos Integrate Springboot
1) New namespace dev


2) stay dev Namespace publishes two configurations
① Nacos1.yaml
②Nacos2.yaml
3) establish Maven The parent project



4)Maven Version of the configuration

5)Maven Parent project add pom rely on
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dgs</groupId>
<artifactId>NacosTest</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<!-- Add the subproject later ,pom There will be this in dependency
<modules>
<module>Nacos1</module>
<module>Nacos2</module>
</modules>-->
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF‐8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF‐8</project.reporting.outputEncoding>
</properties>
<dependencyManagement>
<dependencies>
<!-- spring cloud alibaba 2.1.0.RELEASE-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.1.0.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Greenwich.SR3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.1.3.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
6) New subproject Nacos1



7) Sub project Nacos1 add to pom rely on
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>NacosTest</artifactId>
<groupId>com.dgs</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>Nacos1</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>
8)Nacos1 Sub project , New configuration file

9)Nacos1 Sub project , add to Springboot Start class

10)Nacos1 Sub project , add to Controller, Get remote Nacos Profile contents

11) Start the test

12) New sub projects Nacos2, Same as Nacos1
13) New sub projects Nacos2 Configuration file for

14) New sub projects Nacos2 Start class

15)Nacos2 Sub project , add to Controller, Get remote Nacos Profile contents

16) Start the test

4、 Custom extended Data Id To configure
Spring Cloud Alibaba Nacos Config Can support customized Data Id Configuration of .
Extended by custom Data Id To configure , It can solve the problem of configuration sharing among multiple applications , It can also support multiple configuration files for one application .
spring:
application:
name: service2
cloud:
nacos:
config:
server‐addr: 127.0.0.1:8848
# config external configuration
# 1、Data Id In the default group DEFAULT_GROUP, Dynamic refresh of configuration is not supported
ext‐config[0]:
data‐id: ext‐config‐common01.properties
# 2、Data Id Not in the default group , Dynamic refresh is not supported
ext‐config[1]:
data‐id: ext‐config‐common02.properties
group: GLOBALE_GROUP
# 3、Data Id Neither in the default group , Also supports dynamic refresh
ext‐config[2]:
data‐id: ext‐config‐common03.properties
group: REFRESH_GROUP
refresh: true
|
- adopt spring.cloud.nacos.config.ext-config[n].data-id To support multiple Data Id Configuration of
- adopt spring.cloud.nacos.config.ext-config[n].group The configuration method of custom Daya Id Rent at , Default DEFAULT_GROUP
- adopt spring.cloud.nacos.config.ext-config[n].refresh To control the Data Id When the configuration changes , Whether it supports the dynamic refresh of Zhongke application , Sensing the latest configuration value . Not supported by default
5、 Custom sharing Data Id To configure
spring:
cloud:
nacos:
config:
shared‐dataids: ext‐config‐common01.properties,ext‐config‐common02.properties
refreshable‐dataids: ext‐config‐common01.properties
|
- adopt spring.cloud.nacos.config.shared-dataids To support multiple sharing Data Id Configuration of , Multiple are separated by commas .
- adopt spring.cloud.nacos.config.refreshable-dataids To support which shared configurations Data Id When the configuration changes , Whether the application can be refreshed dynamically , Sensing the latest configuration value , Multiple Data ID Separated by commas . If the configuration is not clear , Dynamic refresh is not supported by default
- It is the group Fixed for DEFAULT_GROUP
6、 Configure priorities
A、 Through internal rules ( Application name 、 Extension ) Automatically generate related Data Id To configure
B、 Multiple extensions Data Id
C、 Multiple shares Data Id
A>B>C
边栏推荐
- 我想知道手机注册股票开户的流程?另外,手机开户安全么?
- 动态代理
- 1. Connection between Jetson and camera
- DID的使用指南,原理
- C basic knowledge review (Part 4 of 4)
- 《单片机原理及应用》-片外拓展
- 15Mo3 German standard steel plate 15Mo3 chemical composition 15Mo3 mechanical property analysis of Wuyang Steel Works
- 基础:3.opencv快速入门图像和视频
- 《单片机原理及应用》—定时器、串行通信和中断系统
- 电脑小技巧
猜你喜欢

你了解数据是如何存储的吗?(C整型和浮点型两类)

C basic knowledge review (Part 4 of 4)

What is the material of 15CrMoR, mechanical properties and chemical analysis of 15CrMoR

Maneuvering target tracking -- current statistical model (CS model) extended Kalman filter / unscented Kalman filter matlab implementation

AVL树的理解和实现

3、Modbus通讯协议详解

Internet of things technology is widely used to promote intelligent water automation management

factory type_ Id:: create process resolution

Burpsuite -- brute force cracking of intruder

一文纵览主流 NFT 市场平台版税、服务费设计
随机推荐
Yolov5 advanced six target tracking environment construction
Yolov3, 4, 5 and 6 Summary of target detection
It is designed with high bandwidth, which is almost processed into an open circuit?
1. Connection between Jetson and camera
MD文档中插入数学公式,Typora中插入数学公式
Advanced C language pointer (Part 2)
Screenshot tips
The use of word in graduation thesis
挖财打新股安全吗
TypeError: __ init__ () got an unexpected keyword argument ‘autocompletion‘
TypeError: __init__() got an unexpected keyword argument ‘autocompletion‘
Centos7 shell脚本一键安装jdk、mongo、kafka、ftp、postgresql、postgis、pgrouting
Matlab [function derivation]
用C语言编程:用公式计算:e≈1+1/1!+1/2! …+1/n!,精度为10-6
How to recruit Taobao anchor suitable for your own store
Leetcode t39: combined sum
MATLAB小技巧(16)矩阵特征向量特征值求解一致性验证--层次分析
factory type_id::create过程解析
Intelligent water and fertilizer integrated control system
爬虫知识点总结






