我正在学习 Eureka 和 Spring Boot 的微服务。我已经知道如何并成功地将所有服务注册到 Eureka 中,但所有服务和 Eureka 都是在 Localhost 上创建的。我想知道,我是否可以存储其他计算机上的服务,并且仍然能够在这台计算机上注册到 Eureka,该怎么做?我的问题有相关文件吗?因为我查阅了 Eureka 文档,所有这些文档都是关于仅在本地主机上创建 eureka 和服务。
谢谢大家!
这是我的尤里卡服务器:application.properties
spring.application.name=netflix-eureka-server
server.port=8761
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
这是我的产品管理服务:application.properties
spring.application.name=product-management-service
eureka.client.service-url.default-zone=http://localhost:8761/eureka
server.port=8077
我找到了解决问题的方法
首先,我在计算机 xxx.xxx.xxx.166 的 application.properties 中添加两行代码,告诉这台计算机上的 eureka 服务将从 IP 地址 xxx.xxx.xxx.124 注册:
spring.application.name=netflix-eureka-server
server.port=8761
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
#add these lines which is the IP address of my another computer
spring.cloud.discovery.client.simple.local.uri=http://xxx.xxx.xxx.124
eureka.instance.appname=xxx.xxx.xxx.124
其次,我通过向文件添加一些行来配置另一台计算机的 application.properties:
spring.application.name=product-management-service
eureka.client.service-url.default-zone=http://localhost:8761/eureka
#new code start here
eureka.client.prefer-same-zone-eureka=false
eureka.client.proxy-host=xxx.xxx.xxx.166
eureka.client.proxy-port=8761
server.address=192.168.11.124
server.port=8077
#configuration to set the ip of host instead of the default localhost
eureka.instance.prefer-ip-address=true
eureka.instance.hostname=${server.address}
eureka.instance.ip-address=${server.address}
eureka.instance.instance-id=${server.address}:${spring.application.name}:${server.port}
#new code end here
这是我的结果Eureka https://i.stack.imgur.com/j5V8k.png.
我希望看到大家针对这种情况提出更多更好的建议。
希望这可以帮助某人 xD。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)