[英]Eureka client fail to fetch registry from (clustered) peer aware eureka servers
[英]Eureka Peer awareness example not working
我在運行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
etc / hosts文件
127.0.0.1 peer1
127.0.0.1 peer2
localhost peer1
localhost peer2
當我運行此Eureka服務時,我不斷收到以下異常:
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]
我可以單實例成功運行Eureka服務。 我只遇到兩個實例的問題。 以下是來自github的演示示例:[ https://github.com/rcapraro/spring-cloud-sample] [1 ]
我在日志中還注意到,tomcat嵌入式服務器是從端口8080而不是8761/8762開始的,不確定為什么嗎?
請幫忙!
嘗試從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);
}
}
如果Eureka
最有可能仍在8080上啟動,則說明您未通過有效的Spring
配置文件。
每個實例都需要以以下方式啟動:
java -Dspring.profiles.active=peer1 target/<artifact>.jar
和
java -Dspring.profiles.active=peer2 target/<artifact>.jar
順便說一句,我建議以不同的方式啟動實例,我認為這樣做的伸縮性不太好,如果您需要啟動第三個實例該怎么辦? 使用此設置,您可能需要修改application.yml
以添加第3個配置文件,看到問題了嗎?
我最近在博客中發布了有關使用Spring Cloud Eureka Ribbon和Feign進行微服務注冊和發現的文章 ,其中介紹了peerAware
使用Spring
配置文件以standalone
模式和peerAware
模式運行Eureka
。 在peerAware
配置文件中,我使用VM參數傳遞了其他Eureka
實例的位置,因此無需更改代碼即可啟動新實例。 它還涵蓋了使用Feign
, Ribbon
和RestTemplate
進行負載平衡的請求,並且使用Jersey
1和Spring
REST實現了客戶端。
我遇到了同樣的問題,沒有運氣就做了很多搜索!
最后,我只是將個人資料修改為個人資料,它出奇地起作用:
spring:
profile: peer1
而不是:
spring:
profiles: peer1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.