Eureka server is registering with each other to achieve a highly available deployment , so we only need to configure the Eureke server with other available serviceurl to enable a highly available deployment
- Create
application-peer2.properties
as a configuration for the Peer2 Service Center and Point Serviceurl to Peer1
-
Spring.application.name=eureka-serverserver.port = 1112 eureka.instance.hostname =peer2# Point to another registry Eureka.client.serviceUrl.defaultZone =http:// peer1:1111/eureka/
hosts
file
-
127.0.0.1 Peer1 127.0.0.1 peer2
- Peer1 and Peer2 are started separately through the
spring.profiles.active
property
-
java-jar eureka-server-1.0.0.jar--spring.profiles.active=peer1java -jar Eureka-server-1.0.0.jar--spring.profiles.active=peer2
At this point, access to Peer1 's registry: http://localhost:1111/。
registered-replicas
There are already peer2 nodes in the Eureka-server.
Similarly, access to Peer2 's registry: http://localhost:1112/
registered-replicas
There are already peer1 nodes in the, and these nodes are in the available shards (available-replicase).
We can also try to turn off Peer1, refresh http://localhost:1112/
, peer1 node becomes unusable shard (Unavailable-replicas).
Service Registration and Discovery
pring.application.name=compute-serviceserver.port=2222eureka.client.serviceUrl.defaultZone= http://peer1:1111/eureka/,http://peer2: 1112/eureka/
How to configure Serviceurl to synchronize services in a cluster
Eureka server synchronization follows a very simple principle: information can be propagated and synchronized as long as one side connects the nodes
Scene One
Assuming we have 3 registries, we will Peer1, Peer2, and Peer3 each point serviceurl to another two nodes. In other words, Peer1, Peer2 and Peer3 are 22 registered with each other. Start the three service registries and point the Compute-service serviceurl to Peer1 and start to get the cluster effect as shown.
Access http://localhost:1112/
, you can see 3 registries composed of clusters, compute-service services through Peer1 synchronization to the mutual registration of Peer2 and Peer3
Summarize:
- 22 The method of registration can realize the full equivalence of nodes in the cluster, achieve the highest availability cluster, and no one registry fault will affect the registration and discovery of the service.
Eureka server is highly available