小编典典

Spring云:功能区和HTTPS

spring-boot

我们希望将HTTPS用于基于Feign和Ribbon的微服务通信。这些服务基于Spring
Boot,并且tomcat已正确设置。实例已在Eureka上启用HTTPS
URL和securePort进行注册。但是,当我们通过Feign调用另一个微服务时,底层的Ribbon无法识别该协议,并退回到HTTP。我可以通过将协议添加到FeignClient注释中来解决该问题,如下所示:

    @FeignClient("https://users")

但是似乎内部也使用Ribbon的Zuul代理和Hystrix /
Turbine都具有相同的HTTP回退问题。有什么方法可以将Ribbon集中配置为默认使用HTTPS或使用已 注册的eureka 实例的
securePort 设置?

Eureka实例配置:

eureka.instance.hostname=localhost
eureka.instance.securePort = ${server.port}
eureka.instance.securePortEnabled = true  
eureka.instance.nonSecurePortEnabled = false 
eureka.instance.metadataMap.hostname = ${eureka.instance.hostname}
eureka.instance.metadataMap.securePort = ${server.port}
eureka.instance.homePageUrl = https://${eureka.instance.hostname}:${server.port}/
eureka.instance.statusPageUrl = https://${eureka.instance.hostname}:${server.port}/admin/info

通过这些设置,在Eureka中看起来就像该服务在HTTPS上运行。Zuul代理运行良好,但是使用HTTP
URL调用服务。您必须通过在密钥库中提供服务器证书来在Spring Boots嵌入式Tomcat中启用SSL:

server.ssl.key-store=server.jks
server.ssl.key-store-password=<pw>
server.ssl.keyStoreType=jks
server.ssl.keyAlias=tomcat
server.ssl.key-password=<pw>

Tomcat只能在HTTPS上运行,并且HTTP端口被阻止,但是我却得到:localhost:8081 failed to respond因为HTTP
URL用于调用服务。通过设置ribbon.IsSecure=true用户服务URL可以正确生成,但是Ribbon负载平衡器无法在Eureka中查找用户服务:Load balancer does not have available server for client: users。我也尝试users.ribbon.IsSecure=true仅在zuul代理中设置,但仍然收到相同的错误。

Caused by: com.netflix.client.ClientException: Load balancer does not have available server for client: user
at com.netflix.loadbalancer.LoadBalancerContext.getServerFromLoadBalancer(LoadBalancerContext.java:468)
at com.netflix.loadbalancer.reactive.LoadBalancerCommand$1.call(LoadBalancerCommand.java:184)
at com.netflix.loadbalancer.reactive.LoadBalancerCommand$1.call(LoadBalancerCommand.java:180)
at rx.Observable$1.call(Observable.java:145)
at rx.Observable$1.call(Observable.java:137)
at rx.Observable$1.call(Observable.java:145)
at rx.Observable$1.call(Observable.java:137)
at rx.Observable.unsafeSubscribe(Observable.java:7304)
at rx.internal.operators.OperatorRetryWithPredicate$SourceSubscriber$1.call(OperatorRetryWithPredicate.java:112)
at rx.schedulers.TrampolineScheduler$InnerCurrentThreadScheduler.enqueue(TrampolineScheduler.java:81)
at rx.schedulers.TrampolineScheduler$InnerCurrentThreadScheduler.schedule(TrampolineScheduler.java:59)
at rx.internal.operators.OperatorRetryWithPredicate$SourceSubscriber.onNext(OperatorRetryWithPredicate.java:77)
at rx.internal.operators.OperatorRetryWithPredicate$SourceSubscriber.onNext(OperatorRetryWithPredicate.java:45)
at rx.internal.util.ScalarSynchronousObservable$1.call(ScalarSynchronousObservable.java:41)
at rx.internal.util.ScalarSynchronousObservable$1.call(ScalarSynchronousObservable.java:30)
at rx.Observable$1.call(Observable.java:145)
at rx.Observable$1.call(Observable.java:137)
at rx.Observable$1.call(Observable.java:145)
at rx.Observable$1.call(Observable.java:137)
at rx.Observable$1.call(Observable.java:145)
at rx.Observable$1.call(Observable.java:137)
at rx.Observable.subscribe(Observable.java:7393)
at rx.observables.BlockingObservable.blockForSingle(BlockingObservable.java:441)
at rx.observables.BlockingObservable.single(BlockingObservable.java:340)
at com.netflix.client.AbstractLoadBalancerAwareClient.executeWithLoadBalancer(AbstractLoadBalancerAwareClient.java:102)
at com.netflix.client.AbstractLoadBalancerAwareClient.executeWithLoadBalancer(AbstractLoadBalancerAwareClient.java:81)
at org.springframework.cloud.netflix.zuul.filters.route.RibbonCommand.forward(RibbonCommand.java:129)
at org.springframework.cloud.netflix.zuul.filters.route.RibbonCommand.run(RibbonCommand.java:103)
at org.springframework.cloud.netflix.zuul.filters.route.RibbonCommand.run(RibbonCommand.java:1)
at com.netflix.hystrix.HystrixCommand$1.call(HystrixCommand.java:298)

阅读 356

收藏
2020-05-30

共1个答案

小编典典

我们现在通过设置来解决zuul代理问题

ribbon.IsSecure=true
eureka.instance.secureVirtualHostName=${spring.application.name}

因此所有服务也都位于中的安全虚拟主机池中com.netflix.discovery.shared.Applications。这有助于发现过程在尤里卡中找到实例。

但是,Hystrix仪表板仍然存在类似问题

2020-05-30