Previously, we implemented service registration and discovery, and implemented the interface call in load balancing. However, our Eureka server is a single point. Although EurekaClient will connect to EurekaServer regularly to obtain the information in the registry and cache it to the local. If eurekacerver is unavailable, EurekaClient will not be updated, which will affect the call of microservice. Therefore, to have a highly available EurekaServer cluster, EurekaServer can realize highly available deployment by running multiple instances to register with each other. So as to ensure the data consistency.
Configure 3 eurekaservers
spring: profiles: es01 application: name: eurekserver server: port: 8081 eureka: instance: hostname: localhost prefer-ip-address: true client: registerWithEureka: false fetchRegistry: false serviceUrl: defaultZone: http://${eureka.instance.hostname}:8082/eureka/,http://${eureka.instance.hostname}:8083/eureka/ --- spring: profiles: es02 application: name: eurekserver server: port: 8082 eureka: instance: hostname: localhost prefer-ip-address: true client: registerWithEureka: false fetchRegistry: false serviceUrl: defaultZone: http://${eureka.instance.hostname}:8081/eureka/,http://${eureka.instance.hostname}:8083/eureka/ --- spring: profiles: es03 application: name: eurekserver server: port: 8083 eureka: instance: hostname: localhost prefer-ip-address: true client: registerWithEureka: false fetchRegistry: false serviceUrl: defaultZone: http://${eureka.instance.hostname}:8081/eureka/,http://${eureka.instance.hostname}:8082/eureka/
Now let's run through the examples used in the last section.
Eureka discovery configuration. Here we only configure the address of one Eureka server. To test more clearly, we need to copy Eureka server.
spring: profiles: dis01 application: name: eurekadiscovery server: port: 8001 eureka: client: serviceUrl: defaultZone: http://localhost:8081/eureka/ --- spring: profiles: dis02 application: name: eurekadiscovery server: port: 8002 eureka: client: serviceUrl: defaultZone: http://localhost:8081/eureka/
Eureka discovery 2 configuration. Here we only have the 8082 Eureka server
spring: application: name: eurekadiscovery2 server: port: 8003 eureka: client: serviceUrl: defaultZone: http://localhost:8082/eureka/
Start the three instances respectively.
http://localhost:8081/ http://localhost:8082/ http://localhost:8083/
As you can see, the three instances have been registered successfully, and the three eurekaservers have been replicated. implement http://localhost:8003/hi?name=sl , EurekaDiscovery 2 can successfully discover and call EurekaDiscovery instance.