我正在对一组 Spring Cloud + Netflix OSS 应用程序进行原型(prototype)设计,但在使用 Eureka 时遇到了麻烦。在我们的设置中,我们有一个 Spring Cloud Config Server + Eureka Server,然后是 2 个利用该服务器组件进行引导和服务发现的模块。
我遇到的问题是,如果我启动 2 个 Eureka Server 实例并尝试将它们配对(基于 the docs 中的 两个 Peer Aware Eureka Servers )它们不会相互同步.请参阅下面的配置和/或 the code on GitHub .
本质上,Peer1 启动并且看起来很好。 Peer2 将启动并且看起来很好,两个对等点在服务中相互显示。但是,如果“UserService”模块启动并向 Peer1 注册自身,Peer2 将永远看不到它。如果我们随后启动指向 Peer2 的“Web”模块,它永远无法解析 UserService。他们基本上是孤立地行动。
我尝试了几种设置 serviceUrl
的组合。在服务器和 Eureka 服务器的实例上,但无济于事。我只是配置错误吗?
对等体 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
url 需要端口。
/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。
同行 1
同行 2
关于spring-cloud - Eureka 对等点未同步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30288959/