【问题标题】:Load balancer does not have available server for client. How to solve?负载均衡器没有可供客户端使用的服务器。怎么解决?
【发布时间】:2019-04-09 19:05:07
【问题描述】:

我注意到很多人问了同样的问题,但是我尝试了他们的方法,但我的问题仍然存在。

我用的是spring-boot + eureka + zuul,

spring.cloud.version: 2.0.2.RELEASE

这里是 Eureka 服务器:

@SpringBootApplication
@EnableEurekaServer
@Slf4j
public class EurekaServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(EurekaServerApplication.class, args);
        log.info("-- EurekaServerApplication started --");
    }
}

以及 eureka 服务器的 application.yml:

server:
port: 8888

eureka:
  client:
    registerWithEureka: false
    fetchRegistry: false
    healthcheck:
      enabled: true
    service-url:
      defaultZone: http://localhost:8888/eureka

那么这里是Zuul服务器:

@SpringBootApplication
@EnableZuulProxy
@EnableEurekaClient
@Slf4j
public class ZuulServerApplication{

    public static void main(String[] args) {
        SpringApplication.run(ZuulServerApplication.class, args);
        log.info("-- ZuulServerApplication started --");
    }
}

以及 Zuul 的 application.yml

server:
  port: 7777

eureka:
  instance:
    appname: zuul-server
  client:
    serviceUrl:
    defaultZone: http://localhost:8888/eureka

zuul:
  ignoredServices: '*'
  routes:
    file-management:
      path: /file-management/**
      serviceId: file-management

还有一个微服务文件管理:

@SpringBootApplication
@EnableEurekaClient
@EnableSwagger2
@Slf4j
public class FileManagementApplication {
    public static void main(String[] args) {
        SpringApplication.run(FileManagementApplication.class, args);
        log.info("-- FileManagement started --");
    }
}

application.yml

... some other configs
server:
  port: 8081
eureka:
  instance:
    appname: file-management
  client:
    serviceUrl:
    defaultZone: http://localhost:8888/eureka

我这几天有这个问题,任何帮助将不胜感激!

【问题讨论】:

    标签: configuration microservices spring-cloud netflix-eureka netflix-zuul


    【解决方案1】:

    经过研究,我解决了我的问题。我把我的解决方案放在这里,希望这可以帮助人们解决同样的问题。

    我是如何解决的:

    1. 在文件管理application.yml 中添加:
    spring:
      application:
        name: file-management
    
    1. zuul application.yml 中添加:
    eureka:
      client:
        fetchRegistry: true
    

    然后就可以了。

    原因是很多教程和例子都是基于一些旧版本的,所以我猜他们在新版本中做了一些调整。

    所以对于像我一样遇到同样问题的人,请确保您阅读的文档或示例与您使用的版本匹配。并希望这个答案可以帮助某人。

    【讨论】:

      【解决方案2】:

      我对这个配置没有任何问题:

       server:
          port: 8881
      
       eureka:
         client:
           eureka-connection-idle-timeout-seconds: 60
           serviceUrl:
             defaultZone: http://localhost:8882/eureka/
           healthcheck:
             enabled: true
      

      你可以查看我的回购here

      您也可以尝试评论 appname:文件管理和对齐 defaultZone。如果格式不正确,有时 yml 属性不会加载。

      【讨论】:

      • 感谢您的回复!我会尝试然后提供反馈。
      • 非常感谢您的建议。我仍然无法解决我的问题。不过还是谢谢你。
      猜你喜欢
      • 2017-05-15
      • 2018-06-07
      • 2019-02-09
      • 2017-12-25
      • 2019-03-23
      • 2016-04-02
      • 2017-06-05
      • 1970-01-01
      • 2021-04-20
      相关资源
      最近更新 更多