当前位置:网站首页>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.
边栏推荐
- C# 一周入门之《C#-类和对象》Day Six
- WPF 学习笔记《WPF布局基础》
- Overview of Federated Learning (2) - Classification, Framework and Future Research Directions of Federated Learning
- 测试人员,除了测试还得会点什么
- Gateway routing gateway
- 计划处理链的很多种情况
- MyCat中对分库分表、ER表、全局表、分片规则、全局序列等的实现与基本使用操作
- Stimulsoft ReportsJS and DashboardsJS. 2022.3.3
- HCIP实验(05)OSPF综合实验
- Process priority nice
猜你喜欢

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!

Hystrix service circuit breaker

SQL 入门之第一讲——MySQL 8.0.29安装教程(windows 64位)

开放地址法哈希实现——线性探测法

Open address method hash implementation - secondary detection method

Stimulsoft ReportsJS and DashboardsJS. 2022.3.3

Gateway 路由网关

记录NLP各种资源网址

小程序毕设作品之微信二手交易小程序毕业设计成品(4)开题报告

WPF引入 ttf 图标文件使用记录
随机推荐
发给你的好友,让 TA 请你吃炸鸡!
LeetCode 114. 二叉树展开为链表(一题三吃)
un7.29: How to install and configure redis in Linux-centos?
JUC(八):synchronized小练习
HCIP OSPF
JUC(六):synchronized
小程序毕设作品之微信二手交易小程序毕业设计成品(4)开题报告
EasyCVR启动时报错“no such file or directory”,该如何解决?
Ansible introduction (detailed) features + advantages + design concept + application field + system architecture + working principle + task execution process
联邦学习综述(二)——联邦学习的分类、框架及未来研究方向
Organizations Going Online: A New Trend in Organizational Digital Transformation
QT based on the third day (3) widget, dialog and mainwindow
web初识
VMware disk expansion record
phpoffice 编辑excel文档
Gateway 路由网关
JUC (six): synchronized
护网行动基本介绍
HCIP实验(05)OSPF综合实验
HCIP experiment (05) OSPF comprehensive experiment