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

The method of Service Partition using DNS in Spring Cloud Eureka Cluster

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly explains "the method of Spring Cloud Eureka cluster using DNS for service partition". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the method of Spring Cloud Eureka cluster using DNS for service partition".

There are several ways to configure the Eureka registry

The common configuration methods on the Internet are as follows

First, use defaultZone, which has no concept of partition. In one zone, all services will use serverUrl configured by defaultZone for service registration and discovery. There are a lot of articles on the Internet. I won't repeat them here.

There are two ways to configure a cluster, one is the configuration file, and the other is DNS.

A partition concept, Region and Zone, is also mentioned here, which is described in the articles of taro source code http://www.iocoder.cn/Eureka/eureka-client-init-second/?sf&2017-11-01 and Zhou Li http://www.itmuch.com/spring-cloud-1/.

Two, one. The first way to configure files, which is also a more comprehensive introduction of online documents.

SpringCloudEureka for service partitions: https://www.jianshu.com/p/2ca32773b3e5 and

Two configuration modes of eureka cluster: configuration file mode and Dns mode http://www.cnblogs.com/relinson/p/eureka_ha_config_properties_and_dns.html

These two articles are also introduced more clearly.

The key point is to configure region and availability-zones, which should pay attention to the order of nodes before and after, and the configuration of service-url, which can basically be realized, but this way needs to be written down in advance. For dynamically increasing the registry to adjust the partition, it is necessary to adjust the configuration of each eurekaclient. To put it bluntly, each service has to modify the corresponding configuration items, so the configuration mode of DNS is extended.

2. Configure Eureka cluster in 2.Dns mode

This way is also introduced online, such as this article https://www.cnblogs.com/relinson/p/eureka_ha_use_dns.html

The first half of the introduction is also very clear, there are also a few key configuration items

Use-dns-for-fetching-service-urls: true is configured in dns mode

Eureka-server-d-n-s-name: XXX.com DNS root domain name

Region: beijing

Eureka-server-u-r-l-context: the eureka directory of the eureka configuration center

Eureka-server-port: 9999 maps the ports of other eurekaServer. Note that in this way, server.port and this port had better be the same.

Because dns controls the change of address and the port remains the same, unlike the previous configuration methods, you can define url and port yourself. So every IP uses the same port to deploy registry services.

These are also the relatively clear configuration methods mentioned in the article, but in the process of stepping on the pit, it is found that these are only explained in the first half, and there are a number of details that can not be found online. Let's talk about it.

1. First of all, both EurekaServer and EurekaClient have to set the DNS address, that is to say, the registry and other services registered to the registry should be configured with a private DNS service address on the running service machine, so that the machine can use the same DNS service address. For local windows debugging, go to the network adapter and change the DNS in the IPv4.

2. To configure the DNS server, take the DNS server of windows as an example, first create a domain XXX.com, that is, corresponding to the

Eureka-server-d-n-s-name

Secondly, you need to build a region such as beijing, and then you need to create a text of type txt and fill it with 3azone.XXX.com 3bzone.XXX.com, which is equivalent to two partitions under a region.

Then we need to build two domains, a 3azone and a 3bzone, in the sibling directory of region. The division of the region can be named and divided according to its own situation.

3b also built a similar configuration, so that the configuration of dns is completed, by looking at the source code of Eureka, his implementation is by looking at the

Obtained by txt.beijing.XXX.com (txt.region.eureka-server-d-n-s-name) in this way

Zone,3azone and 3bzone in 3azone.XXX.com and 3bzone.XXX.com

Then get the data of the corresponding ServiceUrls in txt.3azone.XXX.com and txt.3bzone.XXX.com, that is, the IP address.

In this way, the services can obtain the registry services of different IP machines under the fixed port and register with each other.

3. Unavailable-replicas may occur after registries register with each other, which is mainly caused by two attributes.

Or use IP to register eureka.instance.prefer-ip-address=true. If you use host instead of IP registration, it is very important to configure eureka.instance.hostname: 3azone.XXX.com #. If you use host without configuration, unavailable-replicas will be displayed.

4. After the service center is configured, other client services only need to configure the corresponding connection method.

Eureka:

Instance:

Prefer-ip-address: true

Metadata-map:

Zone: 3azone # which district does the service registration priority belong to?

Client:

Register-with-eureka: true

Fetch-registry: true

Region: beijing

# enable DNS to obtain serviceUrl. Default is false.

Use-dns-for-fetching-service-urls: true

# DNS domain name, which will be used as the root domain name to obtain other information

Eureka-server-d-n-s-name: XXX.com

# eureka service root directory

Eureka-server-u-r-l-context: eureka

# connect to the registry port

Eureka-server-port: 9999 # here must be the port of the registry. If you don't want to write it down, you have to configure the environment variable to implement it.

With a little attention, the above steps can perfectly complete the eureka DNS-based configuration of partition clusters, and dynamically add the number and location of partitions and registries.

Thank you for your reading. the above is the content of "how Spring Cloud Eureka clusters use DNS for service partitioning". After the study of this article, I believe you have a deeper understanding of the method of Spring Cloud Eureka cluster using DNS for service partitioning, and the specific usage needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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

Internet Technology

Wechat

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

12
Report