简体   繁体   English

Spring 启动 (Netflix) 尤里卡副本

[英]Spring boot (Netflix) Eureka replicas

I can't configure Eureka with a replica.我无法使用副本配置 Eureka。 I have two instances of Eureka Server running on the same laptop.我有两个 Eureka Server 实例在同一台笔记本电脑上运行。 It always see each other as unavailable-replica .它总是将彼此视为不可用的副本

The is what the Eureka panel says: Eureka message这就是 Eureka 小组所说的: Eureka message

These are the application.yml files:这些是 application.yml 文件:

------------------------------
server:
    port: 8761

eureka:   
    instance:
        hostname: eurekaserver1
    client:
       registerWithEureka: false
       fetchRegistry: false
       serviceUrl:
          defaultZone: http://localhost:8762/eureka

--------------------------------

server:
    port: 8762

eureka:
    instance:
       hostname: eurekaserver2
    client:
       registerWithEureka: false
       fetchRegistry: false
       serviceUrl:
          defaultZone: http://localhost:8761/eureka

--------------------------------

You need to have different hostnames and the same application name(appname).您需要有不同的主机名和相同的应用程序名称(appname)。 Here is a detailed guide on Eureka's peer awareness.这是有关Eureka 同伴意识的详细指南。

I'm using the following config and it works fine, I think it does not work since you have set registerWithEureka and fetchRegistry to false .我正在使用以下配置,它工作正常,我认为它不起作用,因为您已将registerWithEurekafetchRegistry设置为false

Node.1:节点 1:

server:
    port: 8761

eureka:
  instance:
    appname: discovery-cluster
    hostname: discovery-node1
    preferIpAddress: true
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://${eureka.replicas.node.host}:${eureka.replicas.node.port}/eureka/
  replicas:
    node:
      host: ${node2.ip}
      port: 8762

Node.2:节点 2:

server:
    port: 8762

eureka:
  instance:
    appname: discovery-cluster
    hostname: discovery-node2
    preferIpAddress: true
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://${eureka.replicas.node.host}:${eureka.replicas.node.port}/eureka/
  replicas:
    node:
      host: ${node1.ip}
      port: 8761

Actually it's the combination of both @indika and @Ashraf answers that will make it work:实际上,这是@indika 和@Ashraf 答案的结合才能使其发挥作用:

  1. You need to use hostnames, for example adding XXXX peer1 peer2 on your \etc\hosts file, where XXXX needs to be your laptop's IP address, not 127.0.0.1 .您需要使用主机名,例如在您的\etc\hosts文件中添加XXXX peer1 peer2 ,其中XXXX需要是您的笔记本电脑的 IP 地址,而不是 127.0.0.1
  2. You need to remove registerWithEureka: false from your application.yml file.您需要从application.yml文件中删除registerWithEureka: false The Eureka servers have to register themselves with each other. Eureka 服务器必须相互注册。

Following the documentation here and adding the two alias peer1 and peer2 on my /etc/hosts , I managed to configure two Eureka servers on my laptop with valid available-replicas using the application.yml below:按照此处的文档并在我的/etc/hosts添加两个别名peer1peer2 ,我设法使用下面的application.yml在我的笔记本电脑上配置了两个具有有效可用副本的 Eureka 服务器:

---
server:
  port: 8081
spring:
  profiles: peer1
eureka:
  instance:
    hostname: peer1
  client:
    serviceUrl:
      defaultZone: http://peer2:8082/eureka/

---
server:
  port: 8082
spring:
  profiles: peer2
eureka:
  instance:
    hostname: peer2
  client:
    serviceUrl:
      defaultZone: http://peer1:8081/eureka/

You can run both instances using the two different profiles as follows:您可以使用两个不同的配置文件运行这两个实例,如下所示:

$ java -jar -Dspring.profiles.active=peer1 build/libs/registry.jar
$ java -jar -Dspring.profiles.active=peer2 build/libs/registry.jar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM