Springcloud Tutorials (iii) High-availability service registries

Source: Internet
Author: User

First, the preparatory work

Eureka can made even more resilient and available by running multiple instances and asking them to register with each o Ther. In fact, the "the default behaviour, so all" need to does to make it work are add a valid serviceurl to a peer, e.g.

From official website

Eureka makes it more highly available by running multiple instances. In fact, this is its default maturity, and all you need to do is give the equivalent instance a legitimate association serviceurl.

This article is based on the first article of the project, to make changes.

Second, the transformation work

Under the Resources folder in the Eureka-server project, create the configuration file Application-peer1.yml:

Server:  port:8761spring:  Profiles:peer1eureka:  instance:    hostname:peer1  Client:    Serviceurl:      defaultzone:http://peer2:8769/eureka/

and create another configuration file application-peer2.yml:

Server:  port:8769spring:  Profiles:peer2eureka:  instance:    hostname:peer2  Client:    Serviceurl:      defaultzone:http://peer1:8761/eureka/

At this time the Eureka-server has been transformed complete.

OU could use this configuration to test the peer awareness on a single host (there's not much value in doing so in Produ ction) by Manipulating/etc/hosts to resolve the host names.

In accordance with official documentation instructions, the Etc/hosts,linux system needs to be changed via Vim/etc/hosts, plus:

127.0.0.1 peer1127.0.0.1 Peer2

  

Windows PC, modified in c:/windows/systems/drivers/etc/hosts.

At this time need to transform the next Service-hi:

Eureka:  Client:    serviceurl:      defaultzone:http://peer1:8761/eureka/server:  port:8762spring:  Application:    Name:service-hi

  

Iii. Commencement of Works

Start Eureka-server:

Java-jar Eureka-server-0.0.1-snapshot.jar--spring.profiles.active=peer1java-jar Eureka-server-0.0.1-SNAPSHOT.jar --spring.profiles.active=peer2

  

Start Service-hi:

Java-jar Service-hi-0.0.1-snapshot.jar

Visit: localhost:8761,

You will find that you have registered Service-hi, and you have a Peer2 node, and the same access localhost:8769 you will find a Peer1 node.

Client only registers with 8761, but when you open 8769, you will also find that 8769 also has the client's registration information.

Personal experience: This is done by looking at the official documentation of the demo, but need to manually change the host is not in line with spring Cloud high up?

Prefer IP Address

In some cases, it's preferable for Eureka to advertise the IP Adresses of services rather than the hostname. Set eureka.instance.preferIpAddress to True and if the application registers with Eureka, it'll use the IT IP Address rat She than its hostname.

From official website

Eureka.instance.preferipaddress=true is to let Eureka let other services register it by setting the IP. It may be possible to change the way it is by changing the host.

The architecture diagram at this point:

Eureka-eserver peer1 8761,eureka-eserver peer2 8769 Mutual Sensing, when there is a service registration, two Eureka-eserver is equivalent, they all have the same information, which is the redundancy of the server to increase reliability, When one server goes down, the service does not terminate because the same data exists for the other service.

Source Source

Springcloud Tutorials (iii) High-availability service registries

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.