本文介绍了如何在Spring Cloud中从客户端配置多个Eureka服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从春季文档中,我看到我们可以一起拥有对等eureka服务器,因此对于Eureka1,在application.yml中,我可以拥有:

From the spring doc, I see we can have peer eureka server together, so for Eureka1, in application.yml, I can have:

spring:
  profiles: peer1
eureka:
  instance:
    hostname: peer1
  client:
    serviceUrl:
      defaultZone: http://peer2/eureka/

在Eureka Server 2中,我可以拥有:

And in Eureka Server 2, I can have:

spring:
  profiles: peer2
eureka:
  instance:
    hostname: peer2
  client:
    serviceUrl:
      defaultZone: http://peer1/eureka/

现在这两个eureka服务器可以互相识别,这很好.但是,现在正在配置客户端,当他们再次注册Eureka时,该怎么做?

Now these two eureka servers are aware each other, it is good.BUT, now in configuring client, when they register again Eureka, how to do this?

在我的客户应用程序中,我有:

In my client application, I have:

eureka:
      instance:
        hostname: ${host.instance.name:localhost}
        nonSecurePort: ${host.instance.port:8080}
        leaseRenewalIntervalInSeconds: 5 #default is 30, recommended to keep default
        metadataMap:
          instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}
      client:
        serviceUrl:
          defaultZone: http://(eurekaServerHost):8761/eureka/

    server:
      port: ${host.instance.port:8080}

所以现在我的问题是我应该在客户端application.yml中使用peer1还是peer2作为EurekaServerHost?

So now my question is shall I use peer1 or peer2 as EurekaServerHost in the client application.yml?

谢谢

推荐答案

eureka.client.serviceUrl.defaultZone中使用逗号分隔的对等列表.

Use a comma separated list of peers in eureka.client.serviceUrl.defaultZone.

eureka.client.serviceUrl.defaultZone=http://<peer1host>:<peer1port>/eureka,http://<peer2host>:<peer2port>/eureka

这篇关于如何在Spring Cloud中从客户端配置多个Eureka服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-26 11:32