前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >springcloud学习手册-Eureka常见问题总结

springcloud学习手册-Eureka常见问题总结

作者头像
程序源代码
发布2018-03-09 16:41:33
3.3K0
发布2018-03-09 16:41:33
举报
文章被收录于专栏:程序源代码程序源代码

导读 | Eureka常见问题总结

一、配置方法问题汇总

1.1. Eureka Environment的配置:

eureka.environment: 字符串

配置环境名称,可以在appliaction.yml 中配置eureka.environment:指定一下名称,这样就可以了。这个名称是可配置的选项。

默认:test

参考文档:

https://github.com/Netflix/eureka/wiki/Configuring-Eureka

1.2. Eureka DataCenter的配置

eureka.datacenter: 字符串

配置环境名称,可以在appliaction.yml 中配置eureka.datacenter: 指定一下名称,这样就可以了。这个名称是可配置的选项。

默认:default

解释:

配置-Deureka.datacenter=cloud,这样eureka将会知道是在AWS云上

参考文档:

https://github.com/Netflix/eureka/wiki/Configuring-Eureka

1.3. Eureka开启自我保护的提示

EMERGENCY! EUREKA MAY BE INCORRECTLY CLAIMING INSTANCES ARE UP WHEN THEY'RE NOT. RENEWALS ARE LESSER THAN THRESHOLD AND HENCE THE INSTANCES ARE NOT BEING EXPIRED JUST TO BE SAFE.

产生原因:Eureka Server在运行期间,会统计心跳失败的比例在15分钟之内是否低于85%,如果出现低于的情况(在单机调试的时候很容易满足,实际在生产环境上通常是由于网络不稳定导致),Eureka Server会将当前的实例注册信息保护起来,同时提示这个警告。保护模式主要用于一组客户端和Eureka Server之间存在网络分区场景下的保护。一旦进入保护模式,Eureka Server将会尝试保护其服务注册表中的信息,不再删除服务注册表中的数据(也就是不会注销任何微服务)。

解决方法:

设置enableSelfPreservation:false

配置心跳检测时长,下线leaseRenewalIntervalInSeconds: 2

参考文档:

https://github.com/Netflix/eureka/wiki/Understanding-Eureka-Peer-to-Peer-Communication

1.4. Eureka注册服务慢的问题如何解决?

eureka.instance.leaseRenewalIntervalInSeconds

参考文档:

http://cloud.spring.io/spring-cloud-static/Camden.SR1/#_why_is_it_so_slow_to_register_a_service

原文:

Why is it so Slow to Register a Service?

Being an instance also involves a periodic heartbeat to the registry (via the client’s serviceUrl) with default duration 30 seconds. A service is not available for discovery by clients until the instance, the server and the client all have the same metadata in their local cache (so it could take 3 heartbeats). You can change the period using eureka.instance.leaseRenewalIntervalInSeconds and this will speed up the process of getting clients connected to other services. In production it’s probably better to stick with the default because there are some computations internally in the server that make assumptions about the lease renewal period.

翻译:

作为实例还涉及到与注册中心的周期性心跳,默认持续时间为30秒(通过serviceUrl)。在实例、服务器、客户端都在本地缓存中具有相同的元数据之前,服务不可用于客户端发现(所以可能需要3次心跳)。你可以使用eureka.instance.leaseRenewalIntervalInSeconds 配置,这将加快客户端连接到其他服务的过程。在生产中,最好坚持使用默认值,因为在服务器内部有一些计算,他们对续约做出假设。

1.5. 如何解决Eureka Server不踢出已关停的节点的问题?

server端:

代码语言:javascript
复制
eureka.server.enable-self-preservation(设为false,关闭自我保护主要)
eureka.server.eviction-interval-timer-in-ms 清理间隔(单位毫秒,默认是60*1000)

client端:

代码语言:javascript
复制
eureka.client.healthcheck.enabled = true开启健康检查(需要spring-boot-starter-actuator依赖)
eureka.instance.lease-renewal-interval-in-seconds =10租期更新时间间隔(默认30秒)
eureka.instance.lease-expiration-duration-in-seconds =30  租期到期时间(默认90秒)

示例:

服务器端配置:

eureka:

server:

enableSelfPreservation: false

evictionIntervalTimerInMs: 4000

客户端配置:

eureka:

instance:

leaseRenewalIntervalInSeconds: 10

leaseExpirationDurationInSeconds: 30

注意:

更改Eureka更新频率将打破服务器的自我保护功能

https://github.com/spring-cloud/spring-cloud-netflix/issues/373

1.6. Eureka配置instanceId显示IP

eureka:

client:

serviceUrl:

defaultZone: http://localhost:8761/eureka/

instance:

preferIpAddress: true

instance-id: ${spring.cloud.client.ipAddress}:${server.port}

1.7. 依赖引入

代码语言:javascript
复制
<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>

1.8 注解

  • @SpringBootApplication 该注解表明这是个springboot工程。
  • @EnableEurekaServer: 该注解表明应用为eureka服务,有可以联合多个服务作为集群,对外提供服务注册以及发现功能
  • @EnableEurekaClient:该注解表明应用既作为eureka实例又为eureka client,可以发现注册的服务。
  • @Repository 实现DAO数据库交互

1.9. Eureka配置最佳实践总结

https://github.com/spring-cloud/spring-cloud-netflix/issues/203

声明:文章属于个人原创,转载请注明文章出处

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2017-12-10,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 全华班 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、配置方法问题汇总
    • 1.1. Eureka Environment的配置:
      • 1.2. Eureka DataCenter的配置
        • 1.3. Eureka开启自我保护的提示
          • 1.5. 如何解决Eureka Server不踢出已关停的节点的问题?
            • 1.6. Eureka配置instanceId显示IP
              • 1.7. 依赖引入
                • 1.9. Eureka配置最佳实践总结
                相关产品与服务
                微服务引擎 TSE
                微服务引擎(Tencent Cloud Service Engine)提供开箱即用的云上全场景微服务解决方案。支持开源增强的云原生注册配置中心(Zookeeper、Nacos 和 Apollo),北极星网格(腾讯自研并开源的 PolarisMesh)、云原生 API 网关(Kong)以及微服务应用托管的弹性微服务平台。微服务引擎完全兼容开源版本的使用方式,在功能、可用性和可运维性等多个方面进行增强。
                领券
                问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档