Springcloud high availability and springcloud availability
Purpose
In the actual production environment, a single point of registration center is defective. When the node goes down, the microservices dependent on its services will fail, therefore, a high-availability registration center is needed to make up for this defect. Eureka achieves high availability through the "partner" mechanism. Each Eureka instance must specify another Eureka address as its partner in the configuration. When Eureka starts, it obtains the existing registration list from its partner node, in this way, you do not need to worry about incomplete registration lists when adding machines to the Eureka cluster.
Project Architecture
Configuration file configuration application. properties
Spring. profiles. active = slave # use an IP address to define the Registration Center address eureka. instance. prefer-ip-address = true # disable self-protection mode eureka. server. enable-self-preservation = false ### enable security verification on eureka server. user. name = adminsecurity. user. password = 123456security. basic. enabled = true # do not register yourself with the Registration Center # eureka. client. register-with-eureka = false # The Registry is responsible for maintaining the service instance and does not need to retrieve the service # eureka. client. fetch-registry = false # The call interval of the Service Renewal task is 30 s by default # eureka. instance. lease-renewal-interval-in-seconds = 3 ### defines the default service expiration time as 90 s # eureka. instance. lease-expiration-duration-in-seconds = 540
Configuration application-slave.properties for Registration Center 1
spring.application.name=springcloud-eureka-serverserver.port=8766eureka.instance.instance-id=${spring.cloud.client.ipAddress}:${server.port}eureka.instance.hostname=${spring.cloud.client.ipAddress}eureka.client.serviceUrl.defaultZone=http://${security.user.name}:${security.user.password}@localhost:8765/eureka/eureka.instance.status-page-url-path=/
Configuration application-master.properties for registry 2
spring.application.name=springcloud-eureka-serverserver.port=8765eureka.instance.instance-id=${spring.cloud.client.ipAddress}:${server.port}eureka.instance.hostname=${spring.cloud.client.ipAddress}eureka.client.serviceUrl.defaultZone=http://${security.user.name}:${security.user.password}@localhost:8766/eureka/eureka.instance.status-page-url-path=/
Start
First, start the first service. At this time, set active in the overall configuration application. properties to slave. Then start the startup class. An error is reported at this time, but it does not matter. Start the second one.
spring.profiles.active=slave#spring.profiles.active=master
When the second service is started, set active in application. properties as master. Then start the startup class.
#spring.profiles.active=slavespring.profiles.active=master
In this case, a high-availability registration center is implemented.