Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to get through CMDB to realize the nearest access

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you how to get through CMDB to achieve access to the nearest, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.

In enterprises, CMDB is generally used to store metadata related to machines and equipment, applications, services and so on. When the machines and applications of enterprises reach a certain scale, they need such a system to store and manage their metadata. There are some widely used attributes, such as IP, hostname, server room, application, region, and so on. These data are generally entered into CMDB when the machine is deployed, and these data are used by OPS or monitoring platform for display or related OPS operations.

When services are deployed in multiple data centers or regions, the latency of cross-region service access is often high. The typical network latency between data centers in a city is about 1ms, while the network latency between cities, such as Shanghai to Beijing, is about 30ms. A natural idea at this time is whether service consumers and service providers can have access to the same region. In our practice within the group, this requirement is achieved by communicating with CMDB. In the service discovery component of Nacos, docking CMDB, and then through the configured access rules to achieve the service consumer to the service provider in the same region first.

Cdn.nlark.com/lark/0/2018/png/15356/1544702277705-0bbfca60-6629-477c-92bb-1a690e68f9cd.png ">

Figure 1 intra-region priority access to services

This is actually a load balancing strategy. In the planning of Nacos, a rich configurable load balancing strategy on the server is an important development direction, which is different from the existing registry products. When designing how to support nearest access in an open source scenario, integration with the enterprise's own CMDB is a core issue that we consider. In addition, we are also considering extending Nacos itself to a CMDB that implements basic functionality. In any case, we need to be able to get IP environment information from somewhere, either from the enterprise's CMDB or from our own built-in storage.

CMDB plug-in mechanism

Regardless of how to apply CMDB data to load balancer, we need to obtain CMDB data in Nacos first. In practical use, basically every company will build its own CMDB through purchase or self-research, so in order to decouple the specific implementation of each enterprise's CMDB, a better strategy is to use the SPI mechanism, agree on the abstract call interface of CMDB, and each enterprise can add its own CMDB plug-in, without any code reconstruction, to connect with the enterprise CMDB in the running state.

image.png | center | 295x394

Fig. 2 principle of Nacos CMDB SPI mechanism

As shown in figure 2, Nacos defines a SPI interface that contains methods that are contracted with third-party CMDB. After the user implements the corresponding SPI interface in accordance with the contract, pack the implementation into a jar package and place it in the Nacos installation directory. Restart Nacos to connect the data between Nacos and CMDB. The whole process is not complicated, but it is not easy to understand the meaning of methods and corresponding concepts in the CMDB SPI interface. Here, the related concepts and interface meaning of CMDB mechanism are described in detail.

CMDB Abstract concept entity (Entity)

Entity is the carrier of data in CMDB. In general CMDB, an entity can refer to an IP, application or service. This entity will have many attributes, such as IP server room information, service version information, and so on.

Entity type (Entity Type)

We do not limit that the entity must be an IP, application, or service, depending on the actual business scenario. Nacos has plans to support different entity types in the future, but for now, the entity type required for service discovery is IP.

Label (Label)

Label is our abstract Entity attribute, and Label is defined as a Kmuri V-value pair that describes the Entity attribute. The value ranges of key and value of Label are generally predefined. When you need to make changes to Label, such as adding a new key or value, you need to call a separate API and trigger the corresponding event. A common example of Label is the computer room information of IP. We think that the computer room (site) is the key of Label, and the collection of computer room (site1, site2, site3) is the value of Label. The definition of this Label is: site: {site1, site2, site3}.

Entity event (Entity Event)

A change event for the label of the entity. When the entity attribute of CMDB changes, an event mechanism is needed to notify all subscribers. In order to ensure that the change information carried by the entity event is up-to-date and accurate, this event will only contain the identity of the changed entity and the type of the change event, not the value of the changed label.

CMDB convention interface

When designing the interface with CMDB, we referred to the internal access interface to CMDB and discussed it with several external customers. We finally identified the following interfaces that third-party CMDB plug-ins must implement:

Get tag list Set getLabelNames ()

This method will return a collection of tag names in CMDB that need to be recognized by Nacos, and the CMDB plug-in can decide which tag Nacos to return as needed. Tags that are not in this collection will be ignored by Nacos, even if the tag appears in the attribute of the entity. We allow this collection to change dynamically at run time, and Nacos will periodically call this interface to refresh the tag collection.

Get entity type Set getEntityTypes ()

Gets the collection of types of entities in CMDB. Entity types that are not in this collection will be ignored by Nacos. The entity required by the service discovery module is similar to ip. If you want to achieve advanced load balancing of the service by passing through CMDB data, be sure to include "ip" in the return set.

