简体   繁体   English

Eureka Peer感知示例不起作用

[英]Eureka Peer awareness example not working

I am facing problem while running Eureka server example to understand peer awareness concept. 我在运行Eureka服务器示例以了解对等感知概念时遇到问题。 I have following Eureka service: 我有以下尤里卡服务:

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 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 bootstrap.yml

spring:
  application:
    name: eureka

etc/hosts etc / hosts文件

127.0.0.1   peer1
127.0.0.1   peer2
localhost   peer1
localhost   peer2

When I am running this Eureka service, I am continuously getting following exception: 当我运行此Eureka服务时,我不断收到以下异常:

2016-03-26 12:19:57.708 ERROR 4940 --- [ main] 2016-03-26 12:19:57.708错误4940 --- [main]

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]

I am successfully able to run Eureka service with single instance. 我可以单实例成功运行Eureka服务。 I am only facing issues for two instances. 我只遇到两个实例的问题。 Following demo example from github: [ https://github.com/rcapraro/spring-cloud-sample][1] 以下是来自github的演示示例:[ https://github.com/rcapraro/spring-cloud-sample] [1 ]

What I also noticed in logs is tomcat embeded server is getting started on port-8080 instead of 8761/8762, not sure why? 我在日志中还注意到,tomcat嵌入式服务器是从端口8080而不是8761/8762开始的,不确定为什么吗?

Please help! 请帮忙!

Try removing the @EnableDiscoveryClient from your Application.java. 尝试从Application.java中删除@EnableDiscoveryClient。 Mine looks like this: 我的看起来像这样:

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);
    }
}

If Eureka is still starting on 8080 most-likely you are not passing the active Spring profile. 如果Eureka最有可能仍在8080上启动,则说明您未通过有效的Spring配置文件。

Each instance would need to be started as: 每个实例都需要以以下方式启动:

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

and

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

BTW, I would suggest to start instances in a different way, I don't think this scales very well, what if you need to start a 3rd instance? 顺便说一句,我建议以不同的方式启动实例,我认为这样做的伸缩性不太好,如果您需要启动第三个实例该怎么办? With this setup you probably need to modify application.yml to add a 3rd profile, see the issue? 使用此设置,您可能需要修改application.yml以添加第3个配置文件,看到问题了吗?

I recently blogged about Microservices Registration and Discovery using Spring Cloud Eureka Ribbon and Feign where I covered running Eureka in standalone and peerAware modes using Spring profiles. 我最近在博客中发布了有关使用Spring Cloud Eureka Ribbon和Feign进行微服务注册和发现的文章 ,其中介绍了peerAware使用Spring配置文件以standalone模式和peerAware模式运行Eureka In the peerAware profile, I pass the location of the other Eureka instances using a VM argument, so no need to change the code to start new instances. peerAware配置文件中,我使用VM参数传递了其他Eureka实例的位置,因此无需更改代码即可启动新实例。 It also covers load-balancing requests using Feign , Ribbon and RestTemplate and the clients are implemented using Jersey 1 and Spring REST. 它还涵盖了使用FeignRibbonRestTemplate进行负载平衡的请求,并且使用Jersey 1和Spring REST实现了客户端。

I had the same issue,searched a lot with no luck! 我遇到了同样的问题,没有运气就做了很多搜索!

Finally, I just modified profiles to profile, it surprisingly worked: 最后,我只是将个人资料修改为个人资料,它出奇地起作用:

spring:
  profile: peer1

Rather than: 而不是:

spring:
   profiles: peer1

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

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