负载平衡器没有可供客户端使用的服务器。怎么解决?
Load balancer does not have available server for client. How to solve?
我注意到很多人问了同样的问题,但是我试了他们的方法,但我的问题仍然存在。
我用的是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 --");
}
}
和尤里卡服务器的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
我遇到这个问题已经有几天了,如果您能提供帮助,我们将不胜感激!
我对这个配置没有任何问题:
server:
port: 8881
eureka:
client:
eureka-connection-idle-timeout-seconds: 60
serviceUrl:
defaultZone: http://localhost:8882/eureka/
healthcheck:
enabled: true
你可以查看我的 repo here。
您也可以尝试评论 appname: file-management 和对齐 defaultZone.Sometimes 如果格式不正确,yml 属性将无法加载。
经过研究,我解决了我的问题。我把我的解决方案放在这里,希望这可以帮助人们遇到同样的问题。
我是怎么解决的:
- 在文件管理中
application.yml
添加:
spring:
application:
name: file-management
- 在
zuul
中添加application.yml
:
eureka:
client:
fetchRegistry: true
然后就可以了。
原因是很多教程和例子都是基于一些旧版本的,所以我猜他们在新版本中做了一些调整。
所以对于遇到和我一样问题的人,请确保您阅读的文档或示例与您使用的版本相匹配。并希望这个答案可以帮助某人。
我注意到很多人问了同样的问题,但是我试了他们的方法,但我的问题仍然存在。
我用的是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 --");
}
}
和尤里卡服务器的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
我遇到这个问题已经有几天了,如果您能提供帮助,我们将不胜感激!
我对这个配置没有任何问题:
server:
port: 8881
eureka:
client:
eureka-connection-idle-timeout-seconds: 60
serviceUrl:
defaultZone: http://localhost:8882/eureka/
healthcheck:
enabled: true
你可以查看我的 repo here。
您也可以尝试评论 appname: file-management 和对齐 defaultZone.Sometimes 如果格式不正确,yml 属性将无法加载。
经过研究,我解决了我的问题。我把我的解决方案放在这里,希望这可以帮助人们遇到同样的问题。
我是怎么解决的:
- 在文件管理中
application.yml
添加:
spring:
application:
name: file-management
- 在
zuul
中添加application.yml
:
eureka:
client:
fetchRegistry: true
然后就可以了。
原因是很多教程和例子都是基于一些旧版本的,所以我猜他们在新版本中做了一些调整。
所以对于遇到和我一样问题的人,请确保您阅读的文档或示例与您使用的版本相匹配。并希望这个答案可以帮助某人。