标签:异常 路由 禁用 匹配 com zuul path 搭建 app
//第一台 server: port: 8001 spring: application: name: eureka-server eureka: server: use-read-only-response-cache: false #禁用readOnlyMap,分为ReadWriteMap和ReadOnlyMap eviction-interval-timer-in-ms: 3000 #主动失效检测时间 instance: hostname: server8001 client: # register-with-eureka: false #false表示不将自己也作为服务注册到eureka # fetch-registry: false service-url: #集群设置,搭建eureka集群,用逗号分隔 defaultZone: http://localhost:8002/eureka/,http://localhost:8003/eureka/ //第二台 server: port: 8002 spring: application: name: eureka-server eureka: server: use-read-only-response-cache: false eviction-interval-timer-in-ms: 3000 instance: hostname: server8002 client: # register-with-eureka: false #表示不将自己作为服务注册进eureka # fetch-registry: false service-url: #集群设置,搭建eureka集群,用逗号分隔,defaultZone是map类型,所以没有提示 defaultZone: http://localhost:8001/eureka/,http://localhost:8003/eureka/ //第三台 server: port: 8003 spring: application: name: eureka-server eureka: server: use-read-only-response-cache: false eviction-interval-timer-in-ms: 3000 instance: hostname: server8003 client: # register-with-eureka: false #表示不将自己作为服务注册进eureka # fetch-registry: false service-url: #集群设置,搭建eureka集群,用逗号分隔,defaultZone是map类型,所以没有提示 defaultZone: http://localhost:8001/eureka/,http://localhost:8002/eureka/
//第一台 server: port: 9001 spring: application: name: eureka-client eureka: client: service-url: # 指定集群服务器列表 defaultZone: http://localhost:8001/eureka/,http://localhost:8002/eureka/,http://localhost:8003/eureka/ instance: instance-id: client9001.com prefer-ip-address: true lease-renewal-interval-in-seconds: 5 #发送心跳包服务刷新时间 lease-expiration-duration-in-seconds: 15 #服务过期时间 //第二台 server: port: 9002 spring: application: name: eureka-client eureka: client: service-url: # 指定集群服务器列表 defaultZone: http://localhost:8001/eureka/ instance: instance-id: client9002.com prefer-ip-address: true lease-renewal-interval-in-seconds: 5 #发送心跳包服务刷新时间 lease-expiration-duration-in-seconds: 15 #服务过期时间
添加EnableEurekaClient注解,并添加api业务测试接口
3、zuul负载均衡服务
server: port: 9100 spring: application: name: zuul-gateway eureka: client: service-url: defaultZone: http://localhost:8001/eureka,http://localhost:8002/eureka,http://localhost:8003/eureka registry-fetch-interval-seconds: 5 #拉取服务列表时间 instance: instance-id: gateway-9100.com prefer-ip-address: true zuul: prefix: /gateway ignored-services: eureka-client routes: eureka-client.serviceId: eureka-client eureka-client.path: /client/**
依次启动Eureka服务器、服务提供者client,zull服务,访问其中一台Eureka服务器的控制台显示如下
不停刷新页面,会在9001和9002之间切换,证明配置成功,关闭9002应用,刷新页面,刚开始还会出现访问失败,过了一段时间后就稳定了,
会有一个时间差,也可以给zuul配置熔断器来进行服务降级或者转发请求到其他正常服务。
springCloud搭建微服务集群+Zuul服务器端负载均衡
标签:异常 路由 禁用 匹配 com zuul path 搭建 app
原文地址:https://www.cnblogs.com/zhouyun-yx/p/12009950.html