如何在不同主机上的eureka服务器上注册eureka客户端.春季靴 [英] How to register eureka-clients with eureka-server on different hosts. Spring-boot

查看:353
本文介绍了如何在不同主机上的eureka服务器上注册eureka客户端.春季靴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地主机上运行我的eureka服务器.我可以在运行服务的localhost上注册其他所有设备,一切正常.

I'm running my eureka-server on my localhost. I'm able to register all my other on localhost running services and everthing works like expected.

现在,我想注册一个在Linux机器上运行的服务.我的属性如下所示:

Now I want to register a service which is running on a linux machine. My properties looks like that:

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/

但是该服务无法在localhost的eureka服务器上注册. (最后,它与在localhost上运行的服务相同)

But the service is not able to register on eureka server on localhost. (At the end its the same service which runs on localhost)

我得到那些例外:

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

但是我可以从在本地主机上运行的配置服务中获取配置文件.

But I'm able to get my configuration files from my config-service running on localhost.

我需要将哪些服务从Linux计算机(客户端)注册到localhost(服务器),以将服务注册到eureka?

我使用以下注释:

服务:

@SpringBootApplication
@EnableDiscoveryClient
@EnableEurekaClient
public class MyServiceApplication {

Eureka服务器:

Eureka-Server:

@SpringBootApplication
@EnableEurekaServer
public class EurekaServiceApplication {

P.S .:相反的方法也不起作用.意味着在Linux机器上具有eureka服务器,在localhost上具有服务.获得相同的例外.

P.S.:Also the opposit way is not working. Means having eureka server on linux machine and the services on localhost. Get the same exceptions.

Eureka服务器属性:

Eureka-Server properties:

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

Edit2

testsrv是linux计算机. (172.25.82.108)

testsrv is the linux machine. (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!

Edit3:

依赖项:

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的拼写错误后,一切正常.

After changing .properties to .yml file of one of my service and corrected misspelling of defaultZone everything works like expected.

这篇关于如何在不同主机上的eureka服务器上注册eureka客户端.春季靴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