Before we introduced the Springcloud registry Eureka, but there is a single point of failure problem, a registration center is far from meeting the actual production environment, now we introduce how to build a Eureka cluster.
A: Cluster environment construction
We first build two registration center project, a call Eureka_register_master, a call eureka_register_salve. The port of Master is 7998,salve port is 7999.
The configuration file for Eureka_register_master application.properties is as follows:
server.port=7998eureka.client.register-with-eureka=falseEureka.client.fetch -registry=falsespring.application.name=eureka-servereureka.instance.hostname= mastereureka.client.service-url.defaultzone=http://Salve:7999/eureka
The configuration file for Eureka_register_salve application.properties is as follows:
server.port=7998eureka.client.register-with-eureka=falseEureka.client.fetch -registry=falsespring.application.name=eureka-servereureka.instance.hostname= mastereureka.client.service-url.defaultzone=http://Salve:7999/eureka
The startup file for Eureka_register_master is as follows:
Package Com.ysl;import Org.springframework.boot.springapplication;import Org.springframework.boot.autoconfigure.springbootapplication;import Org.springframework.cloud.netflix.eureka.server.EnableEurekaServer, @EnableEurekaServer @springbootapplication Public class application { publicstaticvoid Main (string[] args) { springapplication.run (application. class , args);} }
The startup file for Eureka_register_salve is as follows:
Package Com.ysl;import Org.springframework.boot.springapplication;import Org.springframework.boot.autoconfigure.springbootapplication;import Org.springframework.cloud.netflix.eureka.server.EnableEurekaServer, @EnableEurekaServer @springbootapplication Public class application { publicstaticvoid Main (string[] args) { springapplication.run (application. class , args);} }
Start:
If the jar is started, the parameter--spring.profiles.active=matser or--spring.profiles.active=salve is required.
Open http://127.0.0.1:7998/and http://127.0.0.1:7999/respectively such as:
by looking at Port 7998 is matser its registered-replicas pointing to http://backup:7999/eureka/, Port 7999 is backup, and its registered-replicas points to http://master:7999/eureka/.
Two: Service-side registration
After setting up multiple registries, our service configuration does not require much change just to modify the application.properties serviceurl of the SERVICE01 project as follows:
Eureka.client.serviceurl.defaultzone=http://master:7998/eureka/,http://salve : 7999/eureka/,
Of course, you can also bind an address, eureka.client.serviceurl.defaultzone=http://master:7998/eureka/both of these bindings.
Three: Cluster understanding
Although we use two nodes as an example above, we may need to build more than two Eureka server nodes in the production environment because of the load and so on. So how to configure Serviceurl to synchronize services in a cluster requires a deeper understanding of the synchronization mechanism between nodes to make decisions. We use a graph to understand the cluster.
Springcloud Eureka Cluster