系列四、Eureka自我保护

一、Eureka自我保护

1.1、故障现象

保护模式主要用于一组客户端和Eureka Server之间存在网络分区场景下的保护。一旦进入保护模式,Eureka Server将会尝试保护其服务注册表中的信息,不再删除服务注册表中的数据,也就是不会注销任何微服务。如果在Eureka Server的首页看到以下这段提示,则说明Eureka进入了保护模式:

1.2、故障原因

注销任何健康的微服务,使用自我保护模式,可以让Eureka集群更加的健壮、稳定。

一句话:某时刻某一个微服务不可用了,Eureka不会立刻清理,依旧会对该微服务的信息进行保存;

属于CAP里面的AP分支;

1.3、怎么禁止自我保护

出厂默认:

自我保护机制是开启的:eureka.server.enable-self-preservation=true

Eureka客户端向服务端发送心跳的时间间隔,单位为秒(默认是30秒)

eureka.instance.lease-renewal-interval-in-seconds=30

Eureka服务端在收到最后一次心跳后等待时间上限,单位为秒(默认是90秒),超时将剔除服务

eureka.instance.lease-expiration-duration-in-seconds=90

使用eureka.server.enable-self-preservation = false 可以禁用自我保护模式

1.3.1、application.yml(8001)

bash 复制代码
server:
  port: 8001

spring:
  application:
    name: cloud-payment-service
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/20230906_springcloud_alibaba?useSSL=false&useUnicode=true&characterEncoding=UTF8&serverTimezone=Asia/Shanghai
    username: root
    password: 123456

mybatis-plus:
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
    map-underscore-to-camel-case: true
  mapper-locations: classpath:mappers/*.xml
  global-config:
    db-config:
      # 基于雪花算法生成id
      id-type: assign_id
      logic-delete-field: deleted
      logic-not-delete-value: 0
      logic-delete-value: 1
  type-aliases-package: org.star.entity.model

eureka:
  client:
    # true:表示是否将自己注册进EurekaServer,默认为true
    register-with-eureka: true
    # 是否从EurekaServer抓取已有的注册信息,默认为true。单节点无所谓,集群必须设置为true才能配合ribbon使用负载均衡
    fetch-registry: true
    service-url:
      # 单机版
      defaultZone: http://localhost:7001/eureka
      # 集群版
      # defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka
  instance:
    instance-id: payment8001
    prefer-ip-address: true
    # Eureka客户端向服务端发送心跳的时间间隔,单位为秒(默认是30秒)
    lease-renewal-interval-in-seconds: 1

1.3.2、application.yml(7001)

bash 复制代码
server:
  port: 7001

eureka:
  instance:
    hostname: localhost
  client:
    # false:表示不向注册中心注册自己、true:表示向注册中心注册自己
    register-with-eureka: false
    # false:表示自己就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
    fetch-registry: false
相关推荐
小码哥0685 小时前
一套可复用的打车系统模板,微服务版网约车系统|类似滴滴的打车平台
微服务·云原生·架构·滴滴·打车
老毛肚5 小时前
微服务网关整合授权中心实现单点登录
运维·微服务·架构
万里侯6 小时前
GitLab CI/CD流水线优化实战:从龟速到飞速的蜕变
微服务·容器·k8s
huipeng9266 小时前
基于SpringCloud的博客系统
java·运维·后端·spring·spring cloud·微服务
豆沙沙包?7 小时前
SpringCloud01-03---简介/从单体到集群架构/从单体到分布式架构
分布式·微服务·架构·springcloud
喵了几个咪7 小时前
单体项目如何“无感”演进微服务?GoWind的Core+BFF分层实践
微服务·架构·golang·gowind·bff
RemainderTime8 小时前
(十二)Spring Cloud Alibaba 2023.x:基于 Filebeat 构建轻量级 ELK日志追踪体系
分布式·elk·elasticsearch·微服务·架构·logback
万里侯8 小时前
户外露营攻略:远离城市喧嚣的完美周末
微服务·容器·k8s
万里侯8 小时前
云原生安全最佳实践:守护容器化应用的安全防线
微服务·容器·k8s
万里侯8 小时前
云原生存储方案对比:选择适合你的存储策略
微服务·容器·k8s