我在配置 Eureka 副本时遇到问题:
Eureka 服务:
@EnableEurekaServer
@SpringBootApplication
public class DiscoveryService {
public static void main(String[] args) {
SpringApplication.run(DiscoveryService.class, args);
}
}
bootstrap.properties
spring.application.name=discovery
spring.cloud.config.uri=http://localhost:8888
我也有两个 yml 文件
对于在 8761 上运行的服务器 1
eureka.client.serviceUrl.defaultZone:http://localhost:8762/eureka/
eureka.client.registerWithEureka:false
eureka.client.fetchRegistry:false
对于在 8762 上运行的服务器 2
eureka.client.serviceUrl.defaultZone:http://localhost:8761/eureka/
eureka.client.registerWithEureka:false
eureka.client.fetchRegistry:false
我可以输入两个仪表板,但我看到两个实例都有这个:
registered-replicas http://localhost:8761/eureka/
unavailable-replicas http://localhost:8761/eureka/,
available-replicas
这是为什么 ?
最佳答案
我猜你的 Eureka 没有在 localhost
上注册自己作为它们的主机名,这就是为什么您在 eureka 仪表板中看到它们不可用的原因。 Eureka 经常使用这种模式,它将服务 url 与调用者主机名匹配来确定复制上下文。
Peer eureka 节点在 com.netflix.eureka.cluster.PeerEurekaNodes::resolvePeerUrls
中获取来自 eureka 服务 url 列表(eureka.client.serviceUrl
键或基于 DNS)。稍后,此列表与 com.netflix.eureka.util.StatusUtil::getStatusInfo
中当前注册的 eureka 应用程序匹配。通过使用主机名来获取副本状态。
由于您的应用程序很可能没有向 localhost
注册自己,它将被添加到不可用的副本中。
关于spring-boot - Eureka 副本不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40984999/