【问题标题】:How to deal with docker deployed spring cloud application mutual access through zuul?如何处理docker部署的spring cloud应用通过zuul互访?
【发布时间】:2019-08-20 01:10:20
【问题描述】:

我在docker中部署了spring cloud应用,包括eureka server,zuul,eureka client。我想通过zuul访问eureka客户端。

Zuul 和 eureka 客户端在 eureka 服务器上注册。我访问每个应用程序,它是工作。当我通过zuul访问eureka客户端时,zuul控制台信息显示java.net.NoRouteToHostException。我不知道为什么以及如何处理这个问题。

Eureka 服务器配置是这样的。

server:
  port: 1020
spring:
  application:
    name: eureka-server
  security:
    basic:
      enabled: true
    user:
      name: admin
      password: admin

eureka:
  client:
    fetch-registry: true
    register-with-eureka: true
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
  instance:
    hostname: 192.168.90.183
    prefer-ip-address: true
    ip-address: 192.168.90.183
  server:
    enable-self-preservation: false
    eviction-interval-timer-in-ms: 5000
management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    shutdown:
      enabled: true

Zuul 的配置是这样的。

server:
  port: 8088
spring:
  application:
    name: gateway
  security:
    oauth2:
management:
  security:
    enabled: false 
  endpoints:
    web:
      exposure:
        exclude: refresh,health,info 
ribbon:
  ReadTimeout: 20000 
  SocketTimeout: 20000
