Springcloud Series IV: Enabling High availability of Eureka server and registering applications on Eureka Sever clusters

Source: Internet
Author: User

1. Review

In a previous blog, a single-node Eureka Server was implemented. Eureka client periodically connects to Eureka Server, obtains information from the registry, and caches it locally. MicroServices always use data from the local cache when consuming remote APIs. As a result, in general, even if the Eureka server goes down, it does not affect calls between services. However, if Eureka server is down and some microservices are unavailable, the cache in the Eureka server may affect the invocation of the microservices or even the high availability of the entire application system if it is not refreshed. Therefore, in a build environment, a highly available Eureka server cluster is typically deployed.

Eureka server can implement highly available deployments by running multiple instances and registering with each other, and Eureka server instances synchronize information incrementally with each other, ensuring that all node data is consistent. In fact, the mutual registration of nodes is the default behavior of Eureka Server.

2. Build a two-node Eureka server cluster

> Copy Project Microservice-discovery-eureka, change Artifactid to Microservice-discovery-eureka-ha01

> Copy Project Microservice-discovery-eureka, change Artifactid to MICROSERVICE-DISCOVERY-EUREKA-HA02

> Modify the Hosts file, under Windows platform, go to directory:C:\Windows\System32\drivers\etc, then open the Hosts file with administrator privileges, add a record

127.0. 0.1 Peer1 Peer2

> Modify MICROSERVICE-DISCOVERY-EUREKA-HA01 configuration file Application.yml

Server:   8762 Eureka:  instance:    hostname: peer1  client:    service-URL:      Defaultzone:http://Peer2:8763/eureka # Sets the address that interacts with Eureka Server, and the query service and registration service need to rely on this address.  Spring:  application:    name:microservice-discovery-eureka-ha

> Modify MICROSERVICE-DISCOVERY-EUREKA-HA02 configuration file Application.yml

Server:   8763 Eureka:  instance:    hostname: peer2  client:    service-URL:      Defaultzone:http://Peer1:8762/eureka # Sets the address that interacts with Eureka Server, and the query service and registration service need to rely on this address.  Spring:  application:    name:microservice-discovery-eureka-ha

> Two items must be spring.application.name the same, eureka.instance.hostname must be different, otherwise it will fail. ( at least that's what I'm testing )

> Start two items, Access: http://peer1:8762/and http://peer2:8763/, at which point the Registered-replicas (registered shard) has a URL address for another system, And all in Available-replicase (available shards)

3. Registering the microservices on the Eureka server cluster

> Modify the configuration file Application.yml in Microservice-provider-user to change Eureka.client.service-url.defaultzone to Http://peer1 : 8762/eureka/.

Eureka:  client:    service-URL:      defaultzone:http://peer1:8762/ eureka/

> Modify the configuration file Application.yml in Microservice-consumer-movie to change the Eureka.client.service-url.defaultzone to HTTP.// peer1:8762/eureka/,http://peer2:8763/eureka/.

Eureka:  client:    service-URL:      defaultzone:http://peer1:8762/eureka/,  http://peer2: 8763/eureka

> Start the Eureka server cluster first, and then start the two micro services. Visit: http://peer1:8762/and http://peer2:8763/. found that the two micro services are registered in the cluster.

Description if the microservices only configure a node in the Eureka server cluster, it can also register properly with the Eureka server cluster because the data between multiple Eureka servers is synchronized with each other.

However, to accommodate some extreme scenarios, it is recommended that you configure multiple Eureka server nodes on the client.

4. Summary

Some of the previous blogs speak of Eureka Server that allow anonymous access.

The next blog will explain adding user authentication for Eureka server. Please expect ~ ~ ~

5. Reference

Li---"Spring Cloud and Docker microservices architecture and Combat"

Springcloud Series IV: Enabling High availability of Eureka server and registering applications on Eureka Sever clusters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.