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

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article is about how to use Eureka cluster to build a highly available service registration center. I think it is very practical, so I share it with you. I hope you can get something after reading this article. Let's follow the editor to have a look.

The registry we built before is only suitable for local development and use, and a cluster must be built in the production environment to ensure high availability. The cluster building method of Eureka is very simple: each Eureka only needs to specify the addresses of multiple other Eureka in the configuration to build a cluster.

Let's take two nodes as an example to illustrate the construction method. Suppose we have two machines, master and slaveone, and what we need to do is:

Register master with slaveone.

Register slaveone with master.

If it's three machines, and so on:

Register master with slaveone and slavetwo.

Register slaveone with master and slavetwo.

Register slavetwo with master and slaveone.

Building steps

Create a new project eureka-server-cluster with the same configuration as eureka-server.

First, we need to add two properties files to start different instances in different environments. Add application-master.properties:

Server.port=8761# points to the Eurekaeureka.client.serviceUrl.defaultZone=http:// username of your slave node: password @ localhost:8762/eureka/

Add application-slaveone.properties:

Server.port=8762# points to the Eurekaeureka.client.serviceUrl.defaultZone=http:// username of your primary node: password @ localhost:8761/eureka/

Add the following to application.properties:

Spring.application.name=eureka-server-cluster# is set to false because the application is a registry, which means that it does not register its own eureka.client.register-with-eureka=false# with the registry. Because the responsibility of the registry is to maintain service instances and does not need to retrieve services, it is also set to falseeureka.client.fetch-registry=falsespring.security.user.name=zhangsanspring.security.user.password=123456# to specify a different environment spring.profiles.active=master.

Start with master by default on machine A, and then add-- spring.profiles.active=slaveone to machine B.

This registers master with slaveone, registers slaveone with master, and the application can continue to use the surviving registry no matter who has a problem.

Previously, in the client, we specified the corresponding registry by configuring eureka.client.serviceUrl.defaultZone. When our registry has multiple nodes, we need to modify the configuration of eureka.client.serviceUrl.defaultZone to the addresses of multiple nodes, which can be separated by English commas:

Eureka.client.serviceUrl.defaultZone= http://zhangsan:123456@localhost:8761/eureka/,http://zhangsan:123456@localhost:8762/eureka/ above is how to use Eureka cluster to build a highly available service registry. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please 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

Development

Wechat

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

12
Report