Eureka peers not synchronized

亡梦爱人 提交于 2019-11-29 02:33:37

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

Peer 2

@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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!