Search code examples
spring-bootdockerspring-cloudnetflix-eurekanetflix-zuul

How to deal with docker deployed spring cloud application mutual access through zuul?


I deployed my spring cloud application in docker,include eureka server,zuul,eureka client. I want to access eureka client via zuul.

Zuul and eureka client are registered at eureka server.I access each application ,it is work. When I access eureka client via zuul, zuul console infomation show java.net.NoRouteToHostException. I don't know why and how to deal with this problem.

Eureka server config is like this.

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 config is like this.

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 client config is like this.

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

My test operate is like this.

I access the zuul by http://192.168.90.183:8088 ,it works well.

I access the eureka client by http://192.168.90.183:8926/getCityCenter , it works well.

When I access the eureka client via zuul by http://192.168.90.183:8088/371300/getCityCenter , it doesn't work.

The console show the information like this.

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

It seems the zuul can't find the router to eureka client of tdcm.

I tried to deployed all application on computer,include eureka server,zuul,eureka client,not in docker. The same config as this article descript,it works well. I don't know why it isn't work when access the eureka client via zuul in docker deployed.

I use the host computer IP address for spring cloud appliction.

My docker version is 17.12.1-ce.

My spring cloud version is Finchley.SR1.

My Spring boot version is 2.0.3.RELEASE.

My host computer is cent-os 7.

How can I deal with the problem?


Solution

  • I know the problem how to dealing.Eureka client config delete the yml value of ip-address.

    eureka:
      instance:
        ip-address: 192.168.90.183   
    

    The reason is eureka client config in the inner network of docker.It can access from zuul through inner network of docker.