springCloud eureka-08 细节问题 ip与服务续约,自我保护机制

一,注册中心页面 微服务不展示ip 信息

        在微服务配置文件yml 添加代码

server:
  port: 9002
spring:
  application:
    name: service-order
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/springclouddemo?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC
    username: root
    password: root
  jpa:
    database: MySQL
    show-sql: true
    open-in-view: true
eureka:
  client:
    service-url:
      defaultZone: http://localhost:9003/eureka/,http://localhost:9004/eureka/
  instance:
    prefer-ip-address: true
    instance-id: ${spring.cloud.client.ip-address}:${server.port} #向注册中心中展示注册服务id

 添加如下代码即可:

    prefer-ip-address: true
    instance-id: ${spring.cloud.client.ip-address}:${server.port} #向注册中心中展示注册服务id
${spring.cloud.client.ip-address} :获取ip地址

二,微服务注册慢(微服务心跳机制 时间问题)

        默认情况下,服务注册到Eureka Server 的过程较慢。 SpringCloud 官方文档中给出了详细的原因
大致含义:服务的注册涉及到心跳,默认心跳间隔为 30s。在实例、服务器、客户端都在本地缓存中具 有相同的元数据之前,服务不可用于客户端发现(所以可能需要 3 次心跳)。可以通过配置
eureka.instance.leaseRenewalIntervalInSeconds

(心跳频率)加快客户端连接到其他服务的过程。在生产中,最好坚持使用默认值,因为在服务器内部有一些计算,他们对续约做出假设。

三,微服务节点剔除问题

        默认情况下,由于Eureka Server 剔除失效服务间隔时间为 90s且存在自我保护的机制。所以不能有效而 迅速的剔除失效节点,这对开发或测试会造成困扰。

        微服务删掉后,由于微服务的失效服务机制在90秒,所以导致,删掉一个微服务后,90秒内,这个服务还在注册中心,我们可以设置短点时间。

Eureka Server
配置关闭自我保护,设置剔除无效节点的时间间隔
server:
  port: 9003
spring:
  application:
    name: eureka-server
  # eureka 配置
eureka:
  instance:
    hostname: 127.0.0.1
  client:
    register-with-eureka: true # 是否将自己注册到注册中心
    fetch-registry: true # 是否从eureka 中获取注册信息
    service-url:
      defaultZone: http://${eureka.instance.hostname}:9004/eureka/ #eureka服务地址;如果是集群则是其它服务器地址,后面要加/eureka
  server:
    enable-self-preservation: false #关闭自我保护
    eviction-interval-timer-in-ms: 4000 #默认注册中心排查到90秒后,微服务没有发送心跳,剔除服务,时间太长了。剔除服务时间间隔,单位:毫秒
  server:
    enable-self-preservation: false #关闭自我保护
    eviction-interval-timer-in-ms: 4000 #默认注册中心排查到90秒后,微服务没有发送心跳,剔除服务,时间太长了。剔除服务时间间隔,单位:毫秒
Eureka Client
配置开启健康检查,并设置续约时间

server:
  port: 9001
spring:
  application:
    name: service-product
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/springclouddemo?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC
    username: root
    password: root
  jpa:
    database: MySQL
    show-sql: true
    open-in-view: true

eureka:
  client:
    service-url:
      defaultZone: http://localhost:9003/eureka/,http://localhost:9004/eureka/
  instance:
    prefer-ip-address: true
    instance-id: ${spring.cloud.client.ip-address}:${server.port} #向注册中心中注册服务id
    lease-expiration-duration-in-seconds: 10 #eureka client 发送心跳给server端后,续约到期时间(默认为90秒)。
    lease-renewal-interval-in-seconds: 5 # 发送心跳续约间隔(每一个心跳的间隔)
 lease-expiration-duration-in-seconds: 10 #eureka client 发送心跳给server端后,续约到期时间(默认为90秒)。
    lease-renewal-interval-in-seconds: 5 # 发送心跳续约间隔(每一个心跳的间隔)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

vegetari

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值