本文介绍了春季云Netflix | Eureka部署在ECS上时未注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ECS和Cloudformation部署Spring Netflix Eureka和相关的微服务应用程序.

I am trying to deploy Spring Netflix Eureka and related microservice application using ECS and Cloudformation.

Eureka无法注册相关的微服务,因为docker镜像无法链接到主机名.

Eureka is not able to register the related microservices because the docker images are not able to link on hostname.

请提出最好的解决方案.

Please suggest what should be the best solution to handle this.

推荐答案

您应使用EC2实例的主机IP,而不是Docker容器主机的IP.在您的微服务中(如果这些是Spring Boot应用程序),请输入以下代码:

You should use EC2 instance's host ip instead of docker container host's. In your microservices (if those are spring boot applications), put this code:

@Bean
@Profile("docker")
public EurekaInstanceConfigBean eurekaInstanceConfig() {
    EurekaInstanceConfigBean config = new EurekaInstanceConfigBean();
    AmazonInfo info = AmazonInfo.Builder.newBuilder().autoBuild("eureka");
    config.setDataCenterInfo(info);
    info.getMetadata().put(AmazonInfo.MetaDataKey.publicHostname.getName(), info.get(AmazonInfo.MetaDataKey.publicIpv4));
    config.setHostname(info.get(AmazonInfo.MetaDataKey.publicHostname));
    config.setIpAddress(info.get(AmazonInfo.MetaDataKey.publicIpv4));
    config.setNonSecurePort(port);
    return config;
}

请记住在春季启动配置中启用"docker"配置文件.

Remember to enable 'docker' profile in spring boot configuration.

这篇关于春季云Netflix | Eureka部署在ECS上时未注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-26 11:42