(B) Spring Cloud Eureka Server High Availability Cluster 1

In the actual project, because there are multiple instances of micro service in Eureka Server registration, Eureka Server will withstand high loads, it is necessary to do high-availability cluster deployment Eureka Server

We transform on the previous article items

 

1. Set the host, simulation Eureka Server deployment in the two loom

The windows host file directory: C: \ Windows \ System32 \ drivers \ etc \ hosts, open with administrator privileges and add the following configuration

 

 

 

2. Add in a multi-profile configuration in Eureka Server

 

    2.1 First, add profiles in Eureka Server pom file

  

  <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>peer1</id>
            <properties>
                <profileActive> Peer1 </ profileActive > 
            </ Properties > 
            < Activation > 
                <-! Default parameters used without a -p peer1 strapping configuration -> 
                < activeByDefault > to true </ activeByDefault > 
            </ Activation > 
        </ Profile > 
        <! - packaging commands -P peer2 package Penalty for -> 
        < Profile > 
            < the above mentioned id > peer2 </ the above mentioned id > 
            < the Properties > 
                < profileActive >peer2</profileActive>
            </properties>
        </profile>
    </profiles>

  2.2 Add multiple yml 

     2.2.1 application.yml

  

spring:
  profiles:
    active: @profileActive@

     2.2.2 application-peer1.yml

  peer1 of Eureka Server to register peer2

Server: 
  Port: 8761 
eureka: 
  instance: 
    hostname: peer1 
  Client: 
    # Indicates whether registered itself to eureka server 
    # the Register-with-eureka: false 
    # whether to obtain registration information from the eureka 
    # FETCH-Registry: false 
    Service-url: 
      defaultzone: http: // peer2: 8762 / eureka /

 

    2.2.3 application-peer2.yml

 peer2 of Eureka Server to register peer1

server:
  port: 8762
eureka:
  instance:
    hostname: peer2
  client:
    #register-with-eureka: false
    #fetch-registry: false
    service-url:
      defaultZone: http://peer1:8761/eureka/

 

 

 

 

 

  Start Eureka Server 2.2.4

 

 Pictured above with maven plugin, were selected peer1 start, enable selected peer2

 

Peer1 will start being given, can be ignored, because the peer2 corresponding Eureka Server has not started until after peer2 subsequent start automatically registered peer1

 

3. Start Eureka Client

 

 3.1 Eureka Client configuration, Eureka Client can only register in peer1

 

eureka:
  client:
    serviceUrl:
      defaultZone: http://peer1:8761/eureka/
server:
  port: 8763
spring:
  application:
    name: eureka-client

 

 Start Eureka client

 

4. Verify access

 

Through the address http: // peer1: 8761 / can see peer2 and Eureka Client has been registered in peer1

 

 

 

 

 Access address http: // peer2: 8762 / can see peer1 have been registered in peer2, and registration information Eureka Client in peer1 has been synchronized to peer2

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/DevinZhang1990/p/12512397.html