aw上的Eureka客户端无法连接到对等服务(eureka客户端)

问题描述 投票:0回答:1

我正在使用spring,spring boot,eureka(用于服务发现)和功能区开发微服务应用程序。

我的应用程序由三个服务客户端,服务器和eureka-server组成

客户端和服务器都在eureka-server注册,后来客户端使用eureka服务发现调用服务器。

我能够在本地运行应用程序,事情很好。

但是当在aws上部署时,事情会变得混乱。

遵循的步骤

  • 同一安全组中的三个ec2实例。
  • 每个微服务都作为docker容器运行,具有正确暴露的端口。
  • 一个ec2实例有弹性ip。 Eureka服务器容器正在其上运行。
  • 客户端和服务器容器部署在其他两个ec2实例上。

结果

使用ECS时

  • 客户端和服务器能够使用Eureka-server注册自己。 Application AMIs Availability Zones Status HELLO-CLIENT n/a (1) (1) UP (1) - 3fcd1c92386d:hello-client:8071 HELLO-SERVER n/a (1) (1) UP (1) - 6a5d643b32e1:hello-server:8072
  • 点击客户端端点获取java.net.UnknownHostException。 Whitelabel Error Page This application has no explicit mapping for /error,so you are seeing this as a fallback. Sun Sep 10 08:38:17 GMT 2017 There was an unexpected error (type=Internal Server Error, status=500). I/O error on GET request for "http://hello-server/hello/server/":6a5d643b32e1; nested exception is java.net.UnknownHostException: 6a5d643b32e1

使用Docker Swarm时

  • 客户端和服务器能够使用Eureka-server注册自己。 Application AMIs Availability Zones Status HELLO-CLIENT n/a (1) (1) UP (1) - ip-10-255-0-5.ap-south-1.compute.internal:hello-client:8071 HELLO-SERVER n/a (1) (1) UP (1) - ip-10-255-0-6.ap-south-1.compute.internal:hello-server:8072
  • 点击客户端端点时连接超时。 白标错误页面 This application has no explicit mapping for /error, so you are seeing this as a fallback. Sun Sep 10 11:22:20 GMT 2017 There was an unexpected error (type=Internal Server Error, status=500). I/O error on GET request for "http://hello-server/hello/server/": Operation timed out (Connection timed out); nested exception is java.net.ConnectException: Operation timed out (Connection timed out)

尤里卡配置

    application.properties
    --------
    spring.application.name=eureka-server
    server.port=8070

    bootstrap.yml
    --------
    eureka:
      client:
        registerWithEureka: false
        fetchRegistry: false
        server:
          waitTimeInMsWhenSyncEmpty: 0
        service-url:
          defaultZone: http://<Elastic IP of eureka server>:8070/eureka

服务器配置

    application.properties
    --------
    spring.application.name=hello-server
    server.port=8072

    bootstrap.yml
    --------
    eureka:
      client:
        service-url:
          defaultZone: http://<Elastic IP of eureka server>:8070/eureka

客户端配置

    application.properties
    --------
    spring.application.name=hello-client
    server.port=8071

    bootstrap.yml
    --------
    eureka:
      client:
        service-url:
          defaultZone: http://<Elastic IP of eureka server>:8070/eureka

休息客户端配置

    Resource.java
    ---------------------------------
    @Autowired
    RestTemplate restTemplate;

    @GetMapping
    @RequestMapping("/hello/client")
    public String hello(){
            String uri = "http://hello-server/hello/server/";
            return restTemplate.getForObject(uri, String.class);
    }


    Config.java
    ----------------------------
    @LoadBalanced
    @Bean
    public RestTemplate restTemplate(){
    return  new RestTemplate();
    }
amazon-web-services docker spring-boot netflix-eureka service-discovery
1个回答
0
投票

我能够解决这个问题。这里的问题是系统试图使用docker容器id作为主机系统无法解析来ping Eureka客户端。在微服务配置中,为所有服务设置eureka.instance.preferIpAddress=true。它肯定会解决问题。

© www.soinside.com 2019 - 2024. All rights reserved.