Eureka 1.1.4 版本 datacenter 的一个重要 bug

本贴最后更新于 2989 天前,其中的信息可能已经时异事殊

最近项目中在使用eureka作为服务发现框架,但是升级到1.1.4版本后,出现了启动eureka,服务每一分钟就上线下线一次的情况

github上已经向开发团队提交了bug:https://github.com/spring-cloud/spring-cloud-netflix/issues/1321

 

There seems to be a problem with public EIP address association not being correctly updated when a new AWS server starts and has a new Eureka server starting with it. When the server starts up, it correctly registers itself

 

2016-09-06 15:55:29.040  WARN 3399 --- [Thread-10] com.netflix.eureka.aws.EIPManager        : The selected EIP 54.67.102.122 is associated with another instance i-0666b391 according to AWS, hence skipping this
2016-09-06 15:55:29.628  INFO 3399 --- [Thread-10] com.netflix.eureka.aws.EIPManager        :

Associated i-25f11391 running in zone: us-west-1c to elastic IP: X.X.X.X

But, every minute after that we get the following log entry:

2016-09-06 16:24:55.568  INFO 3399 --- [Eureka-EIPBinder] c.n.e.r.PeerAwareInstanceRegistryImpl    : Got 1 instances from neighboring DS node
2016-09-06 16:24:55.568  INFO 3399 --- [Eureka-EIPBinder] c.n.e.r.PeerAwareInstanceRegistryImpl    : Renew threshold is: 1
2016-09-06 16:24:55.568  INFO 3399 --- [Eureka-EIPBinder] c.n.e.r.PeerAwareInstanceRegistryImpl    : Priming AWS connections for all replicas..
2016-09-06 16:24:55.568  INFO 3399 --- [Eureka-EIPBinder] c.n.e.r.PeerAwareInstanceRegistryImpl    : No peers needed to prime.
2016-09-06 16:24:55.568  INFO 3399 --- [Eureka-EIPBinder] c.n.e.r.PeerAwareInstanceRegistryImpl    : Changing status to UP
2016-09-06 16:24:55.713  WARN 3399 --- [Eureka-EIPBinder] com.netflix.eureka.aws.EIPManager        : The selected EIP X.X.X.X is associated with another instance i-0666b391 according to AWS, hence skipping this
2016-09-06 16:24:55.804  INFO 3399 --- [Eureka-EIPBinder] com.netflix.eureka.aws.EIPManage

Debugging this, the call to isEIPBound() is always failing, and this is because the following is always null:

String myPublicIP = ((AmazonInfo) myInfo.getDataCenterInfo()).get(MetaDataKey.publicIpv4);

It looks like there is stale datacenterinfo and it never gets refreshed (from what I can tell) and there there are no settings available to have it refreshed automatically.

The odd side affect of this, and we noticed, is that the registry continually gets wiped, and reset causing obvious potential issues down stream for our clients.

有热心网友给出了临时解决方案:


