Eureka implements service registration and discovery, plays a key role in spring cloud microservices, must be guaranteed to be highly available, and the conventional solution is nothing more than a cluster implementation. Here in the local machine to build a pseudo-cluster environment, through two nodes to register each other, and through the master and standby data synchronization to achieve high availability, the actual production environment may have multiple nodes, the same principle. The simple steps are as follows:
"Step1": The Eureka configuration file is as follows
Spring:application:name:eureka-Cluster---Spring:profiles:masterserver:port:8761eureka:instance:hostname:master Client:registerwitheureka:falseFetchregistry:falseserviceUrl:defaultZone:http://Backup:8762/eureka---Spring:profiles:backupserver:port:8762eureka:instance:hostname:backup Client:registerwitheureka:falseFetchregistry:falseserviceUrl:defaultZone:http://Master:8761/eureka
Note: Here the simulation is implemented over the port, and the machine host information needs to be configured:
192.168.31.11 Master
192.168.31.11 Backup
"Step2": Package the deployment and start
Package by mvn Install, then start separately,
Java-jar Eureka.jar--spring.profiles.active=master
Java-jar Eureka.jar--spring.profiles.active=backup
Specify spring.profiles.active at startup to implement a master and standby simulation.
"STEP3": Access test
Visit http://192.168.31.11:8761/details as follows:
Visit http://192.168.31.11:8762/details as follows:
"STEP4": Modify client, start client test
Client modified Eureka's registered address: eureka.client.serviceurl.defaultzone:http://master:8761/eureka/,http://backup:8762/eureka/, Start the client and then access Eureka View separately, which is already registered to each node.
If you stop one of the Eureka nodes and then start viewing again, you will see that the service information is synchronized from the available nodes to the current node.
Spring Cloud notes Eureka high availability through clustering