How to config multiple Eureka Servers from client in Spring Cloud

36,334

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

eureka.client.serviceUrl.defaultZone=http://<peer1host>:<peer1port>/eureka,http://<peer2host>:<peer2port>/eureka
Share:
36,334
user3006967
Author by

user3006967

Updated on June 13, 2021

Comments

  • user3006967
    user3006967 about 3 years

    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/
    

    And in Eureka Server 2, I can have:

    spring:
      profiles: peer2
    eureka:
      instance:
        hostname: peer2
      client:
        serviceUrl:
          defaultZone: http://peer1/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}
    

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

    Thanks