码迷,mamicode.com
首页 > 编程语言 > 详细

springbcloud5----高可用

时间:2018-06-03 19:24:44      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:parent   info   hot   []   frame   alt   net   rgs   span   

技术分享图片

技术分享图片

package com.itmuch.cloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
public class EurekaHaApplication {
  public static void main(String[] args) {
    SpringApplication.run(EurekaHaApplication.class, args);
  }
}
spring:
  application:
    name: EUREKA-HA
---
server:
  port: 8764
spring:
  profiles: peer1
eureka:
  instance:
    hostname: peer1 #主机名是peer1
  client:
    serviceUrl:
      defaultZone: http://peer2:8762/eureka/,http://peer3:8763/eureka/  #把自己注册到2和3,相互注册
---
server:
  port: 8762
spring:
  profiles: peer2
eureka:
  instance:
    hostname: peer2  #主机名是peer2
  client:
    serviceUrl:
      defaultZone: http://peer1:8761/eureka/,http://peer3:8763/eureka/  #把自己注册到1和3,相互注册
---
server:
  port: 8763
spring:
  profiles: peer3
eureka:
  instance:
    hostname: peer3  #主机名是peer3
  client:
    serviceUrl:
      defaultZone: http://peer1:8761/eureka/,http://peer2:8762/eureka/  #把自己注册到1和2,相互注册
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.itmuch.cloud</groupId>
        <artifactId>microservice-spring-cloud</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>microservice-discovery-eureka-ha</artifactId>
    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka-server</artifactId>
        </dependency>
        <!-- <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency> -->
    </dependencies>

</project>

分别启动不同的peer

技术分享图片

用户微服务注册的时候,注册多个eureka server地址。

技术分享图片

 

springbcloud5----高可用

标签:parent   info   hot   []   frame   alt   net   rgs   span   

原文地址:https://www.cnblogs.com/yaowen/p/9129910.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!