java - 将 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
解决方案
我能够通过将 ${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
推荐阅读
- flash - 无法在 Chrome 中从 http 源(wildfly 服务器)加载 swf 文件?
- php - PHP / Laravel - 将数组保存到数据库
- scala - 如何在 Spark scala 或 spark sql 中将列转换为行?
- apache - 即使在服务器上启用 Gzip 压缩也不起作用
- sql-server - 有没有办法在查询 XML 时将变量作为单例传递?
- azure-devops - 自定义 azure-devops backlog 的板视图的列
- python - 在 MSYS2 shell 中访问 Numpy(MINGW64 工作正常,Windows 10)?
- azure-stream-analytics - 当列存在时,流分析中的列名无效
- javascript - 在 React 应用程序中重定向用户的最佳实践是什么?
- android - 如何确定将图标的大小添加到快餐栏