Spring boot Eureka副本不可用

Spring boot Eureka副本不可用,spring-boot,spring-cloud,netflix-eureka,Spring Boot,Spring Cloud,Netflix Eureka,我在配置eureka副本时遇到问题: 尤里卡服务: @EnableEurekaServer @SpringBootApplication public class DiscoveryService { public static void main(String[] args) { SpringApplication.run(DiscoveryService.class, args); } } bootstrap.properties spring.appli

我在配置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

为什么会这样?

您应该在每个服务器的
应用程序.properties
文件中设置
eureka.client.register with eureka=false

我猜您的eureka不会将自己注册为
本地主机名
,这就是为什么您会在eureka仪表板中看到它们不可用的原因。Eureka经常使用这种模式,它将服务url与调用方主机名匹配以确定复制上下文

对等eureka节点从eureka服务URL列表(
eureka.client.serviceUrl
键或基于DNS)中获取到
com.netflix.eureka.cluster.PeerEurekaNodes::resolvePeerUrls
)。稍后,通过使用主机名获取副本状态,将此列表与
com.netflix.eureka.util.StatusUtil::getStatusInfo
中当前注册的eureka应用程序进行匹配


由于您的应用程序很可能没有在
localhost
中注册自身,它将被添加到不可用的副本中。

您在哪里看到有关可用和不可用副本的信息?你有没有一个复制了这个问题的示例项目,我们可以看一下?你成功地让它工作了吗?试着浏览这个博客来设置eureka副本,这可能会有帮助,所以您说我们需要设置
eureka.instance.hostname=localhost
?我将
eureka.instance.hostname=peer0
更改为
eureka.instance.hostname=machine\u ip
。我还将
eureka.client.register with eureka
设置为false,因此我必须将其更改为true。现在它起作用了。感谢
eureka.client.serviceUrl
中使用的主机名应与eureka服务器的
eureka.instance.hostname
中的主机名匹配。谢谢,兄弟。我为此挣扎了很长时间。将我的基于主机IP的配置替换为基于主机名的配置,现在它就像一个魔咒一样工作。