首页 > 解决方案 > 将 Eureka Client 注册到 Eureka Server

问题描述

我尝试将 Eureka 服务器连接到 Eureka 客户端但没有成功。全部在一个容器中。Docker/容器网络设置为主机。

我尝试在我的桌面上托管两者:作品我尝试在我的 Raspberry pi 上托管两者:作品

但是当我在我的 Raspberry Pi 上托管服务器时,我无法从我的桌面连接服务。我尝试了很多都没有成功。

旁注:我可以访问 Eureka Dashboard,并且我正在运行另一个容器,并成功连接到我的桌面上的 SQL 数据库,我想应该不存在网络问题。

客户

server:
  port: 9001


spring:
  application.name: USER-SERVICE
  cloud:
    inetutils:
      preferred-networks:
        - 192.168

eureka:
  instance:
    prefer-ip-address: true
    hostname: 192.168.0.20
  client:
    fetch-registry: true
    register-with-eureka: true
    service-url:
      defeaultZone: http://192.168.0.69:8761/eureka

服务器

server:
  port: 8761


eureka:
  client:
    register-with-eureka: false
    fetch-registry: false
    service-url:
      defaultZone: http://192.168.0.69:8761/eureka
  instance:
    hostname: 192.168.0.69
    prefer-ip-address: true

192.168.0.20 是我的桌面 192.168.0.69 是我的树莓派

这甚至可能吗?我尝试了很多不同的设置...正如我所说的,无论是在本地托管还是在树莓作品上。

提前致谢

错误信息 :

2021-08-15 00:40:24.177  INFO 16044 --- [           main] c.n.d.s.t.d.RedirectingEurekaHttpClient  : Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8761/eureka/}, exception=I/O error on GET request for "http://localhost:8761/eureka/apps/": Connect to localhost:8761 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect; nested exception is org.apache.http.conn.HttpHostConnectException: Connect to localhost:8761 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect stacktrace=org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:8761/eureka/apps/": Connect to localhost:8761 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect; nested exception is org.apache.http.conn.HttpHostConnectException: Connect to localhost:8761 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect

标签: javaspringdockerraspberry-pinetflix-eureka

解决方案


我能够通过将 ${eureka_url: } 添加到 defaultZone 来解决问题。现在完美运行。

eureka:
  client:
    fetch-registry: true
    register-with-eureka: true
    service-url:
      defaultZone: ${eureka_url:http://192.168.0.69:8761/eureka}
  instance:
    hostname: 192.168.0.69
    prefer-ip-address: true

推荐阅读