当前位置:网站首页>[microservices | Nacos] Nacos realizes data isolation of multi environment and multi tenant

[microservices | Nacos] Nacos realizes data isolation of multi environment and multi tenant

2022-06-23 05:20:00 Bulst

Business background

I have three members , Zhang San 、 Li Si 、 The dog egg . The dog egg had a stomachache that day , Ask for leave 3 Months , So I decided to hand over all the new projects to Zhang San and Li Si . If they both build one locally Nacos service , Not easy to manage , So I decided to share Nacos.

Isolation plan

In the above , We have passed based on Docker+Nginx+Nacos Built a highly available cluster , And have unified high availability MySQL data source , Connect to Li , Let's take a look at how our isolation scheme works .

Namespace Isolate multi tenancy

Each tenant may have its own namespace, Each tenant's configuration data and registered service data will belong to its own namespace Next , To achieve data isolation among multi tenants .Nacos adopt Namespace To isolate services and configurations between multiple tenants , And it has good scalability .

Group Environmental groups 【 Number of projects < Number of environments 】

 Insert picture description here

Group Project grouping 【 Number of projects > Number of environments 】

 Insert picture description here

namespce

namespace Design background

namespace The design of nacos Based on this, do multi environment and multi tenant data ( Configuration and services ) Segregated . namely :

From a tenant ( user ) From the perspective of , If there are many different environments , At this time, you can create different namespce, In order to achieve multi environment isolation . for example , You may have daily , There are three different environments for pre delivery and production , Then use a set of nacos There are three different clusters namespace.

From multiple tenants ( user ) From the perspective of , Every tenant ( user ) It may have its own namespace, Every tenant ( user ) The configuration data and registered service data of will belong to their own namespace Next , To achieve data isolation among multi tenants . For example, the super administrator assigned three tenants , They are Zhang San 、 Li Si and Wang Wu . After the distribution , All tenants log in with their own account name and password , Create your own namespace .

namespace Best practices

How to get namespace Value

Whether you are based on Spring Cloud perhaps Dubbo To use nacos, It's all about namespace Parameter input of , So at this point namespace Where can I get the value of ?

If you are not aware of the input of this parameter , that nacos Unified will use a default namespace As input ,nacos naming Will use public Initialize... As a default parameter ,nacos config An empty string is used as the default parameter to initialize .

If you need to customize your own namespace, So how does this value come into being ?

Can be in nacos On the left function side of the console, there is a Namespace The function of , Click to see New namespace The button , Then you can create your own namespace at this time . Once created , Will generate a namespace ID, It is mainly used to avoid the possibility of duplicate namespace names . Therefore, when you need to configure the specified namespace when , The namespace is filled in ID. Important things are to be repeated for 3 times :

When you need to configure the specified namespace when , The namespace is filled in ID
When you need to configure the specified namespace when , The namespace is filled in ID
When you need to configure the specified namespace when , The namespace is filled in ID

explain : namesace by public yes nacos A reserved control for , If you need to create your own namespace, It's better not to talk to public The nuptial , It is named after a real business scenario with specific semantics , So as not to make it literally difficult to distinguish which one you are namespace.

namespace Parameter initialization method

nacos client Yes namespace The initialization process of is shown in the figure below :

nacos client Yes namespace The initialization , It mainly consists of two parts :

The user state passes nacos client When constructing an instance, you can use properties Parameter passed in namespace.

In the cloud ( Alicloud EDAS) Of namespace Argument parsing .

It can be done by -Dnacos.use.cloud.namespace.parsing=true/false To control whether automatic resolution is required in the cloud environment namespace Parameters , The default is true, Yes, it will be automatically parsed , Its purpose is to facilitate users to smoothly go to the cloud at zero cost . If users need to use self built on the cloud nacos Under the namespace, At this time, you just need to -Dnacos.use.cloud.namespace.parsing=false that will do .

原网站

版权声明
本文为[Bulst]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230223461118.html