【问题标题】:Error with Eureka Server Cluster (peer awareness)Eureka 服务器集群出错(对等感知)
【发布时间】:2020-04-18 16:40:03
【问题描述】:

我的问题是关于 Spring Cloud Eureka:我正在尝试运行 Eureka Cluster(2 个节点,localhost:8761,localhost:8762), 但出现了一些错误:

  • RedirectingEurekaHttpClient:
    请求执行错误:
    endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8761/eureka/}

  • 可重试EurekaHttpClient:
    请求执行失败并显示消息:java.net.ConnectException: Connection refused

  • DiscoveryClient : DiscoveryClient_UNKNOWN/192.168.1.4:8761 - was unable to refresh its cache! status = Cannot execute request on any known server

这里是 application.yml 文件:

服务器 1:

spring:
    profiles: eureka-peer1

server:
    port: 8761

eureka:
    instance:
        hostname: eureka-peer1
    client:
        registerWithEureka: true
        fetchRegistry: true
        serviceUrl:
            defaultZone: http://eureka-peer2:8762/eureka/

服务器 2:

spring:
   profiles: eureka-peer2

server:
    port: 8762

eureka:
   instance:
       hostname: eureka-peer2
   client:
       registerWithEureka: true
       fetchRegistry: true
       serviceUrl:
           defaultZone: http://eureka-peer1:8761/eureka/ 

文件 /etc/hosts:

127.0.0.1   localhost
127.0.0.1   eureka-peer1
127.0.0.1   eureka-peer2

ErekaService1Application.javaErekaService2Application.java

package com.example.eurekaservice1;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
@EnableEurekaClient
public class EurekaService1Application {

    public static void main(String[] args) {
        SpringApplication.run(EurekaService1Application.class, args);
    }

}

删除@EnableEurekaClient 并将“registerWithEureka”和“fetchRegistry”设置为“false”会得到相同的结果。

此外,具有这些属性的独立模式会导致相同的错误:

spring:
  profiles: eureka-peer1

server:
  port: 8761

eureka:
  client:
    registerWithEureka: false
    fetchRegistry: false

这里是 pom.xml 文件,使用 start.spring.io 自动生成:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>eureka-service-1</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>eureka-service-1</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Hoxton.SR3</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

【问题讨论】:

    标签: spring-boot netflix-eureka service-discovery


    【解决方案1】:

    同时删除@EnableEurekaClient 和依赖项

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-15
      • 2015-07-07
      • 1970-01-01
      • 2020-05-22
      • 2016-04-06
      • 2013-10-13
      • 1970-01-01
      • 2021-10-09
      相关资源
      最近更新 更多