当前位置:网站首页>Nacos 配置中心
Nacos 配置中心
2022-08-01 20:38:00 【何以解忧,唯有..】
一、配置中心介绍
配置中心可以实现配置更新时无需重新部署应用程序,即可使相应的配置信息生效,可以在所有环境中以集中和动态的方式管理所有应用程序的配置信息,极大的增强了系统的运维能力。
目前分布式配置中心主要有:Nacos、Apollo、Disconf等
二、原理

客户端通过一个长轮询定时任务来检查配置项的数据,当服务端配置发生变更时,客户端将会获取最新的数据进行回调处理。
三、Nacos 配置关键概念说明
环境隔离-命名空间Namespace:
命名空间:区分部署环境,并发、测试、灰度、生产,不同的空间时隔离的。
Nacos 引入命名空间 Namespace 的概念来进行多环境配置和服务的管理及隔离。例如,你可能存在本地开发环境dev、测试环境test、生产环境prod 三个不同的环境,那么可以创建三个不同的 Namespace 区分不同的环境。创建方式如下:

Group:区分业务项目,如 电商项目、OA项目
DataId:Data ID 是配置集的唯一标识,一个应用可以包含多个配置集,每个配置集都需要被一个有意义的名称标识。那么 Data ID 怎么取值呢?格式通俗一点就是 “前缀-环境-扩展名”,如下所示:
DataId的组成规则:
s p r i n g . c l o u d . n a c o s . c o n f i g . p r e f i x − {spring.cloud.nacos.config.prefix}- spring.cloud.nacos.config.prefix−{spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
① prefix:前缀,默认是 spring.application.name 的值,也可以通过配置项 spring.cloud.nacos.config.prefix 来配置。
# 若不指定,默认采用应用名的方案
spring.application.name=cloud-producer-server
# 手动指定配置的dataID前缀标识
# spring.cloud.nacos.config.prefix=cloud-producer-server-config
② active:配置运行环境,即为当前环境对应的 profile。
注意:当 spring.profiles.active 为空时,对应的连接符 ”-“ 也将不存在,dataId 的拼接格式变成 p r e f i x . {prefix}. prefix.{file-extension}
# dev表示开发环境
spring.profiles.active=dev
③ file-exetension:配置文件的类型,默认是 properties,也可以通过配置项 spring.cloud.nacos.config.file-extension 来配置,目前支持的类型有 TEXT、JSON、XML、YAML、HTML、Properties
# 指定配置文件类型为yaml文件
spring.cloud.nacos.config.file-extension=yaml
④ 最终配置:
经过前面三个步骤,我们最终在nacos配置中心的控制台新增配置文件就是:cloud-producer-server-dev.yaml
边栏推荐
- Godaddy domain name resolution is slow and how to use DNSPod resolution to solve it
- 9月备考PMP,应该从哪里备考?
- Where should I prepare for the PMP exam in September?
- [Multi-task learning] Modeling Task Relationships in Multi-task Learning with Multi-gate Mixture-of-Experts KDD18
- WhatsApp group sending actual combat sharing - WhatsApp Business API account
- Remove 360's detection and modification of the default browser
- Batch get protein .pdb files based on Uniprot ID/PDB ID
- 【ES】ES2021 我学不动了,这次只学 3 个。
- 洛谷 P2440 木材加工
- 任务调度线程池基本介绍
猜你喜欢

Buttons with good user experience should not have hover state on mobile phones

【节能学院】推进农业水价综合改革的意见解读

【Untitled】

【节能学院】安科瑞餐饮油烟监测云平台助力大气污染攻坚战

小数据如何学习?吉大最新《小数据学习》综述,26页pdf涵盖269页文献阐述小数据学习理论、方法与应用

【Untitled】

实用新型专利和发明专利的区别?秒懂!

Remove 360's detection and modification of the default browser

扣减库存方案

进行交互或动画时如何选择Visibility, Display, and Opacity
随机推荐
"No title"
基于FPGA的任意字节数(单字节、多字节)的串口(UART)发送(含源码工程)
tiup mirror merge
专利检索常用的网站有哪些?
tiup mirror
使用Huggingface在矩池云快速加载预训练模型和数据集
"Torch" tensor multiplication: matmul, einsum
【多任务模型】Progressive Layered Extraction: A Novel Multi-Task Learning Model for Personalized(RecSys‘20)
【无标题】
What is the difference between a utility model patent and an invention patent?Understand in seconds!
STAHL触摸屏维修一体机显示屏ET-316-TX-TFT常见故障
Remove 360's detection and modification of the default browser
MongoDB快速上手
有用的网站
多线程之生产者与消费者
[Personal Work] Remember - Serial Logging Tool
如何用Chrome编辑以及调试代码
tiup mirror init
Qt设置应用程序开机自启 解决设置失败原因
WhatsApp group sending actual combat sharing - WhatsApp Business API account