SpringCloud distributed micro-cloud infrastructure services tenth chapter: service registry highly available (Finchley version)

Articles SpringCloud tutorials | First: service registration and discovery (Eureka) introduced the service registration and discovery, where the service registry Eureka Server, is an example, when tens of thousands of service to its registration, its load is very high, which in the production environment is not appropriate, this article describes how the Eureka Server cluster.

First, the preparatory work

Eureka can be made even more resilient and available by running multiple instances and asking them to register with each other. Infact, this is the default behaviour, so all you need to do to make it work is add a valid serviceUrl to a peer, e.g.——摘自官网

Eureka by running multiple instances, to make it more highly available. Learn springcloud architecture can be added to beg: 3536247259, in fact, which is its default maturity, you need to do is give an example of such a legitimate association serviceurl.

In this article we project based on the first article, do the modifications.

Second, the transformation of
resources folder in eureka-server project, create a profile application-peer1.yml:

server:
  port: 8761

spring:
  profiles: peer1
eureka:
  instance:
    hostname: peer1
  client:
    serviceUrl:
      defaultZone: http://peer2:8769/eureka/

And create another profile application-peer2.yml:


server:
  port: 8769

spring:
  profiles: peer2
eureka:
  instance:
    hostname: peer2
  client:
    serviceUrl:
      defaultZone: http://peer1:8761/eureka/

Then eureka-server has been the transformation is completed.

ou could use this configuration to test the peer awareness on a single host (there’s not much value in doing that in production) by manipulating /etc/hosts to resolve the host names.

Follow the instructions of official documents, it is necessary to change the etc / hosts, linux system by vim / etc / hosts, plus:

127.0.0.1 peer1
127.0.0.1 peer2

windows computer, in c: / windows / systems / drivers / etc / hosts changes.

Then in need of rehabilitation under service-hi:

eureka:
  client:
    serviceUrl:
      defaultZone: http://peer1:8761/eureka/
server:
  port: 8762
spring:
  application:
    name: service-hi

Third, start the project
start eureka-server:
java -jar eureka-server-0.0.1-SNAPSHOT.jar --spring.profiles.active=peer1
SpringCloud distributed micro-cloud infrastructure services tenth chapter: service registry highly available (Finchley version)
Start service-hi:

java -jar service-hi-0.0.1-SNAPSHOT.jar

Access: localhost: 8761, as shown:
SpringCloud distributed micro-cloud infrastructure services tenth chapter: service registry highly available (Finchley version)
You will find the registered service-hi, and there peer2 nodes, empathy visit localhost: 8769 you will find a peer1 nodes.

client registers only 8761, but you open the 8769, you will find that there are 8769 registered client's information.

Personal experience: This is the official demo by looking at written documents, but the need to manually change the host is not inconsistent with the large high Spring Cloud?
Prefer IP Address

In some cases, it is preferable for Eureka to advertise the IP Adresses of services rather than the hostname. Set eureka.instance.preferIpAddress to true and when the application hostname .-- taken from the official website
eureka.instance.preferIpAddress = true is provided by ip let eureka let other service register it. You might be able to change to change the host by the way.

At this architecture diagram: SpringCloud distributed micro-cloud infrastructure services tenth chapter: service registry highly available (Finchley version)
Eureka-eserver peer1 8761, Eureka-eserver mutual induction peer2 8769, when a service registry, two Eureka-eserver are peers, they are there the same information, which is through server redundancy more than to increase the reliability, when one server goes down, the service does not end, because another service there the same data.

Guess you like

Origin blog.51cto.com/14622290/2461106