gpt4 book ai didi

spring - 为什么Docker中的应用程序在Eureka中像一些哈希而不是IP地址一样进行注册

转载 作者:行者123 更新时间:2023-12-02 18:33:55 33 4
gpt4 key购买 nike

我需要告诉运行在Docker中的Eureka客户端使用主机的IP来注册其服务。我使用了以下内容,但是它不起作用。
是来自 Eureka 的信息
Eureka status
网关服务在没有Docker容器的情况下运行,并且具有IP地址而不是Docker容器ID。
我有Eureka客户端的下一个配置(也有帐户服务)

eureka:
instance:
preferIpAddress: true
client:
service-url:
defaultZone: http://192.168.10.101:8761/eureka/
和 Eureka 配置:
eureka:
instance:
preferIpAddress: true
client:
register-with-eureka: false
fetch-registry: false
server:
waitTimeInMsWhenSyncEmpty: 0
用于帐户服务的Docker文件:
FROM openjdk:8-jdk-alpine
EXPOSE 8081
COPY /build/libs/account-service-1.0-SNAPSHOT.jar .
ENTRYPOINT ["java","-jar","account-service-1.0-SNAPSHOT.jar"]
如果由于这个问题我理解正确,那么网关服务也无法正常工作,因为它不知道任何主机名称为 a462e5bd6528 (容器ID)的主机
/ eureka / app的帐户服务如下所示
<name>ACCOUNT-SERVICE</name>
<instance>
<instanceId>7186158a6d3a:account-service:8081</instanceId>
<hostName>172.17.0.2</hostName>
<app>ACCOUNT-SERVICE</app>
<ipAddr>172.17.0.2</ipAddr>
<status>UP</status>
<overriddenstatus>UNKNOWN</overriddenstatus>
<port enabled="true">8081</port>
<securePort enabled="false">443</securePort>
<countryId>1</countryId>
<dataCenterInfo class="com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo">
<name>MyOwn</name>
</dataCenterInfo>
<leaseInfo>
<renewalIntervalInSecs>30</renewalIntervalInSecs>
<durationInSecs>90</durationInSecs>
<registrationTimestamp>1600017352414</registrationTimestamp>
<lastRenewalTimestamp>1600017472166</lastRenewalTimestamp>
<evictionTimestamp>0</evictionTimestamp>
<serviceUpTimestamp>1600017352415</serviceUpTimestamp>
</leaseInfo>
<metadata>
<management.port>8081</management.port>
</metadata>
<homePageUrl>http://172.17.0.2:8081/</homePageUrl>
<statusPageUrl>http://172.17.0.2:8081/accounts/actuator/info</statusPageUrl>
<healthCheckUrl>http://172.17.0.2:8081/accounts/actuator/health</healthCheckUrl>
<vipAddress>account-service</vipAddress>
<secureVipAddress>account-service</secureVipAddress>
<isCoordinatingDiscoveryServer>false</isCoordinatingDiscoveryServer>
<lastUpdatedTimestamp>1600017352416</lastUpdatedTimestamp>
<lastDirtyTimestamp>1600017352218</lastDirtyTimestamp>
<actionType>ADDED</actionType>
</instance>
</application>
我可以以某种方式切换到IP地址吗?还是正确的情况?
谢谢!
UPD :
当尝试向网关服务发送请求时出现异常,该请求应路由到帐户服务
Caused by: com.netflix.client.ClientException: Load balancer does not have available server for client: account-service

最佳答案

所以我将eureka的配置更改为

eureka:
instance:
preferIpAddress: true
client:
register-with-eureka: false
fetch-registry: true
server:
waitTimeInMsWhenSyncEmpty: 0
提取注册表:true
而且效果很好
我在 Eureka 有相同的服务描述
<name>ACCOUNT-SERVICE</name>
<instance>
<instanceId>4df8e2cd089d:account-service:8081</instanceId>
<hostName>172.18.0.5</hostName>
<app>ACCOUNT-SERVICE</app>
<ipAddr>172.18.0.5</ipAddr>
<status>UP</status>
<overriddenstatus>UNKNOWN</overriddenstatus>
<port enabled="true">8081</port>
<securePort enabled="false">443</securePort>
<countryId>1</countryId>
<dataCenterInfo class="com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo">
<name>MyOwn</name>
</dataCenterInfo>
<leaseInfo>
<renewalIntervalInSecs>30</renewalIntervalInSecs>
<durationInSecs>90</durationInSecs>
<registrationTimestamp>1600182260927</registrationTimestamp>
<lastRenewalTimestamp>1600182500655</lastRenewalTimestamp>
<evictionTimestamp>0</evictionTimestamp>
<serviceUpTimestamp>1600182260391</serviceUpTimestamp>
</leaseInfo>
<metadata>
<management.port>8081</management.port>
</metadata>
<homePageUrl>http://172.18.0.5:8081/</homePageUrl>
<statusPageUrl>http://172.18.0.5:8081/accounts/actuator/info</statusPageUrl>
<healthCheckUrl>http://172.18.0.5:8081/accounts/actuator/health</healthCheckUrl>
<vipAddress>account-service</vipAddress>
<secureVipAddress>account-service</secureVipAddress>
<isCoordinatingDiscoveryServer>false</isCoordinatingDiscoveryServer>
<lastUpdatedTimestamp>1600182260927</lastUpdatedTimestamp>
<lastDirtyTimestamp>1600182260267</lastDirtyTimestamp>
<actionType>ADDED</actionType>
</instance>
但是现在网关服务可以将请求路由到帐户服务

关于spring - 为什么Docker中的应用程序在Eureka中像一些哈希而不是IP地址一样进行注册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63871795/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com