[英]java.net.ConnectException: Connection refused by eureke-server
I am trying to create a simple eureka server which will detect other microservices and all other microservice can talk through it.我正在尝试创建一个简单的eureka服务器,它将检测其他微服务,并且所有其他微服务都可以通过它进行通信。 I am using spring boot 2.0.3 .
我正在使用spring boot 2.0.3 。
EurekaServerApplication.java file (eureka server) EurekaServerApplication.java 文件(尤里卡服务器)
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
HelloServerApplication application.property (eureka server) HelloServerApplication application.property(尤里卡服务器)
spring.application.name=eureka-server
server.port=8070
application.yml (eureka server) application.yml(尤里卡服务器)
eureka:
client:
registerWithEureka: false
fetchRegistry: false
server:
waitTimeInMsWhenSyncEmpty: 0
HelloServerApplication.java (eureka client) HelloServerApplication.java(尤里卡客户端)
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@EnableDiscoveryClient
@SpringBootApplication
public class HelloServerApplication {
public static void main(String[] args) {
SpringApplication.run(HelloServerApplication.class, args);
}
}
application.yml (eureka client) application.yml(尤里卡客户端)
spring:
application:
name: hello-server
server:
port: 8071
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://localhost:8070/eureka/
instance:
hostname: localhost
When I run the eureka server, I can access the server at http://localhost:8070/ but when I try to run a eureka client HelloServerApplication.java the eureka server shows the following error and the eureka client shuts down-当我运行 eureka 服务器时,我可以通过http://localhost:8070/访问服务器,但是当我尝试运行 eureka 客户端HelloServerApplication.java 时,eureka 服务器显示以下错误并且 eureka 客户端关闭 -
Error on eureka server尤里卡服务器上的错误
2018-06-25 17:26:30.250 ERROR 4635 --- [get_localhost-3] c.n.e.cluster.ReplicationTaskProcessor : Network level connection to peer localhost; retrying after delay
com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused (Connection refused)
at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187) ~[jersey-apache-client4-1.19.1.jar:1.19.1]
at com.netflix.eureka.cluster.DynamicGZIPContentEncodingFilter.handle(DynamicGZIPContentEncodingFilter.java:48) ~[eureka-core-1.9.2.jar:1.9.2]
at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27) ~[eureka-client-1.9.2.jar:1.9.2]
at com.sun.jersey.api.client.Client.handle(Client.java:652) ~[jersey-client-1.19.1.jar:1.19.1]
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682) ~[jersey-client-1.19.1.jar:1.19.1]
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74) ~[jersey-client-1.19.1.jar:1.19.1]
at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:570) ~[jersey-client-1.19.1.jar:1.19.1]
at com.netflix.eureka.transport.JerseyReplicationClient.submitBatchUpdates(JerseyReplicationClient.java:116) ~[eureka-core-1.9.2.jar:1.9.2]
at com.netflix.eureka.cluster.ReplicationTaskProcessor.process(ReplicationTaskProcessor.java:80) ~[eureka-core-1.9.2.jar:1.9.2]
at com.netflix.eureka.util.batcher.TaskExecutors$BatchWorkerRunnable.run(TaskExecutors.java:187) [eureka-core-1.9.2.jar:1.9.2]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_171]
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_171]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_171]
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_171]
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_171]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_171]
at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_171]
at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:121) ~[httpclient-4.5.5.jar:4.5.5]
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180) ~[httpclient-4.5.5.jar:4.5.5]
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:144) ~[httpclient-4.5.5.jar:4.5.5]
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:134) ~[httpclient-4.5.5.jar:4.5.5]
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:610) ~[httpclient-4.5.5.jar:4.5.5]
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:445) ~[httpclient-4.5.5.jar:4.5.5]
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835) ~[httpclient-4.5.5.jar:4.5.5]
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:118) ~[httpclient-4.5.5.jar:4.5.5]
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56) ~[httpclient-4.5.5.jar:4.5.5]
at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:173) ~[jersey-apache-client4-1.19.1.jar:1.19.1]
... 10 common frames omitted
I tried moving all properties on both the sides to bootstrap.application file, that did not work.我尝试将两侧的所有属性移动到bootstrap.application文件,但没有用。
I tried this solution: https://github.com/spring-cloud/spring-cloud-netflix/issues/2893 , but it did not work.我尝试了这个解决方案: https : //github.com/spring-cloud/spring-cloud-netflix/issues/2893 ,但没有用。
The eureka configuration in both the server and client side is very sensitive.服务器端和客户端的 eureka 配置都非常敏感。 The service url and default zone configuration should be written as follow :
服务 url 和默认区域配置应编写如下:
service-url (Not serviceUrl):
defaultZone(Not default-zone) : http://localhost:portNumberHere/eureka
尽管有以下设置,但 eureka 似乎试图连接到自己: eureka.client.register-with-eureka=false eureka.client.fetch-registry=false 你有两个选项可以解决这个问题 1-保留 eureka 的默认端口 2 -将下面添加到您的 eureka 服务器的 application.properties eureka.server.maxThreadsForPeerReplication=0
Following configuration in YAML and application.properties file worked for me. YAML 和 application.properties 文件中的以下配置对我有用。
naming-server : name of the configuration in YAML file. Naming-server :YAML 文件中配置的名称。
application.yml应用程序.yml
eureka.client.service-url.defaultZone: http://naming-server:8761/eureka
Also, in Eureka property file make sure you have put below things as stated in above answer此外,在 Eureka 属性文件中,请确保您已按照上述答案中的说明放置以下内容
application.property应用程序属性
eureka.client.register-with-eureka = false
eureka.client.fetch-registry = false
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.