Nacos cluster configuration, NacosRule load balancing, weight setting, namespace

When we have more and more services and more and more service instances (for example, userservice, there are three instances of ports 8081, 8082, and 8083), it is not safe for us to deploy all services in the same computer room. , just like putting eggs in one basket; it is very unsafe and unfriendly, so we need to deploy the computer room and server separately;

A service can be deployed in multiple clusters, a server can deploy multiple services (but this is generally not done, generally a server only deploys one service instance), a cluster can have multiple instances; then how do we configure the
insert image description herecluster Woolen cloth?
insert image description here
Before starting the service, configure the cluster properties, and then start:
For example:
configure the cluster HZ (Hangzhou) for userservice, and start two userservice instances: 8081 and 8082. At this time, these two instances are deployed on the HZ cluster. At this time,
insert image description here
insert image description here
then Modify the cluster name, start a userservice3, and this instance is deployed on the SH (Shanghai) cluster.
insert image description here
You can see the deployed service instance in Nacos:
insert image description here
Click "Details": you can see the cluster and the deployed instance
insert image description here
. Summary:
insert image description here

NacosRule load balancing

Above, we configured userservice1 (service provider) and userservice2 (service provider) in the HZ (Hangzhou) cluster, and userservice3 (service provider) in the SH (Shanghai) cluster.
Operation: Deploy the orderservice (service consumer) in the HZ cluster:
insert image description here

At this time, our orderservice (service consumer) is also configured to the HZ cluster, and when calling userservice (service provider), the default polling algorithm will still be used; regardless of the cluster (userservice1, 2, and 3 will be polled and called) ;

This is very unwise, because in reality, when our service orderservice (service consumer) in Hangzhou wants to call the remote service userservice13 in Shanghai, it will definitely be slower than userservice1 and 2 in the same cluster, which increases the time Loss

So how do we set up orderservice (service consumer) to set default access to services on the same cluster as ourselves?
This leads to our NacosRule load balancing:
After configuring NacosRule load balancing, service providers in the same cluster will be accessed preferentially
insert image description here
insert image description here

Note: After configuring NacosRule, please replace, comment or delete the original Ribbon load balancing configuration, otherwise the Nacos load balancing configuration will not take effect

After the orderservice (service consumer) configures NacosRule load balancing, it will automatically call the services in the same cluster as itself, that is, userservice1 and 2, and will not call userservice3 of the remote cluster

When orderservice (service consumer) calls multiple userservice service instances of the same cluster, it willrandomAccess service instances; that is to say, userservice1 and 2 here will be randomly accessed by orderservice, and 3 will not be accessed preferentially because they are not in the same cluster.

Then if at this time, the userservice1 and 2 services of the same cluster are down, and when orderservice is called, when there is no service adjustable in this cluster, will orderservice call userservice3 of a different cluster?
meeting! But there will be a warning: the HZ cluster was originally accessed, but at this time there was a cross-cluster access, and the userservice3 of the SH cluster was accessed
insert image description here
Summary:
insert image description here

Weight setting of Nacos service instance

Instance weight control:
1. The Nacos console can set the weight value of the instance, between 0 and 1.
2. For multiple instances in the same cluster, the higher the weight, the higher the frequency of access.
3. If the weight is set to 0, it will not be used at all. will be visited

On the Nacos service page, you can set the weight of each instance.
insert image description here
An application of Nacos weight setting:
Scenes: If the current company wants to upgrade a service (assuming there are multiple clusters)
before: The previous method is to wait until the dead of night and when the number of users is the least, stop the service and restart it; the
disadvantage is: there are always users online, stop the service, and the user experience is extremely poor
Use Nacos weights: Set the weight of one of the service instances to 0, gradually no requests will be sent to this service, then stop this service instance, restart and update; at this time, other services are running normally, but the pressure is slightly greater; then wait After the service is updated, other instances will be updated sequentially in the same way.
The advantage is that users will not feel that the service has been updated, and there is no need to wait for the update when there are fewer users, so as to avoid working overtime late at night.

namespace

As a service registration center, Nacos is also
a configuration file in the configuration center Nacos, which is isolated from large to small: namespace, group, service/Data, services of different namespaces cannot access each other
insert image description here

insert image description here
If the above namespace id is not filled, it will be automatically generated:
insert image description here
After setting the namespace, set which namespace to use in the project configuration file, you need to set the namespace id:
insert image description here

Guess you like

Origin blog.csdn.net/dayuiicghaid/article/details/126045124