当前位置:网站首页>Nacos cluster partition
Nacos cluster partition
2022-07-30 03:33:00 【Leon_Jinhai_Sun】
In fact, the concept of cluster partitioning also appeared in previous Eureka, such as:
eureka:client:fetch-registry: falseregister-with-eureka: falseservice-url:defaultZone: http://localhost:8888/eureka# What is this defaultZone, why use this name?Why use this form to declare the registry?In a distributed application, instances of the same service may be started on different machines and locations. For example, our user management service may have one server deployed in Chengdu and one server in Chongqing.At this time, we have started the borrowing service on the server in Chengdu. If our borrowing service wants to call the user service now, we should give priority to the user service in the same area to call, which will make the response faster.
Therefore, we can partition the services deployed in different computer rooms, and we can see that the partition of the instance is the default:
We can modify it directly in the configuration file:
spring:application:name: borrowservicecloud:nacos:discovery:server-addr: localhost:8848# Modify to the cluster in Chongqing areacluster-name: ChongqingOf course, since we are using different startup configurations here, it is also possible to add the environment variable spring.cloud.nacos.discovery.cluster-name directly to the startup configuration, hereWe allocate one area for both user service and book service, and the borrowing service is configured as the Chengdu area:
After the modification is completed, let's try to restart it (Nacos will also restart) and observe the cluster distribution in Nacos:

You can see that there are now two clusters and one instance is running.We then called the borrowing service, but found that the call was not prioritized according to the region, and the load balancing call in the round-robin mode was still used.
We must provide Nacos's load balancing implementation to enable the region-priority invocation mechanism, just modify it in the configuration file:
spring:application:name: borrowservicecloud:nacos:discovery:server-addr: localhost:8848cluster-name: Chengdu# Enable nacos support of loadbalancer and integrate Nacos load balancingloadbalancer:nacos:enabled: trueNow we restart the borrowing service, and we will find that users and book services in the same region are called first. Now we can offline the service in Chengdu:

You can see that after going offline, since there is no service available in this area, the borrowing service will call the user service in the Chongqing area.
In addition to calling according to the priority of the region, the instance in the same region can also set the weight separately. Nacos will give priority to the instance with the larger weight to call. We can configure it directly on the management page:

Or configure it in the configuration file:
spring:application:name: borrowservicecloud:nacos:discovery:server-addr: localhost:8848cluster-name: Chengdu# The size of the weight, the greater the priority, the default is 1weight: 0.5By configuring weights, some less-performing machines can be used less, and more of those instances on better-performing hosts are used.
边栏推荐
- Sentinel 流量防卫兵
- Starlight does not ask passers-by!The young lady on the Wuhan campus successfully switched to software testing in three months and received a salary of 9k+13!
- Rpc 和 gRpc 简介汇总
- JUC(四):简记线程的五/六种状态
- [C Supplement] Conversion of Integer to String
- 使命、愿景、价值观到底有什么区别
- NLP Natural Language Processing (1)
- WPF引入 ttf 图标文件使用记录
- 联邦学习综述(一)——联邦学习的背景、定义及价值
- 【SQL】按某个关联列用一张表的数据更新另一张表
猜你喜欢
随机推荐
软件测试面试题及答案解析,2022最强版
MySQ死锁
QT based on the third day (3) widget, dialog and mainwindow
【无标题】
The most important transport layer
JUC(八):synchronized小练习
Excuse me, when datax is synchronized to the oceanbase database, it is written according to the primary key update method. How to fill in the content in the drop-down box?
web初识
三年经验只会点点点(功能测试),辞职后你可能连工作都找不到了。
26 basic models in 6 categories that operators must master
对“不可能三角”发起挑战的公链们
Hystrix 服务熔断
Stimulsoft ReportsJS and DashboardsJS. 2022.3.3
发给你的好友,让 TA 请你吃炸鸡!
List获取差集产生的问题
开放地址法哈希实现——二次探测法
Drools(7):WorkBench
小程序毕设作品之微信二手交易小程序毕业设计成品(5)任务书
[C Supplement] Conversion of Integer to String
Gateway routing gateway








