• Eureka 高可用


    原来:

     高可用:

    介绍:

    高可用:服务可一直被使用,当一个坏了之后就不能用了,所以需要搭集群,他们之间相互注册

    搭建步骤:

    1.  准备两个Eureka Server
    2. 分别配置,相互注册
    3. Eureka Client分别注册到这两个Eureka Server中

     搭建:

    准备两个Eureka Server 分别配置,相互注册

     创建两个新模块eureka_server_1和eureka_server_2

     添加依赖

    1. <dependencies>
    2. <dependency>
    3. <groupId>org.springframework.bootgroupId>
    4. <artifactId>spring-boot-starter-webartifactId>
    5. dependency>
    6. <dependency>
    7. <groupId>org.springframework.cloudgroupId>
    8. <artifactId>spring-cloud-starter-netflix-eureka-serverartifactId>
    9. dependency>
    10. dependencies>

    添加配置文件

    1. server:
    2. port: 8761/8762 两个server需要端口做区分
    3. #web控制台默认地址 http://localhost:8761
    4. eureka:
    5. instance:
    6. hostname: eureka-server-1 #主机名儿一样无法构成集群
    7. 另一个server: hostname:eureka-server_2
    8. #http://eureka-server-1:8761/eureka
    9. #http://eureka-server-2:8762/eureka
    10. 需要在系统host文件中把这个名字设置为回环地址
    11. client:
    12. service-url:
    13. defaultZone:http://eureka-server-1:8761/eureka
    14. 或者http://eureka-server-2:8762/eureka #相互注册对方地址
    15. registerWithEureka: true
    16. fetchRegistry: true
    17. #两个集群名字一样
    18. spring:
    19. application:
    20. name: eureka_server_ha

      

    添加启动类

    1. package com.gao.eureka;
    2. import org.springframework.boot.SpringApplication;
    3. import org.springframework.boot.autoconfigure.SpringBootApplication;
    4. import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
    5. @SpringBootApplication
    6. //启用 EurekaServer
    7. @EnableEurekaServer
    8. public class EurekaApp {//两个server的启动类不能一样
    9. public static void main(String[] args){
    10. SpringApplication.run(EurekaApp.class,args);
    11. }
    12. }

    Eureka Client分别注册到这两个Eureka Server中

    consumer

    1. server:
    2. port: 9000
    3. eureka:
    4. instance:
    5. hostname: localhost
    6. client:
    7. service-url:
    8. #defaultZone: http://localhost:8761/eureka
    9. defaultZone: http://eureka-server1:8761/eureka,http://eureka-server2:8762/eureka # 注册
    10. spring:
    11. application:
    12. name: eureka-consumer #设置当前应用的名称。将来会在eureka中application显示,将来需要使用该名称来获取路径

    provider

    1. server:
    2. port: 8000
    3. eureka:
    4. instance:
    5. hostname: localhost
    6. prefer-ip-address: true #是否将自己的ip注册到eureka中。(默认false 注册主机名)
    7. ip-address: 127.0.0.1 # 设置当前实例ip(之后会向server注册这个ip)
    8. instance-id: ${eureka.instance.ip-address}:${spring.application.name}:${server.port} #修改instance-id显示(设置web控制台显示的 实例id)
    9. lease-renewal-interval-in-seconds: 30 # 每一次eureka client 向 eureka server发送心跳的时间间隔
    10. lease-expiration-duration-in-seconds: 90 # 如果90秒内eureka server没有收到eureka client的心跳包,则剔除该服务
    11. client:
    12. service-url:
    13. # defaultZone: http://localhost:8761/eureka
    14. defaultZone: http://eureka-server1:8761/eureka,http://eureka-server2:8762/eureka # 注册
    15. server:
    16. enable-self-preservation: false #关闭保护机制 默认是true
    17. eviction-intrerval-timer-in-ms: 3000 #检查服务的时间间隔
    18. spring:
    19. application:
    20. name: eureka-provider #设置当前应用的名称。将来会在eureka中application显示,将来需要使用该名称来获取路径

     DsReplicas 为高可用

    当两个server中一个坏了的时候,还可以继续使用

    两个服务之间也是互通的

     

    域名,不能含有下划线

    域名可以由(a-z、A-Z 大小写等价)26个英文字母、数字(0-9)以及连接符“-”组成,但是域名的首位必须是字母或数字。对于域名的长度也有一定的限制:

    国际通用顶级域名长度不得超过26个字符

    中国国家顶级域名长度不得超过20个字符

  • 相关阅读:
    技术专家说 | 如何基于 Spark 和 Z-Order 实现企业级离线数仓降本提效?
    python:使用卷积神经网络(CNN)进行回归预测
    【Java基础】Java导Excel攻略
    tensor维度变换
    渗透测试修复笔记 - 02 Docker Remote API漏洞
    【Canvas】js用Canvas绘制漩涡螺旋图动画效果
    【总结】kubernates 插件工具总结
    基于springboot+vue的汽车改装方案网站(源码+论文)
    Tomcat选择不同配置文件启动
    LCR 002. 二进制求和
  • 原文地址:https://blog.csdn.net/qq_51497041/article/details/126181707