The main content of this chapter is: The reason for using Nacos configuration management and configuration management, configuration management, and how best to achieve dynamic refresh and summarize, and finally the interpretation of the principle of Nacos configuration refresh
The technology is similar to Spring Cloud Config
Significance Configuration Management
Project pain points
Different environments, different configurations
configuration properties dynamically refreshed
In order to solve the pain points commonly used scheme is introduced configure the server architecture as follows:
- The introduction of dependence
- Write Configuration (configuration greater than convention), to endeavor to comply with mappings Oh FIG.
- Create a new profile bs.yml
- In the operation panel and NACOS
- Start Content Center
2 dynamic refresh configuration
After modifying the configuration, the application can dynamically refresh configuration without the need to restart the application
- Annotations can be added @RefreshScope
Rollback Bug (Do not roll back to the original state! Nacos 1.2 will be resolved)
- https://github.com/alibaba/nacos/issues/186
https://qithub.com/alibaba/nacos/issues/434
May try to avoid using historical version, directly modify the configuration
3 shared configuration
3.1 within the same application
It is larger than the designated common
3.2 different between applications
- For example, this configuration in the user / content centers have, it can be configured to manage shared nacos
Let's look at two scenarios NACOS configure shared:
shared-detaids
ext-config
priority
shared-dataids < ext-config < 自动
4 leading context
4.1 for connecting a configuration server, the configuration read external
Our bootstrap.yml is to guide the context of the configuration file
for our application, is to connect NACOS, read NACOS configuration of
4.2 Application parent context of the Context
Remote configuration (NACOS) & local configuration priority
By default, remote configuration of high priority oh
- The following configuration file must be placed in a remote configuration takes effect
5 Data Persistence
5.1 As a service discovery component
Its data is local path exists:
~/nacos/naming/public
5.2 as a configuration server
Data is divided into two parts
NACOS web ui中添加的配置数据:
$NACOS_ HOME/data/derby-data
如果想查看其具体内容,必须停止nacos,然后连接Derby这个Apache开发的内嵌数据库,通过IDEA的数据源连接
配置属性的快照
~/nacos/config
6 搭建生产可用的Nacos集群
一次搭建即可,也不一定就你哦!
推荐阅读
搭建生产可用的Nacos集群7 NACOS配置管理最佳实践
- 能放本地,不放远程
- 尽量规避优先级
- 定规范,例如所有配置属性都要加上注释
配置管理人员尽量少(官方正在开发权限控制)