Eureka peers not synchronized

前端 未结 2 2105
暗喜
暗喜 2020-12-09 22:50

I\'m prototyping a set of Spring Cloud + Netflix OSS applications and have run into trouble with Eureka. In our setup, we have a Spring Cloud Config Server + Eureka Server,

相关标签:
2条回答
  • 2020-12-09 23:10

    @spencergibb's didn't mention why this hack-ish workaround is required. There is a gotcha with running more than one Eureka server on the same host. Netflix code (com.netflix.eureka.cluster.PeerEurekaNodes.isThisMyUrl) filters out the peer URLs that are on the same host. This may have been done to prevent the server registering as its own peer (I’m guessing here) but because they don’t check for the port, peer awareness doesn’t work unless the Eureka hostnames in the eureka.client.serviceUrl.defaultZone are different. The hacky workaround for this is to define unique hostnames and then map them to 127.0.0.1 in the /etc/hosts file (or its Windows equivalent).

    I've created a blog post with the details of Eureka here, that fills in some missing detail from Spring doc or Netflix blog. It is the result of several days of debugging and digging through source code.

    0 讨论(0)
  • 2020-12-09 23:12

    There were a few problems. The defaultZone needs to be in the client section as noted in the docs. The defaultZone url needs the port.

    /etc/hosts

    127.0.0.1       peer1
    127.0.0.1       peer2
    

    Peer 1 Config (Partial)

    eureka:
      instance:
        hostname: peer1
        leaseRenewalIntervalInSeconds: 3
      client:
        serviceUrl:
          defaultZone: http://peer2:8889/eureka/
    

    Peer 2 Config (Partial)

    eureka:
      dashboard:
        path: /dashboard
      instance:
        hostname: peer2
        leaseRenewalIntervalInSeconds: 3
      client:
        serviceUrl:
          defaultZone: http://peer1:8888/eureka/
      server:
        waitTimeInMsWhenSyncEmpty: 0
    

    User service config (Partial) Config port was wrong.

    spring:
      application:
        name: user-service
      cloud:
        config:
          uri: http://localhost:8888/configs
    

    You can see user-service replicated to both peer1 and peer2. I can post a PR to your code if you want.

    Peer 1

    Peer1

    Peer 2

    Peer2

    0 讨论(0)
提交回复
热议问题