Spring cloud eureka high availability cluster configuration

Spring cloud eureka high availability cluster configuration

Preface

The single machine mode of eureka registration center is characterized by low disaster tolerance, multiple registration services, low performance of a single node, easy to fail or even crash. In production, I adopt the cluster mode, that is, the high availability of eureka.

How to build a highly available cluster configuration

Just register with each other and get information from each other

Configure two eureka Service Center ports as 90019002

configuration file

  • Profile with port 9001


#tomcat port
server:
  port: 9001


spring:
  application:
    #Specify service name
    name: eurekaserver_gky

eureka:
  client:
    registerWithEureka: true  #Whether to register yourself with Eureka service is a service in itself, so there is no need to register
    fetchRegistry: true # Get registration information from Eureka
    serviceUrl:  # The owner of Eureka client interacting with Eureka server
      defaultZone: http://127.0.0.1:9002/eureka/

  instance:
    #Register your own ip to the eureka service
    prefer-ip-address: true

  • Profile with port 9002



#tomcat port
server:
  port: 9002


spring:
  application:
    #Specify service name
    name: eurekaserver_gky

eureka:
  client:
    registerWithEureka: true  #Whether to register yourself with Eureka service is a service in itself, so there is no need to register
    fetchRegistry: true # Get registration information from Eureka
    serviceUrl:  # The owner of Eureka client interacting with Eureka server
      defaultZone: http://127.0.0.1:9001/eureka/

  instance:
    #Register your own ip to the eureka service
    prefer-ip-address: true

main method

Start class consistency


//Open service center, life is an eureka service registry
@EnableEurekaServer
@SpringBootApplication
public class EurekaserverApplication {

    public static void main(String[] args) {
        SpringApplication.run(EurekaserverApplication.class, args);
    }

}

Pom file


    <!--    springcloud Dependency management-->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Greenwich.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
                <exclusions>
                </exclusions>
            </dependency>
        </dependencies>
    </dependencyManagement>


<!--    Subfunctional dependency-->

    <dependencies>

<!--        Add to eureka Service dependency-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>

    </dependencies>

Startup service

github code, please click Portal

Tags: Programming Spring Tomcat github

Posted on Wed, 18 Mar 2020 10:06:37 -0400 by convinceme