尤里卡(Eureka)同行未同步 [英] Eureka peers not synchronized
问题描述
我正在制作一组Spring Cloud + Netflix OSS应用程序的原型,并且遇到了Eureka的麻烦.在我们的设置中,我们有一个Spring Cloud Config Server + Eureka Server,然后是两个利用该服务器组件进行引导和服务发现的模块.
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, and then 2 modules that utilize that server component for bootstrapping and service discovery.
我遇到的问题是,如果我启动了两个Eureka Server实例并尝试将它们配对(基于
The problem I run into is that if I spin up 2 instances of the Eureka Server and try to pair them (based on the Two Peer Aware Eureka Servers in the docs) they don't synchronize with each other. See configs below and/or the code on GitHub.
本质上,Peer1启动并看起来不错. Peer2将启动,并且看起来不错,并且两个对等方在服务中彼此展示.但是,如果"UserService"模块启动并向Peer1注册,Peer2将永远看不到它.如果然后旋转指向Peer2的"Web"模块,它将永远无法解析UserService.他们基本上是孤立地行动.
Essentially, Peer1 starts up and looks fine. Peer2 will startup and look fine, with both peers showing each other in the services. However, if the "UserService" module spins up and registers itself with Peer1, Peer2 will never see it. If we then spin up the "Web" module pointing to Peer2, it can never resolve the UserService. They basically act in isolation.
我尝试了几种在服务器和Eureka服务器实例上同时设置serviceUrl
的组合,但无济于事.我只是在配置错误的东西吗?
I've tried several combinations of setting the serviceUrl
both on the server and the instance of the Eureka servers but to no avail. Am I just configuring things wrong?
对等1/默认配置:
server:
port: 8888
eureka:
dashboard:
path: /dashboard
instance:
hostname: peer1
leaseRenewalIntervalInSeconds: 3
client:
serviceUrl:
defaultZone: ${eureka.server.serviceUrl:http://localhost:${server.port}/eureka/}
server:
serviceUrl:
defaultZone: http://localhost:${server.port}/eureka/
peer2: http://peer2/eureka/
waitTimeInMsWhenSyncEmpty: 0
spring:
application:
name: demo-config-service
profiles:
active: native
# required for Spring Cloud Bus
rabbitmq:
host: ${DOCKER_IP:192.168.59.103}
port: 5672
username: guest
password: guest
virtualHost: /
cloud:
config:
server:
prefix: /configs
native:
searchLocations: /Users/dave/workspace/oss/distributed-spring/modules/config-server/src/main/resources/testConfigs
# git :
# uri: https://github.com/joshlong/microservices-lab-configuration
对等2配置:
server:
port: 8889
eureka:
dashboard:
path: /dashboard
instance:
hostname: peer2
leaseRenewalIntervalInSeconds: 3
client:
serviceUrl:
defaultZone: ${eureka.server.serviceUrl:http://localhost:${server.port}/eureka/}
server:
serviceUrl:
defaultZone: http://localhost:8888/eureka/
peer1: http://peer1/eureka/
waitTimeInMsWhenSyncEmpty: 0
spring:
application:
name: demo-config-service
profiles:
active: native
# required for Spring Cloud Bus
rabbitmq:
host: ${DOCKER_IP:192.168.59.103}
port: 5672
username: guest
password: guest
virtualHost: /
cloud:
config:
server:
prefix: /configs
native:
searchLocations: /Users/dave/workspace/oss/distributed-spring/modules/config-server/src/main/resources/testConfigs
# git :
# uri: https://github.com/joshlong/microservices-lab-configuration
推荐答案
有一些问题.如文档中所述,defaultZone
必须位于客户端部分. defaultZone
网址需要端口.
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
对等1配置(部分)
eureka:
instance:
hostname: peer1
leaseRenewalIntervalInSeconds: 3
client:
serviceUrl:
defaultZone: http://peer2:8889/eureka/
对等2配置(部分)
eureka:
dashboard:
path: /dashboard
instance:
hostname: peer2
leaseRenewalIntervalInSeconds: 3
client:
serviceUrl:
defaultZone: http://peer1:8888/eureka/
server:
waitTimeInMsWhenSyncEmpty: 0
用户服务配置(部分).配置端口错误.
spring:
application:
name: user-service
cloud:
config:
uri: http://localhost:8888/configs
您可以看到同时复制到peer1和peer2的用户服务.如果您愿意,我可以在您的代码中发布PR.
You can see user-service replicated to both peer1 and peer2. I can post a PR to your code if you want.
对等1
对等2
这篇关于尤里卡(Eureka)同行未同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!