微服务未使用 AWS fargate 在 Eureka 中注册
Microservices doesnt register in Eureka with AWS fargate
我正在尝试在 AWS ECS 中部署我的 spring 启动微服务。我能够 运行 Eureka 容器作为一项任务,它工作正常。但是当我 运行 使用 AWS Fargate 的任何其他微服务时,它的日志显示
[ main] c.n.e.transport.JerseyReplicationClient : Cannot find localhost ip
java.net.UnknownHostException: 4terdtrtxxx: 53543xxxxd: Name does not resolve
at java.net.InetAddress.getLocalHost(InetAddress.java:1505) ~[na:1.8.0_151]
...
。我认为问题是当我 运行 使用 AWS Fargate 时,springboot 无法识别它的 IP 地址以在 Eureka 中注册。我该如何解决这个问题?
问题是 eureka 客户端没有从 Fargate 元数据服务获取正确的 IP。
我通过覆盖 IP(我自己称为元数据服务)解决了这个问题。
我创建了 a sample,它展示了如何做到这一点。
我希望 eureka 客户端在某个时候包含类似的功能。
如果您使用的是 spring 云,则可以使用此方法:
@Bean
public EurekaInstanceConfigBean eurekaInstanceConfig(InetUtils inetUtils){
EurekaInstanceConfigBean config = new EurekaInstanceConfigBean(inetUtils);
String ip = null;
try {
ip = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
e.printStackTrace();
}
config.setIpAddress(ip);
config.setPreferIpAddress(true);
return config;
}
我正在尝试在 AWS ECS 中部署我的 spring 启动微服务。我能够 运行 Eureka 容器作为一项任务,它工作正常。但是当我 运行 使用 AWS Fargate 的任何其他微服务时,它的日志显示
[ main] c.n.e.transport.JerseyReplicationClient : Cannot find localhost ip
java.net.UnknownHostException: 4terdtrtxxx: 53543xxxxd: Name does not resolve
at java.net.InetAddress.getLocalHost(InetAddress.java:1505) ~[na:1.8.0_151]
...
。我认为问题是当我 运行 使用 AWS Fargate 时,springboot 无法识别它的 IP 地址以在 Eureka 中注册。我该如何解决这个问题?
问题是 eureka 客户端没有从 Fargate 元数据服务获取正确的 IP。 我通过覆盖 IP(我自己称为元数据服务)解决了这个问题。 我创建了 a sample,它展示了如何做到这一点。
我希望 eureka 客户端在某个时候包含类似的功能。
如果您使用的是 spring 云,则可以使用此方法:
@Bean
public EurekaInstanceConfigBean eurekaInstanceConfig(InetUtils inetUtils){
EurekaInstanceConfigBean config = new EurekaInstanceConfigBean(inetUtils);
String ip = null;
try {
ip = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
e.printStackTrace();
}
config.setIpAddress(ip);
config.setPreferIpAddress(true);
return config;
}