【问题标题】:Error "Load balancer does not have available server for client" when using zuul and eureka使用 zuul 和 eureka 时出现错误“负载均衡器没有可用于客户端的服务器”
【发布时间】:2019-08-18 02:05:47
【问题描述】:

我在 Heroku 上有几个微服务 - eureka-server、Zuul 服务器和一些应用服务。

当我尝试通过 Zuul 网关访问我的任何服务时,例如“service1”,Zuul 无法将请求转发到相应的服务(当我尝试在本地运行它们时一切正常)。 我在 Zuul 日志中发现了以下错误:

com.netflix.zuul.exception.ZuulException: Forwarding error 
Caused by: com.netflix.client.ClientException: Load balancer does not have the available server for the client: service1

以下是我的服务配置:

1) “zuul 服务器”application.yml

server:
  port: ${PORT:8000}

zuul:
  prefix: /api
  ignoredServices: '*'
  routes:
    service1:
      path: /path_for_service1/**
      serviceId: service1
      strip-prefix: false
   ...

management:
  endpoints:
    web:
      exposure:
        include: "*"

eureka:
  client:
    serviceUrl:
      defaultZone: ${EUREKA_URL:http://localhost:5000}/eureka/

2)“尤里卡服务器”application.yml

server:
  port: ${PORT:5000}

eureka:
  instance:
    hostname: localhost
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

3.1) "service1" application.yml

server.port=${PORT:8081}
eureka.client.service-url.defaultZone=${EUREKA_URL:http://localhost:5000}/eureka/

3.2) "service1" bootstrap.yml

spring:
  application:
    name: service1

所有微服务都在 eureka 仪表板中可见。

如果我将 zuul 路由更改为硬编码的 url,它运行良好,但它不是我想要的。

zuul:
  prefix: /api
  ignoredServices: '*'
  routes:
    service1:
      path: /path_for_service1/**
      url: http://url_of_service_1
      strip-prefix: false

你能帮我解决这个问题吗?

【问题讨论】:

    标签: spring-boot heroku netflix-eureka netflix-zuul netflix-ribbon


    【解决方案1】:

    最后,我找到了根本原因 :) 默认情况下,所有服务都使用 heroku 主机名(如“085930c7-b893-4b34-88a7-6e37fbe7fa0f”)在 eureka 中注册,外部无法访问。 但是服务可以通过域名访问。 所以我只是将域名设置添加到每个服务的application.properties(https://blog.heroku.com/managing_your_microservices_on_heroku_with_netflix_s_eureka

    eureka:
      instance:
        non-secure-port: 80
        hostname: ${DOMAIN_NAME}
    

    现在它可以工作了。

    【讨论】:

    • 我也有同样的问题。希望能有所帮助。
    猜你喜欢
    • 2021-04-20
    • 2018-06-07
    • 2019-09-18
    • 2019-03-23
    • 2017-05-15
    • 2017-06-05
    • 1970-01-01
    • 2016-04-02
    • 2019-02-09
    相关资源
    最近更新 更多