码头工人的Eureka客户端未与Eureka服务器连接

时间:2017-11-28 19:04:32

标签: docker spring-boot netflix-eureka

我有一台尤里卡服务器。

server:
  port: 8761
eureka:
  client:
    registerWithEureka: false
    fetchRegistry: false

我有一个eureka客户。

spring:
  application:
    name: mysearch
server:
  port: 8020
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka
  instance:
    preferIpAddress: true

我的eureka客户端正在一个docker容器中运行。

FROM java:8
COPY ./mysearch.jar /var/tmp/app.jar
EXPOSE 8180
CMD ["java","-jar","/var/tmp/app.jar"]

我正在java -jar eureka-server.jar启动eureka服务器 之后我开始使用eureka客户端的docker实例  sudo docker build -t web .sudo docker run -p 8180:8020 -it web。 我可以从浏览器访问eureka客户端和服务器,但客户端没有与Eureka服务器连接。我无法在eureka服务器仪表板中看到客户端。我收到了错误和警告。

WARN 1 --- [tbeatExecutor-0] c.n.d.s.t.d.RetryableEurekaHttpClient    : Request execution failed with message: java.net.ConnectException: Connection refused (Connection refused)
ERROR 1 --- [tbeatExecutor-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_FLIGHTSEARCH/98b0d95fd668:flightsearch:8020 - was unable to send heartbeat!
INFO 1 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_FLIGHTSEARCH/98b0d95fd668:flightsearch:8020: registering service...
ERROR 1 --- [nfoReplicator-0] c.n.d.s.t.d.RedirectingEurekaHttpClient  : Request execution error
WARN 1 --- [nfoReplicator-0] c.n.d.s.t.d.RetryableEurekaHttpClient    : Request execution failed with message: java.net.ConnectException: Connection refused (Connection refused)
WARN 1 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_FLIGHTSEARCH/98b0d95fd668:flightsearch:8020 - registration failed Cannot execute request on any known server
WARN 1 --- [nfoReplicator-0] c.n.discovery.InstanceInfoReplicator     : There was a problem with the instance info replicator

我在AWS EC2 Ubuntu实例中执行此操作。 谁能告诉我我在这里做错了什么?

3 个答案:

答案 0 :(得分:2)

CREATE DEFINER=`root`@`localhost` PROCEDURE `user_add`(IN obj longtext)
 BEGIN

 DECLARE errcode CHAR(5) DEFAULT '00000';
 DECLARE errmsg TEXT; 
 DECLARE exit handler for sqlexception

BEGIN
GET DIAGNOSTICS CONDITION 1

   errcode = RETURNED_SQLSTATE, errmsg = MESSAGE_TEXT;
Select '-1' as State, CONCAT('SQL Exception Raised , error = ',errcode,', message = ',errmsg) as Message;
ROLLBACK;
END;
START TRANSACTION;
SET @obj = obj;
SET @vjson:= JSON_valid(@obj);  
If @vjson = 0 Then 
    Set @state = -1;
    Set @message = 'Not a Valid JSON';
Else 
    Set @action := REPLACE(JSON_EXTRACT(@obj,'$.action'),'"','');
    Set @firstname := REPLACE(JSON_EXTRACT(@obj,'$.firstname'),'"','');
    Set @lastname := REPLACE(JSON_EXTRACT(@obj,'$.lastname'),'"','');
    Set @emailid := REPLACE(JSON_EXTRACT(@obj,'$.emailid'),'"','');
    Set @password := REPLACE(JSON_EXTRACT(@obj,'$.password'),'"','');
    Set @contactnumber := REPLACE(JSON_EXTRACT(@obj,'$.contactnumber'),'"','');
    Set @gender := REPLACE(JSON_EXTRACT(@obj,'$.gender'),'"','');
    Set @dob := REPLACE(JSON_EXTRACT(@obj,'$.dob'),'"','');
    Set @userexists = (Select 1 from userbasic where emailid = @emailid and isactive = 1);
    IF isNull(@userexists) Then 
        Set @state = -1;
        Set @message = 'Not Valid User';
    ElseIF @action='basicinfo'  Then
        INSERT INTO userbasic 
    (firstname,
      lastname,
      emailid,
      password,
      mobile,
      gender,
      dob,
      createdon,
      modified,
      isactive) 
      VALUES 
      (@firstname, @lastname,@emailid,@password,@contactnumber,@gender,@dob,now(),now(),1);

        Set @state = last_insert_id();
        Set @message = 'Success';  
    Else 

        Set @state = 1;
        Set @message = 'Success';

    End IF;
END IF;
 COMMIT;
 Select @state as state, @message as message;
 END

通过上述更改,端口8761将在主机上公开并可以连接到服务器。 使用localhost“http://localhost:8761/eureka”进行连接,该主机正在主机上搜索端口8761。

在Eureka客户端配置中使用host ip而不是localhost,因为如果localhost使用它来搜索容器中的端口8761

http://hostip:8761/eureka

答案 1 :(得分:2)

确保您在Swarm模式下运行。(单节点也可以运行Swarm)

$ docker swarm init

创建了一个覆盖网络,因此服务可以相互ping通。

$ docker network create -d overlay mybridge

为eurika客户端设置application.property,如下所示

eureka.client.service-url.defaultZone=http://discovery:8761/eureka

现在创建第一个发现服务(Eureka发现服务器)

$ docker service create  -d --name discovery --network mybridge \
    --replicas 1 -p 8761:8761 server-discovery

打开浏览器并使用端口8761

命中任何节点

现在创建客户服务:

$ docker service create  -d --name goodbyeapp --network mybridge \
    --replicas 1 -p 2222:2222 goodbye-service

这将注册到发现服务。

答案 2 :(得分:1)

在容器世界中,每次重新启动eureka服务器时,eureka服务器ip地址都会更改。因此,为尤里卡服务器URL指定主机IP地址并非总是有效。

在docker-compose.yml中,我必须将eureka客户端服务链接到eureka服务器容器。在链接服务之前,eureka客户端无法连接到服务器。

这已在最近的另一篇文章中得到解答:Applications not registering to eureka when using docker-compose