Eureka, as the Spring Cloud service discovery and Registration center, is at the core of the entire microservices system. A single Eureka service, obviously can not meet the high availability of the actual production environment, which requires us to configure a variety of emergency situations, with strong capacity for disaster tolerance of Eureka services. Here I will take a simpler example to describe the implementation of this highly available service.
First, service construction
New->project-> Select Spring Initialir such as:
Next, choose Cloud Discovery->eureka Server, and then keep going next.
The Pom.xml file for the completed project is as follows:
1<?xml version= "1.0" encoding= "UTF-8"?>2<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"3xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >4<modelVersion>4.0.0</modelVersion>5 6<groupId>com.example</groupId>7<artifactId>eureka</artifactId>8<version>0.0.1-SNAPSHOT</version>9<packaging>jar</packaging>Ten One<name>eureka</name> A<description>demo Project forSpring boot</description> - -<parent> the<groupId>org.springframework.boot</groupId> -<artifactId>spring-boot-starter-parent</artifactId> -<version>1.5.9.RELEASE</version> -<relativePath/> <!--lookup parent from repository to +</parent> - +<properties> A<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> at<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> -<java.version>1.8</java.version> -<spring-cloud.version>Edgware.RELEASE</spring-cloud.version> -</properties> - -<dependencies> in<dependency> -<groupId>org.springframework.cloud</groupId> to<artifactId>spring-cloud-starter-eureka-server</artifactId> +</dependency> - the<dependency> *<groupId>org.springframework.boot</groupId> $<artifactId>spring-boot-starter-test</artifactId>Panax Notoginseng<scope>test</scope> -</dependency> the</dependencies> + A<dependencyManagement> the<dependencies> +<dependency> -<groupId>org.springframework.cloud</groupId> $<artifactId>spring-cloud-dependencies</artifactId> $<version>${spring-cloud.version}</version> -<type>pom</type> -<scope>Import</scope> the</dependency> -</dependencies>Wuyi</dependencyManagement> the -<build> Wu<plugins> -<plugin> About<groupId>org.springframework.boot</groupId> $<artifactId>spring-boot-maven-plugin</artifactId> -</plugin> -</plugins> -</build> A + the</project>
To create a service registry and add annotations to the application class, you only need one annotation @enableeurekaserver
1 PackageCom.example.demo;2 3 Importorg.springframework.boot.SpringApplication;4 Importorg.springframework.boot.autoconfigure.SpringBootApplication;5 ImportOrg.springframework.cloud.netflix.eureka.server.EnableEurekaServer;6 7 @EnableEurekaServer8 @SpringBootApplication9 Public classeurekaapplication {Ten One Public Static voidMain (string[] args) { ASpringapplication.run (eurekaapplication.class, args); - } -}
Modifying the Application.properties configuration file
1 server.port=87612 spring.application.name=eureka-server3 eureka.client.fetch-registry=false4 eureka.client.register-with-eureka=false5 eureka.client.serviceurl.defaultzone=http://localhost:8762/eureka/
Second, packaging deployment
Package with Maven to generate a jar package
Deploy the jar package to two servers, server 1 (192.168.12.52), server 2 (192.168.12.36), and modify the jar package configuration file Application.properties
Server 1:
1 server.port=87612 spring.application.name=eureka-server3 eureka.client.fetch-registry=false4 eureka.client.register-with-eureka=false5 eureka.client.serviceurl.defaultzone=http://192.168.12.36:8762/eureka/
Server 2:
1 server.port=87622 spring.application.name=eureka-server3 eureka.client.fetch-registry=false4 eureka.client.register-with-eureka=false5 eureka.client.serviceurl.defaultzone=http://192.168.12.52:8761/eureka/
Enter DOS and execute the following command
Java-jar Eureka-0.0.1-snapshot.jar
Open URL 192.168.12.52:8761,192.168.12.26:8762 (note Two servers to be able to ping through) can write a simple service, to set up a good Eureka Service Center registration, testing, here is no longer to repeat.
Spring cloud| High-availability Eureka Cluster service