如何处理 docker 部署的 Spring 云应用通过 zuul 相互访问?



我在docker中部署了我的Spring Cloud应用程序,包括尤里卡服务器,zuul,尤里卡客户端。我想通过 zuul 访问尤里卡客户端。

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

尤里卡服务器配置是这样的。

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

尤里卡客户端配置是这样的。

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 访问尤里卡客户端,它运行良好。

当我通过 zuul 访问尤里卡客户端时 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的尤里卡客户端的路由器。

我尝试在计算机上部署所有应用程序,包括尤里卡服务器,zuul,尤里卡客户端,而不是在码头工人中。与本文描述的相同配置,效果很好。我不知道为什么在部署的 docker 中通过 zuul 访问尤里卡客户端时它不起作用。

我使用主机 IP 地址进行春季云应用。

我的码头工人版本是 17.12.1-ce。

我的春季云版本是Finchley.SR1。

我的 Spring 启动版本是 2.0.3.RELEASE。

我的主机是 cent-os 7。

我该如何处理这个问题?

我知道如何处理问题。尤里卡客户端配置删除 IP 地址的 yml 值。

eureka:
instance:
ip-address: 192.168.90.183   

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

最新更新