我有一个独立的spring boot应用程序(版本 - 1.5.9.RELEASE),它是一个客户端注册到Eureka服务器。 spring boot应用程序所需的applicait.yml文件如下所示
spring:
application:
admin:
jmx-name: hello-server
server:
port: 8070
address: 10.12.134.54
eureka:
client:
register-with-eureka: true
fetch-registry: true
availability-zones:
local: http://10.12.134.54:8070/eureka/
instance:
prefer-ip-address: true
hostname: localhost
但是当我启动应用程序时,它无法向Eureka服务器注册,因为它使用的是hostname:port而不是ipaddress:port。
有谁能建议我如何摆脱这个问题?
这是错误日志
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) ~[na:1.8.0_66]
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source) ~[na:1.8.0_66]
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) ~[na:1.8.0_66]
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) ~[na:1.8.0_66]
at java.net.AbstractPlainSocketImpl.connect(Unknown Source) ~[na:1.8.0_66]
at java.net.PlainSocketImpl.connect(Unknown Source) ~[na:1.8.0_66]
at java.net.SocksSocketImpl.connect(Unknown Source) ~[na:1.8.0_66]
at java.net.Socket.connect(Unknown Source) ~[na:1.8.0_66]
at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:121) ~[httpclient-4.5.3.jar:4.5.3]
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180) ~[httpclient-4.5.3.jar:4.5.3]
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:144) ~[httpclient-4.5.3.jar:4.5.3]
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:134) ~[httpclient-4.5.3.jar:4.5.3]
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:610) ~[httpclient-4.5.3.jar:4.5.3]
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:445) ~[httpclient-4.5.3.jar:4.5.3]
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835) ~[httpclient-4.5.3.jar:4.5.3]
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:118) ~[httpclient-4.5.3.jar:4.5.3]
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56) ~[httpclient-4.5.3.jar:4.5.3]
at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:173) ~[jersey-apache-client4-1.19.1.jar:1.19.1]
... 72 common frames omitted
2017-12-21 18:23:05.031 WARN 15652 --- [ main] c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution failed with message: java.net.ConnectException: Connection refused: connect
2017-12-21 18:23:05.033 ERROR 15652 --- [ main] com.netflix.discovery.DiscoveryClient : DiscoveryClient_UNKNOWN/MOB80737.hq.k.grp:8070 - 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
at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:111) ~[eureka-client-1.7.0.jar:1.7.0]
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134) ~[eureka-client-1.7.0.jar:1.7.0]
答案 0 :(得分:0)
以下是我的Eureka客户端配置:
eureka:
client:
serviceUrl:
defaultZone: ${DISCOVERY_URL:http://discovery-service:8761}/eureka/
registry-fetch-interval-seconds: 6
instance-info-replication-interval-seconds: 6
register-with-eureka: true
fetch-registry: true
heartbeat-executor-thread-pool-size: 5
eureka-service-url-poll-interval-seconds: 10
instance:
leaseRenewalIntervalInSeconds: 10
leaseExpirationDurationInSeconds: 20
prefer-ip-address: true
希望这有帮助