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 use Eureka Cluster to build a highly available Service Registry in Spring Cloud

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

Share

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

Today, I will talk to you about how to use Eureka clusters to build highly available service registration centers in Spring Cloud. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something from this article.

This article focuses on how to build a highly available Eureka cluster.

1. What's the difference between distributed and cluster?

Many people may be a little confused about the concepts of distribution and clustering. Let me first explain to you in words that are easy to understand:

Distributed: a business is split into multiple sub-services and deployed on different servers

Cluster: the same business is deployed on different servers

So each distributed node completes a different business, and if a node dies, then this business function is inaccessible and may even affect other businesses. The cluster is a more organized architecture, it is precisely because of the organization, a service node is dead, other service nodes can be on top, thus ensuring the robustness of the service.

Therefore, the cluster can be understood as: you have me, I have you, hand in hand side by side, together to ensure the robustness of the service.

2. Eureka cluster logic

Before building an Eureka cluster, let's review the single Eureka service built earlier and take a look at the yml configuration file:

Server:

Port: 7001

Eureka:

Instance:

# instance name of eureka server

Hostname: eureka01

Client:

# false means not registering yourself with the registry

Register-with-eureka: false

# false indicates that the client is the registry. My duty is to maintain the service instance and not to retrieve the service.

Fetch-registry: false

Service-url:

# setting up the address query service and registration service that interact with Eureka Server depends on this address (stand-alone).

DefaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

This is an Eureka service, named eureka7001, and the registry is its own. So how do we build an Eureka cluster? Suppose you now have three Eureka services: eureka7001, eureka7002, and eureka7003.

In order to show that there are both you and me in the cluster, it is not difficult to imagine that there should be eureka7002 in eureka7001 and eureka7001 in eureka7003;eureka7002 and eureka7001 and eureka7002 in eureka7003;eureka7003. As shown in the following figure:

This sets up an Eureka cluster, so how do we implement it? Next, it will be implemented in a specific way.

3. Transformation of Eureka7001

From the above analysis, Eureka7001 needs to attach Eureka7002 and Eureka7003, so you need to reconfigure defaultZone in the configuration file of Eureka7001, as follows:

Server:

Port: 7001

Eureka:

Instance:

# instance name of eureka server

Hostname: eureka01

Client:

# false means not registering yourself with the registry

Register-with-eureka: false

# false indicates that the client is the registry. My duty is to maintain the service instance and not to retrieve the service.

Fetch-registry: false

Service-url:

DefaultZone: http://eureka02.com:7002/eureka/,http://eureka03.com:7003/eureka/

OK,defaultZone is configured with eureka7002 and eureka 7003.

4. Set up Eureka7002

In the same way, copy an Eureka7001 project and modify its configuration file:

Server:

Port: 7002

Eureka:

Instance:

# instance name of eureka server

Hostname: eureka02

Client:

# false means not registering yourself with the registry

Register-with-eureka: false

# false indicates that the client is the registry. My duty is to maintain the service instance and not to retrieve the service.

Fetch-registry: false

Service-url:

DefaultZone: http://eureka01.com:7001/eureka/,http://eureka03.com:7003/eureka/

As you can see, in eureka7002, eureka7001 and eureka7003 are linked in.

5. Set up Eureka7003

Set up the eureka7003 in the same way.

Server:

Port: 7003

Eureka:

Instance:

# instance name of eureka server

Hostname: eureka03

Client:

# false means not registering yourself with the registry

Register-with-eureka: false

# false indicates that the client is the registry. My duty is to maintain the service instance and not to retrieve the service.

Fetch-registry: false

Service-url:

DefaultZone: http://eureka01.com:7001/eureka/,http://eureka02.com:7002/eureka/

Ok, now that the three eureka registries are set up, don't forget to map eureka7001, eureka7002, and eureka7003 to 127.0.0.1 in the local hosts file.

6. Modify order service

Let's first recall how the configuration file of the previous order provider was written:

# client registers in the list of eureka services

Eureka:

Client:

Service-url:

DefaultZone: http://eureka01:7001/eureka/

Instance:

Instance-id: book order Service-8001 # humanized display of service information

Prefer-ip-address: true # access path can display ip address

Is to register the order service with eureka7001, because there was only one eureka registry before, so now there are three, we need to modify the configuration to register the order service with three eureka.

# client registers in the list of eureka services

Eureka:

Client:

Service-url:

DefaultZone: http://eureka01:7001/eureka/,http://eureka02:7002/eureka/,http://eureka03:7003/eureka/

Instance:

Instance-id: book order Service-8001 # humanized display of service information

Prefer-ip-address: true # access path can display ip address

7. Test effect

OK, all the building steps are completed, then start eureka7001, eureka7002 and eureka7003 respectively, and then start placing orders to provide services. Then we can visit each of the next three eureka registries to see the results. Taking visiting eureka7001 as an example, I can see that the service center is hung with eureka7002 and eureka7003, and the order service is successfully registered with the registry.

After reading the above, do you have any further understanding of how to use Eureka clusters to build a highly available service registry in Spring Cloud? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

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