Java.net.ConnectException: Eureka服务器拒绝连接。

4

我正在尝试创建一个简单的eureka服务器,它将检测其他微服务,并且所有其他微服务都可以通过它进行通信。我正在使用spring boot 2.0.3

我的eureka服务器

EurekaServerApplication.java文件(eureka服务器)

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 应用配置 (Eureka服务端)

spring.application.name=eureka-server
server.port=8070

应用配置文件 (Eureka 服务器)

eureka:
  client:
    registerWithEureka: false
    fetchRegistry: false
    server:
      waitTimeInMsWhenSyncEmpty: 0

我的Eureka客户端

HelloServerApplication.java(Eureka客户端)

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客户端)

spring:
  application:
    name: hello-server

server:
  port: 8071

eureka:
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://localhost:8070/eureka/
  instance:
    hostname: localhost

当我运行eureka服务器时,我可以访问位于http://localhost:8070/的服务器,但是当我尝试运行eureka客户端HelloServerApplication.java时,eureka服务器显示以下错误,eureka客户端关闭-

eureka服务器出现错误

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

我尝试将双方的所有属性都移动到 bootstrap.application 文件中,但没有成功。

我尝试了这个解决方案:https://github.com/spring-cloud/spring-cloud-netflix/issues/2893,但没有成功。


你的服务器上是否缺少 defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ - Craig Smith
@CraigSmith 不,我已经将它添加到 HelloServer 的 application.yml 文件中,如下所示:serviceUrl: defaultZone: http://localhost:8070/eureka/ - Sunil
请查看以下链接:https://dev59.com/l6Tia4cB1Zd3GeqP-Tq_ 看起来你需要在客户端和服务器上都进行设置。 - Craig Smith
@CraigSmith我在yml文件(服务器/客户端)中都添加了serviceUrl:defaultZone:http:// localhost:8070 / eureka /'。现在,服务器不显示巨大的异常消息,而是显示- 2018-06-25 18:50:27.352 INFO 9171 --- [nio-8070-exec-2] c.n.e.registry.AbstractInstanceRegistry:已注册实例HELLO-SERVER / 192.168.1.201:hello-server:8071,状态为UP(复制=false)2018-06-25 18:50:27.414 INFO 9171 --- [nio-8070-exec-3] c.n.e.registry.AbstractInstanceRegistry:已注册实例HELLO-SERVER / 192.168.1.201:hello-server:8071,状态为DOWN(复制=false)`。 - Sunil
为什么你同时拥有application.properties和application.yml文件?你应该选择其中一个。 - Craig Smith
@CraigSmith 那也没有帮助,我把所有的属性都移到了 yml 文件中。 - Sunil
3个回答

3

在服务器端和客户端中,Eureka配置非常敏感。服务URL和默认区域配置应按以下方式编写:

 service-url (Not serviceUrl):
   defaultZone(Not default-zone) : http://localhost:portNumberHere/eureka

你肯定是想写 defaultZone - TT.
@BereketBabiso,我认为service-url和serviceUrl是相同的。 - jagga

0

以下是我在 YAML 和 application.properties 文件中的配置。

naming-server:YAML 文件中的配置名称。

application.yml

eureka.client.service-url.defaultZone: http://naming-server:8761/eureka

同时,在 Eureka 属性文件中,请确保您按照上面的答案所述放置了以下内容。

application.property

eureka.client.register-with-eureka = false
eureka.client.fetch-registry = false

0

看起来尽管以下设置:eureka.client.register-with-eureka=false和eureka.client.fetch-registry=false,Eureka仍然试图连接到自身。你有两个选项来解决这个问题: 1-保持默认的Eureka端口。 2-将下面的内容添加到你的Eureka服务器的application.properties文件中: eureka.server.maxThreadsForPeerReplication=0


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接