Eureka's cluster building method - guaranteed high availability

In the microservices architecture, the registry is an essential component
The registration center we built earlier is only suitable for local development. In the production environment, a cluster must be set up to ensure high availability.
Eureka's cluster setup is simple, and each Eureka needs to specify another N Eureka address in the configuration.
Below we explain with 2 nodes
We have master and slaveone 2 machines, all we need to do is:
- Master registered to slaveone
- The slaveone can be registered to the master.

If it is 3 machines, then so on:


Master registered to slaveone, slavetwo
Slaveone registered to the master, slavetwo
The slavetwo is registered to the master, slaveone. First we need to add 2 property files to start different instances through different environments.
Add applicaTIon-master.properTIes

Server.port=8761
# pointing to your slave node Eureka
eureka.client.serviceUrl.defaultZone=http://username:password@slaveone:8762/eureka/
Add applicaTIon-slaveone.properTIes

Server.port=8762
#Eureka pointing to your primary node
eureka.client.serviceUrl.defaultZone=http://username:password@master:8761/eureka/
Master and slaveone are hostname, can be added in the hosts file, directly write IP
Add the following content to application.properties
Spring.application.name=fangjia-eureka

Eureka.instance.hostname=localhost
# Since the app is a registry, it is set to false, which means you are not registering yourself with the registry.
Eureka.client.register-with-eureka=false
# Since the role of the registry is to maintain the service instance, he does not need to retrieve the service, so it is also set to false.
Eureka.client.fetch-registry=false
# Close self protection
eureka.server.enableSelfPreservation=false
Security.basic.enabled=true
Security.user.name=username
Security.user.password=Password
# Specify a different environment
Spring.profiles.active=master
Start on the A machine by default to start with the master, and then add -spring.profiles.active=slaveone on the B machine to start the master so that the master is registered to the slave, the slaveone is registered to the master, and the configuration information on the 2 side is synchronized. No matter who hangs, the application can continue to use the surviving registry.

New Products

New Products

SHENZHEN CHONDEKUAI TECHNOLOGY CO.LTD , https://www.szsiheyi.com