当前位置:网站首页>Nacos注册中心
Nacos注册中心
2022-06-10 16:36:00 【itmkyuan】
● 认识和安装Nacos
● Nacos快速入门
● Nacos服务分级存储模型
● Nacos环境隔离
认识Nacos
Nacos是阿里巴巴的产品,现在是SpringCloud的一个组件。相比Eureka功能更加丰富,在国内受欢迎程度较高。
nacos服务分级存储模型
服务跨集群调用问题
服务调用尽可能选择本地集群的服务,跨集群调用延迟较高
本地集群不可访问时,再去访问其他集群
服务集群属性
1.修改application.yml属性,添加如下内容
spring:
cloud:
nacos:
server-addr: localhost:8001 #nacos的服务地址
discovery:
cluster-name: SH #集群名称 这里SH代指上海
2.在nacos控制台可以看到集群变化:
总结
1.Nacos服务分级存储模型
① 一级是服务,例如userservice
② 二级是集群,例如杭州和上海
③ 三级是实例,例如杭州机房的某台部署了userservice的服务区
2.如何设置实例的集群属性
① 修改application.yml文件,添加spring.cloud.nacos.discovery.cluster-name属性即可
根据集群负载均衡
1.修改order-service中的application.yml,设置集群为HZ:
spring:
cloud:
nacos:
server-addr: localhost:8001 #nacos的服务地址
discovery:
cluster-name: HZ #集群名称 这里HZ代指杭州
2.然后在order-service中设置负载均衡的IRule为NacosRule,这个规则优先会寻找与自己同集群的服务:
userservice: #要做配置的微服务名称
ribbon:
NFLoadBalancerRuleClassName: com.alibaba.cloud.nacos.ribbon.NacosRule #负载均衡规则
3.注意将user-service的权重都设置为1。
NacosRule负载均衡策略
① 优先选择同集群服务列表
② 本地集群找不到提供者,才去其他集群寻找,并且会报警告
③ 确定了可用实例列表后,再采用随机负载均衡挑选实例
根据权重负载均衡
实际部署中会出现这样的场景:
- 服务器设备性能有差异,部分实例所在机器性能较好,另一些较差,我们希望性能好的机器承担更多的用户请求
- nacos提供了权重配置来控制访问频率,权重越大则访问频率越高
1.在nacos控制台可以设置实例的权重值,首先选中实例后面的编辑按钮
2.将权重值设置为0.1,测试可以发现8082被访问的频率大大降低
实例的权重控制
① nacos可以设置实例的权重值,0~1之间
② 同集群的多个实例权重越高被访问的频率越高
③ 权重设置为0则完全不会被访问
环境隔离-namespace
Nacos中服务存储和数据存储的最外层都是一个名为namespace的东西,用来做最外层的隔离
1.在Nacos控制台可以创建namespace,用来隔离不同环境
2.然后填写一个新的命名空间信息
3.保存后会在控制台看到这个命名空间的id:
4.修改oder-service的application.yml,添加namespace:
spring:
cloud:
nacos:
server-addr: localhost:8001 #nacos服务地址
discovery:
cluster-name: HZ #集群名称
namespace: c072b17e-a5a6-4c23-aff3-aa83749eefa0 #命名空间 填id
5.重启order-service后,再来查看控制台

6.此时访问order-service,因为namespace不同,会导致找不到userservice控制台会报错:
Nacos环境隔离
① namespace用来做环境隔离
② 每个namespace都有唯一id
③ 不同namespace下的服务不可见
Nacos和Eureka对比
nacos注册中心细节分析
临时实例和非临时实例
服务注册到nacos时,可以选择为注册为临时实例或临时实例,通过下面的配置来设置:
spring:
cloud:
nacos:
server-addr: localhost:8001 #nacos服务地址
discovery:
ephemeral: false #是否是临时实例
Nacos和eureka共同点
① 都支持服务注册和服务拉取
② 都支持服务提供者心跳方式做健康检测
Nacos和eureka区别
① Nacos支持服务端主动监测服务提供者状态:临时实例采用心跳模式,非临时实例采用主动检测模式
② 临时实例心跳不正常会被踢出,非临时实例则不会被踢出
③ Nacos主持服务列表变更的消息推送模式,服务列表更新更及时
④ Nacos集群默认采用AP方式,当集群中存在非临时实例时,采用CP模式;Eureka采用AP模式
感谢参与:
视频地址:https://www.bilibili.com/video/BV1LQ4y127n4?p=17
边栏推荐
- Swift 3pThread tool Promise Pipeline Master/Slave Serial Thread confinement Serial queue
- Brands are difficult to establish, IPO is difficult, and Chinese tea enterprises are trapped in "tradition"?
- SOA architecture / test phase interface description language transformation scheme
- Accuracy of alphafold and NMR determination of protein structure in solution
- “挽弓当挽强,用箭当用长”,曼孚科技为数据服务行业开启新赛道
- 2022年G2电站锅炉司炉考试模拟100题及模拟考试
- Under the "plastic ban order", does the Hong Kong stock exchange pay for the deep excavation of degradable plastics by Zhongbao new materials?
- Attributes of script tag
- 当v-if和v-for需要同时使用的时候
- 【抬杠C#】如何实现接口的base调用
猜你喜欢
Redis operation set, Zset, hash data types and use of visualization tools

“挽弓当挽强,用箭当用长”,曼孚科技为数据服务行业开启新赛道

亟需丰富智能家居产品线,扫地机器人赛道上挤得下萤石吗?

Numpy learning notes

vscode常用快捷键

MFC basic knowledge and course design ideas

Hidden Markov model and its training (1)

元宇宙的定义和 7 大无限特征

Online communication skill network: a sparse model for solving multi task and multi-modal problems (Qingyuan talk, issue 19, tangduyu)

Solve the problem that idea is stuck in opening a project
随机推荐
目标客户匹配数据表格成功案例展示
What is the highest compound interest insurance product? How much does it cost a year?
Fabric.js 元素被选中时保持原有层级
Numpy learning notes
元宇宙的定义和 7 大无限特征
Redis operation set, Zset, hash data types and use of visualization tools
What are the differences between domain name filing and ICP filing?
华为matepad能成为你的笔记本电脑副屏?
Designing drugs with code: are we here yet?
SOA architecture / test phase interface description language transformation scheme
为 Chocolatey 设置代理
路由器实验之serial接口的静态路由配置(补充)
“挽弓当挽强,用箭当用长”,曼孚科技为数据服务行业开启新赛道
adb不是内部或外部命令,也不是可运行的程序或批处理文件
Online communication skill network: a sparse model for solving multi task and multi-modal problems (Qingyuan talk, issue 19, tangduyu)
基于DeepFace模型设计的人脸识别软件
Detailed derivation of perspective projection transformation and related applications
【报表工具的第二次革命】基于SPL语言优化报表结构、提升报表运算性能
使用KuboardSpray安装kubernetes(v1.23.1)
当v-if和v-for需要同时使用的时候