2

我正在尝试在 AWS ECS 中部署我的 Spring Boot 微服务。我能够将 Eureka 容器作为一项任务运行,并且运行良好。但是当我使用 AWS Fargate 运行任何其他 micoservice 时,它​​的日志显示

[ 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 运行时,sp​​ringboot 无法识别它的 IP 地址以在 Eureka 中注册。我该如何解决这个问题?

4

2 回答 2

3

问题是 eureka 客户端没有从 Fargate 元数据服务获取正确的 IP。我通过覆盖 IP(我自己称为元数据服务)解决了这个问题。我创建了一个示例来展示如何做到这一点。

我希望在某些时候将类似的功能包含在 eureka 客户端中。

于 2018-08-17T10:36:35.577 回答
1

如果您使用的是spring cloud,则可以使用此方法:

@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;
}
于 2019-09-17T13:46:07.733 回答