【问题标题】:Zuul Forwarding error - Trying to connect to a different(unknown) ipZuul 转发错误 - 尝试连接到不同的(未知)ip
【发布时间】:2019-12-27 12:02:23
【问题描述】:

我已经为我的 Spring Boot 应用程序配置了 zuul 代理和 eureka 命名服务器。 Zuul 代理在端口8765 上运行,eureka 在端口8761 上运行。 还有另外两个微服务,user-servicemessage-service 在端口 80818082 上运行。

我还为 zuul 代理服务使用了 swagger,我可以在一个地方找到所有微服务 api。

Zuul 代理服务中的 Swagger 配置

@Component
@Primary
@EnableAutoConfiguration
public class Controller implements SwaggerResourcesProvider{
    @Override
    public List<SwaggerResource> get() {
        List<SwaggerResource> resources= new ArrayList<>();
        SwaggerResource user = new SwaggerResource();
        user.setName("USER-SERVICE");
        user.setLocation("/api/user/v2/api-docs");
        user.setSwaggerVersion("2.0");
        resources.add(user);
        SwaggerResource message = new SwaggerResource();
        message.setName("MESSAGE-SERVICE");
        message.setLocation("/api/message/v2/api-docs");
        message.setSwaggerVersion("2.0");
        resources.add(message);
        return resources;
    }
}

Zuul 代理的application.yml

server:
  port: 8765

eureka:
  client:
    serviceUrl:
      defaultZone: http://eureka-naming-server:8761/eureka/
  instance:
    prefer-ip-address: true
    metadataMap:
      instanceId: ${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${random.value}}}
    instanceId: ${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${random.value}}}
zuul:
  prefix: /api
  sensitive-headers: Cookie,Set-Cookie
  routes:
    user-service:
      path: /user/**
      service-id: USER-SERVICE
    message-service:
      path: /message/**
      service-id: MESSAGE-SERVICE

我还使用docker-compose 文件以默认子网 (169.254.3.0/24) 启动 docker 微服务。

用户服务的ip地址是169.254.3.6 message-service的ip地址是169.254.3.10

问题来了

当我通过 zuul proxy swgger ui 调用这些服务时,我经常收到 500 错误。这是我第一次点击特定的网址,它会引发 500 错误。 但经过几次尝试后,我得到了回应。

指示问题的 Zuul 日志

com.netflix.zuul.exception.ZuulException: Forwarding error
...
Caused by: com.netflix.client.ClientException: null
...
Caused by: java.lang.RuntimeException: org.apache.http.conn.ConnectTimeoutException: Connect to 172.22.97.14:8081 [/172.22.97.14] failed: connect timed out
...
Caused by: org.apache.http.conn.ConnectTimeoutException: Connect to 172.22.97.14:8081 [/172.22.97.14] failed: connect timed out
...
Caused by: java.net.SocketTimeoutException: connect timed out

我不知道 172.22.97.14:8081,为什么不尝试连接 172.22.97.14:8081 而不是连接到 169.254.3.6: 8081

有人可以帮我了解这里发生了什么..

任何帮助将不胜感激!

[编辑] zuul代理容器ip为169.254.3.10

【问题讨论】:

  • 我认为 169.254.3.6 在你的情况下是不可路由的。你能连接到那个地址吗?
  • @LinPy 我可以从服务器连接到 169.254.3.6。 telnet 169.254.3.6 8081 工作正常。
  • 我的意思是远程不是来自本地 IP 的位置
  • 配置中定义的端口8081在哪里,我看到服务器尝试连接到端口8084
  • @LinPy 对不起。我放错了日志。无论如何,在端口8084 中,我也在为此运行我的管理服务相同的问题。我已经编辑了帖子。

标签: spring-boot docker routes netflix-eureka netflix-zuul


【解决方案1】:

当我使用相同的 Zuulserver 在 localhost 和 DEV 环境上开发微服务时,我的项目出现了这个问题(当我在 localhost 上启动 microservis 时,它连接到 DEV env 上的 zullserver)。然后,当我尝试通过 zuulserver 调用某些操作时,它尝试连接到不在 DEV env 上的 microservis。但在我的机器上。

我怀疑你这边的问题和你开发应用程序的 IP 是 172.22.97.14:8081 一样。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-22
    • 2013-02-20
    • 2018-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-02
    • 1970-01-01
    相关资源
    最近更新 更多