Get tag details Label getLabel (String labelName)

Gets the details of the label. The returned Label class contains a collection of tag names and tag values. If the value of this tag of an entity is not in the set of tag values, it will be considered invalid.

Query entity tag value String getLabelValue (String entityName, String entityType, String labelName); Map getLabelValues (String entityName, String entityType)

There are two methods, one is to obtain the value corresponding to a label signature of the entity, and the other is to obtain the key-value pairs of all the tags of the entity. The parameter contains the value and type of the entity. Note that this method is not called every time a query is triggered inside Nacos. There is a cache of CMDB data inside Nacos. Only when this cache expires or does not exist will the CMDB plug-in be accessed to query the data. In order to make the implementation of the CMDB plug-in as simple as possible, we have implemented the corresponding caching and refresh logic within Nacos.

Query entity Map getAllEntities (); Entity getEntity (String entityName, String entityType)

Querying entities consists of two methods: querying all entities and querying a single entity. Currently, querying a single entity is actually querying all the tags of that entity, but we distinguish this method from the method of getting all tags, because querying a single entity method may be extended to get more information than all tags.

Querying all entities pulls all the data from CMDB at once, which may consume performance, whether for Nacos or CMDB. The strategy for calling this method within Nacos is to pull all data regularly through a configurable scheduled task cycle. When implementing the CMDB plug-in, you should also pay attention to the performance of the CMDB service itself and adopt an appropriate strategy.

Query entity event List getEntityEvents (long timestamp)

The purpose of this method is to get the change message of the entity in the recent period of time, and to pull the changed entity incrementally. Because Nacos does not access the CMDB plug-in to query the entity in real time, you need this method to pull events to get updates to the entity. The timestamp in the parameter is the time when the event was last pulled, and the CMDB plug-in can choose to use or ignore this parameter.

CMDB plug-in development process

Referring to https://github.com/nacos-group/nacos-examples, an example plugin implementation has been given here.

The specific steps are as follows:

Create a new maven project and introduce the dependency nacos-api:

Com.alibaba.nacos nacos-api 0.7.0

Introduce packaging plug-ins:

Org.apache.maven.plugins maven-assembly-plugin jar-with-dependencies

Define implementation classes, inherit com.alibaba.nacos.api.cmdb.CmdbService, and implement related methods.

Create a new directory under the src/main/resource/ directory: META-INF/services

After the code self-test is completed, execute the command to package:

Mvn package assembly:single-Dmaven.test.skip=true

Upload the jar package containing dependencies under the target directory to the nacos CMDB plug-in directory:

{nacos.home} / plugins/cmdb

Turn on the load plug-in switch in nacos's application.properties:

Nacos.cmdb.loadDataAtStart=true

Restart nacos Server and load it into your nacos-cmdb plug-in to get your CMDB data.

Using Selector to achieve priority access in the same computer room

After getting the CMDB data, you can use the powerful power of CMDB data to implement a variety of flexible load balancing strategies. Here is an example of how to use CMDB data and Selector to access the nearest.

Suppose that Nacos has obtained some information about IP's data center through CMDB, and the corresponding tag information is as follows:

11.11.11.11 site: x1122.22.22.22 site: x1233.33.33.33 site: x1144.44.44.44 site: x1255.55.55.55 site: x13

11.11.11.11,22.22.22,33.33.33.33, 44.44.44.44 and 55.55.55.55 all contain tags site, and their corresponding values are x11, x12, x11, x12, x13, respectively. Let's sign up for a service and load IP11.11.11.11 and 22.22.22.22 below.

Figure 4 Editing the service route type

Here we select the service route type as the label, and then enter the expression of the label:

CONSUMER.label.site = PROVIDER.label.site

The format of this expression is related to our abstract Selector mechanism, which will be covered in another article. What you need to remember here is that any expression in the following format:

CONSUMER.label.labelName = PROVIDER.label.labelName

The load balancing strategy based on the same labelName priority will be implemented.

Then assume that the IP of the service consumer is 33.33.33.33, 44.44.44.44 and 55.55.55, respectively, and they are querying the service instance list using the following API:

Naming.selectInstances ("nacos.test.1", true)

Then different consumers will get a different list of instances. 33.33.33.33 get 11.11.11.11, 44.44.44.44 will get 22.22.22.22, while 55.55.55.55 will get 11.11.11.11 and 22.22.22.22 at the same time.

The above content is how to get through CMDB to access the nearest place. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report