SpringCloud | Part 7: Highly Available Service Registry

The first part of the article: Service registration and discovery (Eureka) introduces service registration and discovery. The service registration center, Eureka Server, is an instance. When thousands of services are registered with it, its load is very high. , which is not suitable for production environments. This article mainly introduces how to cluster Eureka Server.

1. Preparation
Eureka can be made even more resilient and available by running multiple instances and asking them to register with each other. In fact, this is the default behaviour, so all you need to do to make it work is add a valid serviceUrl to a peer, eg

Eureka makes it more highly available by running multiple instances. In fact, this is its default familiarity, all you need to do is give the peer instance a valid associated serviceurl.

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

2. Transformation work
In the resources folder of the eureka-server project, create a configuration file application-peer1.yml :

server:
  port: 8761

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


And create another configuration file application-peer2.yml :

server:
  port: 8769

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


At this time, eureka-server has been transformed.

you 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.

As indicated by the official documentation, etc/hosts needs to be changed, linux System through vim /etc/hosts, plus:

127.0.0.1 peer1
127.0.0.1 peer2

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

At this time, you need to modify the service-hi:

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


3. Start the project

Start eureka-server:

java -jar eureka-server-0.0.1-SNAPSHOT.jar - -spring.profiles.active=peer1

java -jar eureka-server-0.0.1-SNAPSHOT.jar - -spring. profiles.active=peer2


start service-hi:

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

access: localhost:8761,:

you will find that service-hi is registered, and there is a peer2 node, similarly access localhost :8769 You will find a peer1 node.

The client only registers with 8761, but if you open 8769, you will also find that 8769 also has client registration information.

Personal experience: This is a demo written by reading the official documentation, but does it not conform to the superiority of Spring Cloud if you need to manually change the host?

Reprinted from: http://blog.csdn.net/forezp/article/details/70183572


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326207414&siteId=291194637