spring cloud Eureka常见问题总结
Spring Cloud中,Eureka常见问题总结。
指定Eureka的Environment
|
1
|
eureka.environment: 指定环境
|
参考文档:https://github.com/Netflix/eureka/wiki/Configuring-Eureka
指定Eureka的DataCenter
|
1
|
eureka.datacenter: 指定数据中心
|
参考文档:https://github.com/Netflix/eureka/wiki/Configuring-Eureka
文中指出,配置-Deureka.datacenter=cloud,这样eureka将会知道是在AWS云上。
如何解决Eureka注册服务慢的问题
使用配置项:
|
1
|
eureka.instance.leaseRenewalIntervalInSeconds
|
参考文档:
http://cloud.spring.io/spring-cloud-static/Camden.SR1/#_why_is_it_so_slow_to_register_a_service
原文:
|
1
2
3
|
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.
|
翻译:
|
1
|
作为实例还涉及到与注册中心的周期性心跳,默认持续时间为30秒(通过serviceUrl)。在实例、服务器、客户端都在本地缓存中具有相同的元数据之前,服务不可用于客户端发现(所以可能需要3次心跳)。你可以使用eureka.instance.leaseRenewalIntervalInSeconds 配置,这将加快客户端连接到其他服务的过程。在生产中,最好坚持使用默认值,因为在服务器内部有一些计算,他们对续约做出假设。
|
Eureka的自我保护模式
如果在Eureka Server的首页看到以下这段提示,则说明Eureka已经进入了保护模式。
|
1
|
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之间存在网络分区场景下的保护。一旦进入保护模式,Eureka Server将会尝试保护其服务注册表中的信息,不再删除服务注册表中的数据(也就是不会注销任何微服务)。
详见:https://github.com/Netflix/eureka/wiki/Understanding-Eureka-Peer-to-Peer-Communication
如何解决Eureka Server不踢出已关停的节点的问题
在开发过程中,我们常常希望Eureka Server能够迅速有效地踢出已关停的节点,但是新手由于Eureka自我保护模式,以及心跳周期长的原因,常常会遇到Eureka Server不踢出已关停的节点的问题。解决方法如下:
(1) Eureka Server端:配置关闭自我保护,并按需配置Eureka Server清理无效节点的时间间隔。
|
1
2
|
eureka.server.enable-self-preservation # 设为false,关闭自我保护
eureka.server.eviction-interval-timer-in-ms # 清理间隔(单位毫秒,默认是60*1000)
|
(2) Eureka Client端:配置开启健康检查,并按需配置续约更新时间和到期时间。
|
1
2
3
|
eureka.client.healthcheck.enabled # 开启健康检查(需要spring-boot-starter-actuator依赖)
eureka.instance.lease-renewal-interval-in-seconds # 续约更新时间间隔(默认30秒)
eureka.instance.lease-expiration-duration-in-seconds # 续约到期时间(默认90秒)
|
示例:
服务器端配置:
|
1
2
3
4
|
eureka:
server:
enable-self-preservation: false
eviction-interval-timer-in-ms: 4000
|
客户端配置:
|
1
2
3
4
5
6
7
|
eureka:
client:
healthcheck:
enabled: true
instance:
lease-expiration-duration-in-seconds: 30
lease-renewal-interval-in-seconds: 10
|
注意:
更改Eureka更新频率将打破服务器的自我保护功能,生产环境下不建议自定义这些配置。
详见:https://github.com/spring-cloud/spring-cloud-netflix/issues/373
自定义Eureka的Instance ID
在Spring Cloud中,服务的Instance ID的默认值是${spring.cloud.client.hostname}:${spring.application.name}:${spring.application.instance_id:${server.port}},也就是机器主机名:应用名称:应用端口 。因此在Eureka Server首页中看到的服务的信息类似如下:itmuch:microservice-provider-user:8000 。如果想要自定义这部分的信息怎么办?
示例:
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
instance:
preferIpAddress: true
instance-id: ${spring.cloud.client.ipAddress}:${server.port} # 将Instance ID设置成IP:端口的形式
Eureka配置最佳实践参考
https://github.com/spring-cloud/spring-cloud-netflix/issues/203
注意点:eureka.client.healthcheck.enabled=true配置项必须设置在application.yml中
eureka.client.healthcheck.enabled=true 只应该在application.yml中设置。如果设置在bootstrap.yml中将会导致一些不良的副作用,例如在Eureka中注册的应用名称是UNKNOWN等。
spring cloud Eureka常见问题总结的更多相关文章
- 1 Spring Cloud Eureka服务治理
注:此随笔为读书笔记.<Spring Cloud微服务实战> 什么是微服务? 微服务是将一个原本独立的系统拆分成若干个小型服务(一般按照功能模块拆分),这些小型服务都在各自独立的进程中运行 ...
- Spring Cloud Eureka Server集群Demo级搭建
将上篇随笔Spring Cloud Eureka服务Demo级搭建进行改造,改造成一个在本机的伪集群 1.修改hosts文件(windows10 hosts文件位置:C:\Windows\System ...
- spring cloud eureka高可用
记录下自己踩的坑 spring cloud eureka的高可用网上的教程大致分为两种,一种是两两互相注册,一种是三个互相注册. 1.两两互相注册 普通服务的注册写法都是http://peer1/eu ...
- 笔记:Spring Cloud Eureka 服务治理
Spring Cloud Eureka 是 Spring Cloud Netflix 微服务套件的一部分,基于 Netflix Eureka 做了二次封装,主要负责完成微服务架构中的服务治理功能,服务 ...
- Spring Cloud Eureka 自我保护机制
Eureka Server 在运行期间会去统计心跳失败比例在 15 分钟之内是否低于 85%,如果低于 85%,Eureka Server 会将这些实例保护起来,让这些实例不会过期,但是在保护期内如果 ...
- Spring Cloud Eureka 常用配置详解,建议收藏!
前几天,栈长分享了 <Spring Cloud Eureka 注册中心集群搭建,Greenwich 最新版!>,今天来分享下 Spring Cloud Eureka 常用的一些参数配置及说 ...
- Spring Cloud Eureka 你还在让它裸奔吗??
前些天栈长在微信公众号Java技术栈分享了 Spring Cloud Eureka 最新版 实现注册中心的实战教程:Spring Cloud Eureka 注册中心集群搭建,Greenwich 最新版 ...
- Spring Cloud Eureka 注册中心集群搭建,Greenwich 最新版!
Spring Cloud 的注册中心可以由 Eureka.Consul.Zookeeper.ETCD 等来实现,这里推荐使用 Spring Cloud Eureka 来实现注册中心,它基于 Netfl ...
- Spring Cloud微服务笔记(三)服务治理:Spring Cloud Eureka快速入门
服务治理:Spring Cloud Eureka 一.服务治理 服务治理是微服务架构中最为核心和基础的模块,它主要用来实现各个微服务实例的自动化注册与发现. 1.服务注册: 在服务治理框架中,通常会构 ...
随机推荐
- SpringBoot文件上传大小设置(yml中配置)
#文件大小 MB必须大写 # maxFileSize 是单个文件大小 # maxRequestSize是设置总上传的数据大小 spring: servlet: multipart: enabled: ...
- oracle dblink的创建与使用
一.什么是DBLINK dblink,顾名思义就是数据库的链接. 当我们要跨本地数据库访问另一个数据库中的表的数据时,在本地数据库中就必须要创建远程数据库的dblink,通过该dblink就可以达到访 ...
- [转] pytorch指定GPU
查过好几次这个命令,总是忘,转一篇mark一下吧 转自:http://www.cnblogs.com/darkknightzh/p/6836568.html PyTorch默认使用从0开始的GPU,如 ...
- Thymeleaf模板布局
⒈定义片段 1.使用th:fragment <div th:fragment="copy"> © 2019 <a href="http://www.co ...
- 【转】Linux下查看系统配置
[转]Linux下查看系统配置 CPU 1. lscpu:显示cpu架构信息 [xxx@localhost ~]$ lscpu Architecture: x86_64 CPU op-mode(s): ...
- platform模块
import platform ''' python中,platform模块给我们提供了很多方法去获取操作系统的信息 如: import platform platform.platform() #获 ...
- 快速开发工具:Servoy
快速开发工具:Servoy https://servoy.com/
- 利用微信企业号的告警功能,联动检测ICMP的shell脚本
作者:邓聪聪 由于设备IP众多,为了及时发现IP地址有不可达现象,利用微信的联动报警,及时发现问题,以下是脚本内容!!! ping.sh #!/bin/bash ###SCRIPT_NAME:icmp ...
- python中的os.listdir()函数
os.listdir() 方法用于返回指定的文件夹包含的文件或文件夹的名字的列表.这个列表以字母顺序. 它不包括 '.' 和'..' 即使它在文件夹中. 只支持在 Unix, Windows 下使用. ...
- 001_谈阿里核心业务监控平台SunFire的技术架构
<1>阿里全球运行指挥中心(GOC)的SunFire出品 <2>在2016年双11全球购物狂欢节中,天猫全天交易额1207亿元,前30分钟每秒交易峰值17.5万笔,每秒支付峰值 ...