【问题标题】:Eureka Peer awareness example not working尤里卡同伴意识示例不起作用
【发布时间】:2016-07-13 23:00:57
【问题描述】:

我在运行 Eureka 服务器示例以了解对等感知概念时遇到问题。 我有以下 Eureka 服务:

package com.micro.eurekaserver;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableDiscoveryClient
@EnableEurekaServer
public class EurekaServerMicroServiceApplication {

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

application.yml

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

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

bootstrap.yml

spring:
  application:
    name: eureka

等/主机

127.0.0.1   peer1
127.0.0.1   peer2
localhost   peer1
localhost   peer2

当我运行这个 Eureka 服务时,我不断收到以下异常:

2016-03-26 12:19:57.708 错误 4940 --- [主要]

com.netflix.discovery.DiscoveryClient    : Can't contact any eureka nodes - possibly a security group issue?

com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect
    at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187) ~[jersey-apache-client4-1.19.jar:1.19]
    at com.sun.jersey.api.client.filter.GZIPContentEncodingFilter.handle(GZIPContentEncodingFilter.java:123) ~[jersey-client-1.19.jar:1.19]
    at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27) ~[eureka-client-1.3.7.jar:1.3.7]
    at com.sun.jersey.api.client.Client.handle(Client.java:652) ~[jersey-client-1.19.jar:1.19]
    at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682) ~[jersey-client-1.19.jar:1.19]
    at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74) ~[jersey-client-1.19.jar:1.19]
    at com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:509) ~[jersey-client-1.19.jar:1.19]
    at com.netflix.discovery.DiscoveryClient.getUrl(DiscoveryClient.java:1802) [eureka-client-1.3.7.jar:1.3.7]
    at com.netflix.discovery.DiscoveryClient.makeRemoteCall(DiscoveryClient.java:1546) [eureka-client-1.3.7.jar:1.3.7]
    at com.netflix.discovery.DiscoveryClient.makeRemoteCallWithFollowRedirect(DiscoveryClient.java:1460) [eureka-client-1.3.7.jar:1.3.7]
    at com.netflix.discovery.DiscoveryClient.makeRemoteCall(DiscoveryClient.java:1443) [eureka-client-1.3.7.jar:1.3.7]
    at com.netflix.discovery.DiscoveryClient.makeRemoteCall(DiscoveryClient.java:1394) [eureka-client-1.3.7.jar:1.3.7]

2016-03-26 12:23:09.963 ERROR 4940 --- [tbeatExecutor-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_EUREKA/KHUJEMA-PC:eureka - was unable to send heartbeat!

com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect
    at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187) ~[jersey-apache-client4-1.19.jar:1.19]
    at com.sun.jersey.api.client.filter.GZIPContentEncodingFilter.handle(GZIPContentEncodingFilter.java:123) ~[jersey-client-1.19.jar:1.19]
    at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27) ~[eureka-client-1.3.7.jar:1.3.7]
    at com.sun.jersey.api.client.Client.handle(Client.java:652) ~[jersey-client-1.19.jar:1.19]
    at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682) ~[jersey-client-1.19.jar:1.19]

我能够成功地使用单个实例运行 Eureka 服务。我只面临两个实例的问题。以下来自 github 的演示示例:[https://github.com/rcapraro/spring-cloud-sample][1]

我在日志中还注意到,tomcat 嵌入式服务器在端口 8080 而不是 8761/8762 上启动,不知道为什么?

请帮忙!

【问题讨论】:

    标签: java spring-boot netflix-eureka


    【解决方案1】:

    尝试从 Application.java 中删除 @EnableDiscoveryClient。我的看起来像这样:

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
    
    @SpringBootApplication
    @EnableEurekaServer
    public class Application {
    
        public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
        }
    }
    

    【讨论】:

      【解决方案2】:

      如果 Eureka 仍然从 8080 开始,很可能您没有通过活动的 Spring 配置文件。

      每个实例都需要启动为:

      java -Dspring.profiles.active=peer1 target/<artifact>.jar
      

      java -Dspring.profiles.active=peer2 target/<artifact>.jar
      

      顺便说一句,我建议以不同的方式启动实例,我认为这不是很好,如果您需要启动第三个实例怎么办?使用此设置,您可能需要修改 application.yml 以添加第三个配置文件,看到问题了吗?

      我最近写了一篇关于Microservices Registration and Discovery using Spring Cloud Eureka Ribbon and Feign 的博客,其中我介绍了使用Spring 配置文件在standalonepeerAware 模式下运行Eureka。在peerAware 配置文件中,我使用VM 参数传递了其他Eureka 实例的位置,因此无需更改代码即可启动新实例。它还涵盖了使用FeignRibbonRestTemplate 的负载平衡请求,并且使用Jersey 1 和Spring REST 实现了客户端。

      【讨论】:

        【解决方案3】:

        我有同样的问题,搜索了很多没有运气!

        最后,我只是将配置文件修改为配置文件,效果惊人:

        spring:
          profile: peer1
        

        而不是:

        spring:
           profiles: peer1
        

        【讨论】:

          猜你喜欢
          • 2016-08-02
          • 2017-03-26
          • 2020-05-30
          • 1970-01-01
          • 1970-01-01
          • 2018-11-11
          • 1970-01-01
          • 2017-07-22
          • 2018-04-15
          相关资源
          最近更新 更多