java - 如何在不同主机上向 eureka-server 注册 eureka-clients。 Spring Boot

标签 java spring spring-boot netflix-eureka

我在我的本地主机上运行我的 Eureka 服务器。我能够在本地主机运行的服务上注册我的所有其他服务,一切都按预期工作。

现在我想注册一个在 linux 机器上运行的服务。我的属性看起来像这样:

spring.application.name=myService-service
spring.cloud.config.uri=http://myMachine.domain.lan:8888
server.port=8002
eureka.client.service-url.default-zone=http://myMachine.domain.lan:8761/eureka/

但该服务无法在本地主机上的 Eureka 服务器上注册。 (最后它是在本地主机上运行的相同服务)

我得到那些异常:

java.net.ConnectException: Connection refused
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server

但我能够从在本地主机上运行的配置服务获取我的配置文件。

从 linux 机器(客户端)到本地主机(服务器)将我的服务注册到 eureka 需要哪些配置?

我使用这个注解:

服务:

@SpringBootApplication
@EnableDiscoveryClient
@EnableEurekaClient
public class MyServiceApplication {

Eureka 服务器:

@SpringBootApplication
@EnableEurekaServer
public class EurekaServiceApplication {

P.S.: 反之亦然。意味着在 linux 机器上有 eureka 服务器,在本地主机上有服务。获取相同的异常。

编辑1:

Eureka 服务器属性:

spring.application.name=eureka-service
spring.cloud.config.uri=http://myMachine.domain.lan:8888
server.port=8761
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.instance.hostname=KBHWS242.myDomain.lan
eureka.instance.prefer-ip-address=true

编辑2:

testsrv 是 linux 机器。 (172.25.82.108)

2016-08-31 09:17:01.912  INFO 27105 --- [           main] com.netflix.discovery.DiscoveryClient    : Starting heartbeat executor: renew interval is: 30
2016-08-31 09:17:01.919  INFO 27105 --- [           main] c.n.discovery.InstanceInfoReplicator     : InstanceInfoReplicator onDemand update allowed rate per min is 4
2016-08-31 09:17:01.923  INFO 27105 --- [           main] com.netflix.discovery.DiscoveryClient    : Discovery Client initialized at timestamp 1472627821923 with initial instances count: 0
2016-08-31 09:17:02.068  INFO 27105 --- [           main] c.n.e.EurekaDiscoveryClientConfiguration : Registering application reservation-service with eureka with status UP
2016-08-31 09:17:02.070  INFO 27105 --- [           main] com.netflix.discovery.DiscoveryClient    : Saw local status change event StatusChangeEvent [timestamp=1472627822070, current=UP, previous=STARTING]
2016-08-31 09:17:02.073  INFO 27105 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_RESERVATION-SERVICE/testsrv1.myDomain.lan:reservation-service:8002: registering service...
2016-08-31 09:17:02.173 ERROR 27105 --- [nfoReplicator-0] c.n.d.s.t.d.RedirectingEurekaHttpClient  : Request execution error

com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused

Caused by: java.net.ConnectException: Connection refused


2016-08-31 09:17:02.174  WARN 27105 --- [nfoReplicator-0] c.n.d.s.t.d.RetryableEurekaHttpClient    : Request execution failure
2016-08-31 09:17:02.175  WARN 27105 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_RESERVATION-SERVICE/testsrv1.myDomain.lan:reservation-service:8002 - registration failed Cannot execute request on any known server

com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server


2016-08-31 09:17:02.175  WARN 27105 --- [nfoReplicator-0] c.n.discovery.InstanceInfoReplicator     : There was a problem with the instance info replicator

com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server

2016-08-31 09:17:02.594  INFO 27105 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8002 (http)
2016-08-31 09:17:02.596  INFO 27105 --- [           main] c.n.e.EurekaDiscoveryClientConfiguration : Updating port to 8002
2016-08-31 09:17:04.134  INFO 27105 --- [           main] o.h.h.i.QueryTranslatorFactoryInitiator  : HHH000397: Using ASTQueryTranslatorFactory
2016-08-31 09:17:04.659  INFO 27105 --- [           main] a.e.ReservationServiceApplication        : Started ReservationServiceApplication in 44.893 seconds (JVM running for 47.272)
2016-08-31 09:17:31.913  INFO 27105 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient    : Disable delta property : false
2016-08-31 09:17:31.914  INFO 27105 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient    : Single vip registry refresh property : null
2016-08-31 09:17:31.914  INFO 27105 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient    : Force full registry fetch : false
2016-08-31 09:17:31.914  INFO 27105 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient    : Application is null : false
2016-08-31 09:17:31.914  INFO 27105 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient    : Registered Applications size is zero : true
2016-08-31 09:17:31.914  INFO 27105 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient    : Application version is -1: true
2016-08-31 09:17:31.914  INFO 27105 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient    : Getting all instance registry info from the eureka server
2016-08-31 09:17:31.917 ERROR 27105 --- [freshExecutor-0] c.n.d.s.t.d.RedirectingEurekaHttpClient  : Request execution error

com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused

Caused by: java.net.ConnectException: Connection refused

2016-08-31 09:17:31.917  WARN 27105 --- [freshExecutor-0] c.n.d.s.t.d.RetryableEurekaHttpClient    : Request execution failure
2016-08-31 09:17:31.918 ERROR 27105 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_RESERVATION-SERVICE/testsrv1.myDomain.lan:reservation-service:8002 - was unable to refresh its cache! status = Cannot execute request on any known server

com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server

2016-08-31 09:17:31.924 ERROR 27105 --- [tbeatExecutor-0] c.n.d.s.t.d.RedirectingEurekaHttpClient  : Request execution error

com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused

Caused by: java.net.ConnectException: Connection refused

DiscoveryClient_RESERVATION-SERVICE/testsrv1.myDomain.lan:reservation-service:8002 - was unable to send heartbeat!

编辑3:

依赖关系:

Maven: org.springframework.cloud:spring-cloud-commons:1.1.1.RELEASE
Maven: org.springframework.cloud:spring-cloud-config-client:1.1.2.RELEASE
Maven: org.springframework.cloud:spring-cloud-context:1.1.1.RELEASE
Maven: org.springframework.cloud:spring-cloud-netflix-core:1.1.5.RELEASE
Maven: org.springframework.cloud:spring-cloud-netflix-eureka-client:1.1.5.RELEASE
Maven: org.springframework.cloud:spring-cloud-starter:1.1.1.RELEASE
Maven: org.springframework.cloud:spring-cloud-starter-archaius:1.1.5.RELEASE
Maven: org.springframework.cloud:spring-cloud-starter-config:1.1.3.RELEASE
Maven: org.springframework.cloud:spring-cloud-starter-eureka:1.1.5.RELEASE
Maven: org.springframework.cloud:spring-cloud-starter-ribbon:1.1.5.RELEASE


Maven: org.springframework.cloud:spring-cloud-netflix-eureka-server:1.1.5.RELEASE

最佳答案

将我的一项服务的 .properties 更改为 .yml 文件并更正 defaultZone 的拼写错误后,一切都按预期进行。

关于java - 如何在不同主机上向 eureka-server 注册 eureka-clients。 Spring Boot ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39242635/

相关文章:

java - JPA 为 postgres 保留的关键字

java - 使用正则表达式 (java) 的 ASCII 字符检查

java - 为什么我不能将 A 的实例添加到声明为 Set< 的集合中?延伸 A>?

java - 如何在 Eclipse 中从给定的物理 wsdl 文件生成 Web 服务客户端

spring - @Indexed 不适用于 spring 数据 cassandra

spring - 在Spring MongoDB存储库中将$ slice与Kotlin中的@Query一起使用时,注释参数错误

java - Angular 和 spring boot 没有绑定(bind)在一起,所以它们在同一个端口 8080 上运行

java - 我们可以使用 MongoRespository 进行 findByNameAndPassword() 这种类型的查询吗?

java - 可以为每个 SpringbootTest 注解加载特定的 data.sql

java - 为什么我的 @Scheduled Spring Boot 任务在 Azure 中运行不一致?