zoukankan      html  css  js  c++  java
  • Spring Cloud Eureka高可用落地实战

    一、原理

    如图所示,多台Server端之间相互注册(这里以两台Server为例),Client端向所有的Server端注册。

    二、Server端配置

    1. 添加依赖

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

    2. 使用@EnableEurekaServer注解,开启Server端

    @EnableEurekaServer
    @SpringBootApplication
    public class TestEurekaApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(QmkxServerEurekaApplication.class, args);
        }
    }

    3. 增加配置

      为了配置方便,这里使用主机名代替IP,此处以单机为例,若多台机器,改为相应IP即可。

    hosts配置:

    127.0.0.1   peer1
    127.0.0.1   peer2

    application-peer1.yml配置:

    server:
    port: 2181
    eureka:
    client:
    service-url:
    defaultZone: http://peer2:2182/eureka/
    instance:
    hostname: peer1
    prefer-ip-address: true

    application-peer2.yml配置:

    server:
    port: 2182
    eureka:
    client:
    service-url:
    defaultZone: http://peer1:2181/eureka/
    instance:
    hostname: peer2
    prefer-ip-address: true

    三、Client端配置

    1. 添加依赖

    <dependency>
      <groupId>org.springframework.cloud</groupId>
       <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>

    2. 使用@EnableDiscoveryClient注解,开启注册功能

    @EnableDiscoveryClient
    @SpringBootApplication
    public class TestUserApplication {
        public static void main(String[] args) {
            SpringApplication.run(TestUserApplication.class, args);
        }
    }

    3. 修改配置文件,添加所有的Server,用逗号隔开

    # 注册中心
    eureka:
      instance:
        prefer-ip-address: true
      client:
        service-url:
          defaultZone: http://peer1:2181/eureka/,http://peer2:2182/eureka/

    四、查看Eureka

  • 相关阅读:
    对数线性模型与线性链条件随机场
    25匹马,5个跑道,每个跑道最多能有1匹马进行比赛,最少比多少次能比出前3名?前5名?
    SVM 与 LR的异同
    EM算法简易推导
    K-means算法的优缺点
    自助采样包含训练集里63.2%的样本?
    指数加权移动平均
    oracle 对于用户的相关操作
    docker 安装 maven 私有库 nexus3
    idea 自动注入@Autowired 警告 Field injection is not recommended 关闭
  • 原文地址:https://www.cnblogs.com/wslook/p/10000179.html
Copyright © 2011-2022 走看看