@Configuration
@Slf4j
@ConditionalOnAwsCloudEnvironment
@EnableContextInstanceData
@Import(UtilAutoConfiguration.class)
@AutoConfigureAfter(UtilAutoConfiguration.class)
public class AwsInstanceConfig {
<span class="pl-k">@Value</span>(<span class="pl-s"><span class="pl-pds">"</span>${server.port:${SERVER_PORT:${PORT:8080}}}<span class="pl-pds">"</span></span>)
<span class="pl-k">int</span> nonSecurePort;

<span class="pl-k">@Value</span>(<span class="pl-s"><span class="pl-pds">"</span>${management.port:${MANAGEMENT_PORT:${server.port:${SERVER_PORT:${PORT:8080}}}}}<span class="pl-pds">"</span></span>)
<span class="pl-k">int</span> managementPort;

<span class="pl-k">@Value</span>(<span class="pl-s"><span class="pl-pds">"</span>${eureka.instance.hostname:${EUREKA_INSTANCE_HOSTNAME:}}<span class="pl-pds">"</span></span>)
<span class="pl-smi">String</span> hostname;

<span class="pl-k">@Autowired</span>
<span class="pl-smi">ConfigurableEnvironment</span> env;


<span class="pl-k">@Bean</span>
<span class="pl-k">public</span> <span class="pl-smi">EurekaInstanceConfigBean</span> <span class="pl-en">eurekaInstanceConfigBean</span>(<span class="pl-smi">InetUtils</span> <span class="pl-v">utils</span>) {
    log<span class="pl-k">.</span>info(<span class="pl-s"><span class="pl-pds">"</span>Setting AmazonInfo on EurekaInstanceConfigBean<span class="pl-pds">"</span></span>);
    <span class="pl-k">final</span> <span class="pl-smi">EurekaInstanceConfigBean</span> instance <span class="pl-k">=</span> <span class="pl-k">new</span> <span class="pl-smi">EurekaInstanceConfigBean</span>(utils) {

        <span class="pl-k">@Scheduled</span>(<span class="pl-c1">initialDelay</span> <span class="pl-k">=</span> <span class="pl-c1">30000L</span>, <span class="pl-c1">fixedRate</span> <span class="pl-k">=</span> <span class="pl-c1">30000L</span>)
        <span class="pl-k">public</span> <span class="pl-k">void</span> <span class="pl-en">refreshInfo</span>() {
            log<span class="pl-k">.</span>debug(<span class="pl-s"><span class="pl-pds">"</span>Checking datacenter info changes<span class="pl-pds">"</span></span>);
            <span class="pl-smi">AmazonInfo</span> newInfo <span class="pl-k">=</span> <span class="pl-smi">AmazonInfo</span><span class="pl-k">.</span><span class="pl-smi">Builder</span><span class="pl-k">.</span>newBuilder()<span class="pl-k">.</span>autoBuild(<span class="pl-s"><span class="pl-pds">"</span>eureka<span class="pl-pds">"</span></span>);
            <span class="pl-k">if</span> (<span class="pl-k">!</span><span class="pl-v">this</span><span class="pl-k">.</span>getDataCenterInfo()<span class="pl-k">.</span>equals(newInfo)) {
                log<span class="pl-k">.</span>info(<span class="pl-s"><span class="pl-pds">"</span>Updating datacenterInfo to {}<span class="pl-pds">"</span></span>, newInfo);
                ((<span class="pl-smi">AmazonInfo</span>) <span class="pl-v">this</span><span class="pl-k">.</span>getDataCenterInfo())<span class="pl-k">.</span>setMetadata(newInfo<span class="pl-k">.</span>getMetadata());
            }
        }

        <span class="pl-k">private</span> <span class="pl-smi">AmazonInfo</span> <span class="pl-en">getAmazonInfo</span>() {
            <span class="pl-k">return</span> (<span class="pl-smi">AmazonInfo</span>) getDataCenterInfo();
        }

        <span class="pl-k">@Override</span>
        <span class="pl-k">public</span> <span class="pl-smi">String</span> <span class="pl-en">getHostname</span>() {
            <span class="pl-smi">AmazonInfo</span> info <span class="pl-k">=</span> getAmazonInfo();
            <span class="pl-k">final</span> <span class="pl-smi">String</span> publicHostname <span class="pl-k">=</span> info<span class="pl-k">.</span>get(<span class="pl-smi">AmazonInfo</span><span class="pl-k">.</span><span class="pl-smi">MetaDataKey</span><span class="pl-k">.</span>publicHostname);
            <span class="pl-k">return</span> <span class="pl-v">this</span><span class="pl-k">.</span>isPreferIpAddress() <span class="pl-k">?</span>
                info<span class="pl-k">.</span>get(<span class="pl-smi">AmazonInfo</span><span class="pl-k">.</span><span class="pl-smi">MetaDataKey</span><span class="pl-k">.</span>localIpv4) <span class="pl-k">:</span>
                publicHostname <span class="pl-k">==</span> <span class="pl-c1">null</span> <span class="pl-k">?</span>
                    info<span class="pl-k">.</span>get(<span class="pl-smi">AmazonInfo</span><span class="pl-k">.</span><span class="pl-smi">MetaDataKey</span><span class="pl-k">.</span>localHostname) <span class="pl-k">:</span> publicHostname;
        }

        <span class="pl-k">@Override</span>
        <span class="pl-k">public</span> <span class="pl-smi">String</span> <span class="pl-en">getHostName</span>(<span class="pl-k">final</span> <span class="pl-k">boolean</span> <span class="pl-v">refresh</span>) {
            <span class="pl-k">return</span> getHostname();
        }

        <span class="pl-k">@Override</span>
        <span class="pl-k">public</span> <span class="pl-smi">String</span> <span class="pl-en">getHomePageUrl</span>() {
            <span class="pl-k">return</span> <span class="pl-v">super</span><span class="pl-k">.</span>getHomePageUrl();
        }

        <span class="pl-k">@Override</span>
        <span class="pl-k">public</span> <span class="pl-smi">String</span> <span class="pl-en">getStatusPageUrl</span>() {
            <span class="pl-smi">String</span> scheme <span class="pl-k">=</span> getSecurePortEnabled() <span class="pl-k">?</span> <span class="pl-s"><span class="pl-pds">"</span>https<span class="pl-pds">"</span></span> <span class="pl-k">:</span> <span class="pl-s"><span class="pl-pds">"</span>http<span class="pl-pds">"</span></span>;
            <span class="pl-k">return</span> scheme <span class="pl-k">+</span> <span class="pl-s"><span class="pl-pds">"</span>://<span class="pl-pds">"</span></span> <span class="pl-k">+</span> getHostname() <span class="pl-k">+</span> <span class="pl-s"><span class="pl-pds">"</span>:<span class="pl-pds">"</span></span>
                <span class="pl-k">+</span> managementPort <span class="pl-k">+</span> getStatusPageUrlPath();
        }

        <span class="pl-k">@Override</span>
        <span class="pl-k">public</span> <span class="pl-smi">String</span> <span class="pl-en">getHealthCheckUrl</span>() {
            <span class="pl-smi">String</span> scheme <span class="pl-k">=</span> getSecurePortEnabled() <span class="pl-k">?</span> <span class="pl-s"><span class="pl-pds">"</span>https<span class="pl-pds">"</span></span> <span class="pl-k">:</span> <span class="pl-s"><span class="pl-pds">"</span>http<span class="pl-pds">"</span></span>;
            <span class="pl-k">return</span> scheme <span class="pl-k">+</span> <span class="pl-s"><span class="pl-pds">"</span>://<span class="pl-pds">"</span></span> <span class="pl-k">+</span> getHostname() <span class="pl-k">+</span> <span class="pl-s"><span class="pl-pds">"</span>:<span class="pl-pds">"</span></span>
                <span class="pl-k">+</span> managementPort <span class="pl-k">+</span> getHealthCheckUrlPath();
        }
    };
    <span class="pl-smi">AmazonInfo</span> info <span class="pl-k">=</span> <span class="pl-smi">AmazonInfo</span><span class="pl-k">.</span><span class="pl-smi">Builder</span><span class="pl-k">.</span>newBuilder()<span class="pl-k">.</span>autoBuild(<span class="pl-s"><span class="pl-pds">"</span>eureka<span class="pl-pds">"</span></span>);
    log<span class="pl-k">.</span>info(<span class="pl-s"><span class="pl-pds">"</span>Info: {}<span class="pl-pds">"</span></span>, info);
    instance<span class="pl-k">.</span>setDataCenterInfo(info);
    instance<span class="pl-k">.</span>setNonSecurePort(<span class="pl-v">this</span><span class="pl-k">.</span>nonSecurePort);
    instance<span class="pl-k">.</span>setInstanceId(getDefaultInstanceId(<span class="pl-v">this</span><span class="pl-k">.</span>env));
    <span class="pl-k">if</span> (<span class="pl-v">this</span><span class="pl-k">.</span>managementPort <span class="pl-k">!=</span> <span class="pl-v">this</span><span class="pl-k">.</span>nonSecurePort <span class="pl-k">&amp;&amp;</span> <span class="pl-v">this</span><span class="pl-k">.</span>managementPort <span class="pl-k">!=</span> <span class="pl-c1">0</span>) {
        <span class="pl-k">if</span> (<span class="pl-smi">StringUtils</span><span class="pl-k">.</span>hasText(<span class="pl-v">this</span><span class="pl-k">.</span>hostname)) {
            instance<span class="pl-k">.</span>setHostname(<span class="pl-v">this</span><span class="pl-k">.</span>hostname);
        }
    }

    <span class="pl-k">return</span> instance;
}

}