zuul:
  # sensitiveHeaders: "*"
  routes:
    tdcm-linyi:
      path: /371300/**
      serviceId: tdcm

  ratelimit:
    key-prefix: your-prefix  
    enabled: true
    behind-proxy: true  
    default-policy: 
      limit: 100 
      quota: 1000 
      refresh-interval: 60
      type: 
      - user
      - origin
      - url
  host:
    connect-timeout-millis: 20000
    socket-timeout-millis: 20000

#================================eureka setting==============================
eureka:
  instance:
    instance-id: ${eureka.instance.hostname}:${server.port}
    hostname: 192.168.90.183
    prefer-ip-address: true
    ip-address: 192.168.90.183    
    lease-expiration-duration-in-seconds: 10 
    lease-renewal-interval-in-seconds: 5 
  client:
    serviceUrl:
      defaultZone:  http://admin:admin@${EUREKA_HOST:192.168.90.183}:${EUREKA_PORT:1020}/eureka 
    fetch-registry: true
    register-with-eureka: true

Eureka 客户端配置是这样的。

spring:
  application:
    name: tdcm
  banner:
    charset: UTF-8
  http:
    encoding:
      charset: UTF-8
      enabled: true
      force: true
  messages:
    encoding: UTF-8
  mvc:
    throw-exception-if-no-handler-found: true
# Server
server:
  port: 8926
  tomcat:
    uri-encoding: UTF-8
#================================eureka settinig==============================
eureka:
  instance:
    instance-id: ${eureka.instance.hostname}:${server.port}
    hostname: 192.168.90.183
    prefer-ip-address: true
    ip-address: 192.168.90.183
    lease-expiration-duration-in-seconds: 10  
    lease-renewal-interval-in-seconds: 5 
  client:
    serviceUrl:
      defaultZone:  http://admin:admin@${EUREKA_HOST:192.168.90.183}:${EUREKA_PORT:1020}/eureka 
    fetch-registry: true
    register-with-eureka: true

我的测试操作是这样的。

我通过http://192.168.90.183:8088访问zuul,效果很好。

我通过http://192.168.90.183:8926/getCityCenter访问eureka客户端,效果很好。

当我通过 zuul 访问 eureka 客户端时 http://192.168.90.183:8088/371300/getCityCenter ,它不起作用。

控制台显示这样的信息。

03-29 01:55:27.229 INFO  [c.n.loadbalancer.DynamicServerListLoadBalancer] - DynamicServerListLoadBalancer for client tdcm initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=tdcm,current list of Servers=[192.168.90.183:8926],Load balancer stats=Zone stats: {defaultzone=[Zone:defaultzone;    Instance count:1;   Active connections count: 0;    Circuit breaker tripped count: 0;   Active connections per server: 0.0;]
},Server stats: [[Server:192.168.90.183:8926;   Zone:defaultZone;   Total Requests:0;   Successive connection failure:0;    Total blackout seconds:0;   Last connection made:Thu Jan 01 00:00:00 UTC 1970;  First connection made: Thu Jan 01 00:00:00 UTC 1970;    Active Connections:0;   total failure count in last (1000) msecs:0; average resp time:0.0;  90 percentile resp time:0.0;    95 percentile resp time:0.0;    min resp time:0.0;  max resp time:0.0;  stddev resp time:0.0]
]}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList@3275110f
03-29 01:55:28.201 INFO  [com.netflix.config.ChainedDynamicProperty] - Flipping property: tdcm.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
03-29 01:55:28.545 INFO  [org.apache.http.impl.execchain.RetryExec] - I/O exception (java.net.NoRouteToHostException) caught when processing request to {}->http://192.168.90.183:8926: No route to host (Host unreachable)
03-29 01:55:28.546 INFO  [org.apache.http.impl.execchain.RetryExec] - I/O exception (java.net.NoRouteToHostException) caught when processing request to {}->http://192.168.90.183:8926: No route to host (Host unreachable)
03-29 01:55:28.546 INFO  [org.apache.http.impl.execchain.RetryExec] - Retrying request to {}->http://192.168.90.183:8926
03-29 01:55:28.546 INFO  [org.apache.http.impl.execchain.RetryExec] - Retrying request to {}->http://192.168.90.183:8926
03-29 01:55:28.547 INFO  [org.apache.http.impl.execchain.RetryExec] - I/O exception (java.net.NoRouteToHostException) caught when processing request to {}->http://192.168.90.183:8926: No route to host (Host unreachable)
03-29 01:55:28.548 INFO  [org.apache.http.impl.execchain.RetryExec] - Retrying request to {}->http://192.168.90.183:8926
03-29 01:55:28.555 ERROR [c.t.gateway.component.exception.ProducerFallback] - s:tdcm
03-29 01:55:28.556 ERROR [c.t.gateway.component.exception.ProducerFallback] - exception: null
03-29 01:55:29.549 ERROR [c.t.gateway.component.exception.ProducerFallback] - s:tdcm
03-29 01:55:29.550 ERROR [c.t.gateway.component.exception.ProducerFallback] - exception: null
03-29 01:55:29.550 ERROR [c.t.gateway.component.exception.ProducerFallback] - s:tdcm
03-29 01:55:29.551 ERROR [c.t.gateway.component.exception.ProducerFallback] - exception: null
03-29 01:55:29.549 ERROR [c.t.gateway.component.exception.ProducerFallback] - s:tdcm
03-29 01:55:29.552 ERROR [c.t.gateway.component.exception.ProducerFallback] - exception: null
03-29 01:55:37.508 ERROR [c.t.gateway.component.exception.ProducerFallback] - s:tdcm
03-29 01:55:37.510 ERROR [c.t.gateway.component.exception.ProducerFallback] - exception: null
03-29 01:55:39.031 ERROR [c.t.gateway.component.exception.ProducerFallback] - s:tdcm
03-29 01:55:39.033 ERROR [c.t.gateway.component.exception.ProducerFallback] - exception: null

好像zuul找不到tdcm的eureka客户端的路由器。

我尝试在计算机上部署所有应用程序,包括 eureka 服务器、zuul、eureka 客户端,而不是在 docker 中。与本文描述的配置相同,效果很好。不知道为什么在docker部署的时候通过zuul访问eureka客户端就不行了。

我使用spring cloud应用的主机IP地址。

我的 docker 版本是 17.12.1-ce。

我的 Spring Cloud 版本是 Finchley.SR1。

我的 Spring Boot 版本是 2.0.3.RELEASE。

我的主机是cent-os 7。

我该如何处理这个问题?

【问题讨论】:

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


    【解决方案1】:

    我知道问题怎么处理了。Eureka客户端配置删除ip-address的yml值。

    eureka:
      instance:
        ip-address: 192.168.90.183   
    

    原因是docker内网的eureka客户端配置,可以通过docker内网从zuul访问。

    【讨论】:

      猜你喜欢
      • 2015-10-25
      • 2019-08-18
      • 2016-06-24
      • 2017-04-23
      • 2016-11-21
      • 2019-10-02
      • 1970-01-01
      • 2016-07-11
      • 2020-02-24
      相关资源
      最近更新 更多