netfix的贡献者已经在修复这个bug,预计下一个版本能解决:https://github.com/Netflix/eureka/pull/843

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...

推荐标签 标签

  • JavaScript

    JavaScript 一种动态类型、弱类型、基于原型的直译式脚本语言,内置支持类型。它的解释器被称为 JavaScript 引擎,为浏览器的一部分,广泛用于客户端的脚本语言,最早是在 HTML 网页上使用,用来给 HTML 网页增加动态功能。

    729 引用 • 1327 回帖
  • CentOS

    CentOS(Community Enterprise Operating System)是 Linux 发行版之一,它是来自于 Red Hat Enterprise Linux 依照开放源代码规定释出的源代码所编译而成。由于出自同样的源代码,因此有些要求高度稳定的服务器以 CentOS 替代商业版的 Red Hat Enterprise Linux 使用。两者的不同在于 CentOS 并不包含封闭源代码软件。

    238 引用 • 224 回帖
  • ZooKeeper

    ZooKeeper 是一个分布式的,开放源码的分布式应用程序协调服务,是 Google 的 Chubby 一个开源的实现,是 Hadoop 和 HBase 的重要组件。它是一个为分布式应用提供一致性服务的软件,提供的功能包括:配置维护、域名服务、分布式同步、组服务等。

    59 引用 • 29 回帖 • 5 关注
  • 代码片段

    代码片段分为 CSS 与 JS 两种代码,添加在 [设置 - 外观 - 代码片段] 中,这些代码会在思源笔记加载时自动执行,用于改善笔记的样式或功能。

    用户在该标签下分享代码片段时需在帖子标题前添加 [css] [js] 用于区分代码片段类型。

    69 引用 • 372 回帖
  • 外包

    有空闲时间是接外包好呢还是学习好呢?

    26 引用 • 232 回帖 • 2 关注
  • 服务器

    服务器,也称伺服器,是提供计算服务的设备。由于服务器需要响应服务请求,并进行处理,因此一般来说服务器应具备承担服务并且保障服务的能力。

    125 引用 • 588 回帖
  • 支付宝

    支付宝是全球领先的独立第三方支付平台,致力于为广大用户提供安全快速的电子支付/网上支付/安全支付/手机支付体验,及转账收款/水电煤缴费/信用卡还款/AA 收款等生活服务应用。

    29 引用 • 347 回帖
  • Android

    Android 是一种以 Linux 为基础的开放源码操作系统,主要使用于便携设备。2005 年由 Google 收购注资,并拉拢多家制造商组成开放手机联盟开发改良,逐渐扩展到到平板电脑及其他领域上。

    334 引用 • 323 回帖 • 1 关注
  • Kotlin

    Kotlin 是一种在 Java 虚拟机上运行的静态类型编程语言,由 JetBrains 设计开发并开源。Kotlin 可以编译成 Java 字节码,也可以编译成 JavaScript,方便在没有 JVM 的设备上运行。在 Google I/O 2017 中,Google 宣布 Kotlin 成为 Android 官方开发语言。

    19 引用 • 33 回帖 • 63 关注
  • danl
    132 关注
  • VirtualBox

    VirtualBox 是一款开源虚拟机软件,最早由德国 Innotek 公司开发,由 Sun Microsystems 公司出品的软件,使用 Qt 编写,在 Sun 被 Oracle 收购后正式更名成 Oracle VM VirtualBox。

    10 引用 • 2 回帖 • 6 关注
  • WiFiDog

    WiFiDog 是一套开源的无线热点认证管理工具,主要功能包括:位置相关的内容递送;用户认证和授权;集中式网络监控。

    1 引用 • 7 回帖 • 587 关注
  • CSS

    CSS(Cascading Style Sheet)“层叠样式表”是用于控制网页样式并允许将样式信息与网页内容分离的一种标记性语言。

    198 引用 • 550 回帖
  • SOHO

    为成为自由职业者在家办公而努力吧!

    7 引用 • 55 回帖 • 19 关注
  • SSL

    SSL(Secure Sockets Layer 安全套接层),及其继任者传输层安全(Transport Layer Security,TLS)是为网络通信提供安全及数据完整性的一种安全协议。TLS 与 SSL 在传输层对网络连接进行加密。

    70 引用 • 193 回帖 • 431 关注
  • 安全

    安全永远都不是一个小问题。

    199 引用 • 816 回帖
  • CloudFoundry

    Cloud Foundry 是 VMware 推出的业界第一个开源 PaaS 云平台,它支持多种框架、语言、运行时环境、云平台及应用服务,使开发人员能够在几秒钟内进行应用程序的部署和扩展,无需担心任何基础架构的问题。

    5 引用 • 18 回帖 • 167 关注
  • Vue.js

    Vue.js(读音 /vju ː/,类似于 view)是一个构建数据驱动的 Web 界面库。Vue.js 的目标是通过尽可能简单的 API 实现响应的数据绑定和组合的视图组件。

    266 引用 • 665 回帖
  • 设计模式

    设计模式(Design pattern)代表了最佳的实践,通常被有经验的面向对象的软件开发人员所采用。设计模式是软件开发人员在软件开发过程中面临的一般问题的解决方案。这些解决方案是众多软件开发人员经过相当长的一段时间的试验和错误总结出来的。

    200 引用 • 120 回帖
  • 工具

    子曰:“工欲善其事,必先利其器。”

    286 引用 • 729 回帖
  • Windows

    Microsoft Windows 是美国微软公司研发的一套操作系统,它问世于 1985 年,起初仅仅是 Microsoft-DOS 模拟环境,后续的系统版本由于微软不断的更新升级,不但易用,也慢慢的成为家家户户人们最喜爱的操作系统。

    222 引用 • 473 回帖 • 1 关注
  • 导航

    各种网址链接、内容导航。

    40 引用 • 173 回帖
  • Jenkins

    Jenkins 是一套开源的持续集成工具。它提供了非常丰富的插件,让构建、部署、自动化集成项目变得简单易用。

    53 引用 • 37 回帖
  • V2Ray
    1 引用 • 15 回帖 • 1 关注
  • Laravel

    Laravel 是一套简洁、优雅的 PHP Web 开发框架。它采用 MVC 设计,是一款崇尚开发效率的全栈框架。

    20 引用 • 23 回帖 • 721 关注
  • 区块链

    区块链是分布式数据存储、点对点传输、共识机制、加密算法等计算机技术的新型应用模式。所谓共识机制是区块链系统中实现不同节点之间建立信任、获取权益的数学算法 。

    91 引用 • 751 回帖 • 2 关注
  • jQuery

    jQuery 是一套跨浏览器的 JavaScript 库,强化 HTML 与 JavaScript 之间的操作。由 John Resig 在 2006 年 1 月的 BarCamp NYC 上释出第一个版本。全球约有 28% 的网站使用 jQuery,是非常受欢迎的 JavaScript 库。

    63 引用 • 134 回帖 • 724 关注