Nginx+Zuul 一主一备 或者 轮训多个

在微服务中,所有服务请求都会统一到Zuul网关上。

Nginx 配置:

  1. #user nobody;
  2. worker_processes 1;
  3.  
  4. #error_log logs/error.log;
  5. #error_log logs/error.log notice;
  6. #error_log logs/error.log info;
  7.  
  8. #pid logs/nginx.pid;
  9.  
  10. events {
  11. worker_connections 1024;
  12. }
  13.  
  14. http {
  15. include mime.types;
  16. default_type application/octet-stream;
  17.  
  18. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  19. # '$status $body_bytes_sent "$http_referer" '
  20. # '"$http_user_agent" "$http_x_forwarded_for"';
  21.  
  22. #access_log logs/access.log main;
  23.  
  24. sendfile on;
  25. #tcp_nopush on;
  26.  
  27. #keepalive_timeout 0;
  28. keepalive_timeout 65;
  29.  
  30. #gzip on;
  31.  
  32. upstream backServer{
  33. server 192.168.8.159:81;
  34. server 192.168.8.159:82;
  35. }
  36.  
  37. server {
  38. listen 80;
  39. server_name www.toov5.com;
  40.  
  41. location / {
  42.  
  43. ### 指定上游服务器负载均衡服务器
  44. proxy_pass http://backServer/;
  45. index index.html index.htm;
  46.  
  47. }
  48. }
  49.  
  50. }

  

网关:

yml:

  1. ###注册 中心
  2. eureka:
  3. client:
  4. serviceUrl:
  5. defaultZone: http://localhost:8100/eureka/
  6. server: ##api网关端口号
  7. port: 81
  8. ###网关名称
  9. spring: ##网关服务名称
  10. application:
  11. name: service-zuul
  12. ###网关名称
  13. cloud:
  14. config:
  15. ####读取后缀
  16. profile: dev
  17. ####读取config-server注册地址
  18. discovery:
  19. service-id: confi
  20.  
  21. ### 配置网关反向代理
  22. zuul:
  23. routes:
  24. api-member: ##随便写的
  25. ### 以 /api-member/访问转发到会员服务 通过别名找
  26. path: /api-member/**
  27. serviceId: app-toov5-member ##别名 如果集群的话 默认整合了ribbon 实现轮训 负载均衡
  28. api-order: ##随便写的
  29. ### 以 /api-order/访问转发到订单服务
  30. path: /api-order/**
  31. serviceId: app-toov5-order ##别名

  

启动类:

  1. package com.toov5;
  2.  
  3. import org.springframework.boot.SpringApplication;
  4. import org.springframework.boot.autoconfigure.SpringBootApplication;
  5. import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
  6. import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
  7.  
  8. @SpringBootApplication
  9. @EnableEurekaClient
  10. @EnableZuulProxy //开启网关代理
  11. public class AppGateway {
  12. public static void main(String[] args) {
  13. SpringApplication.run(AppGateway.class, args);
  14. }
  15. // //zuul配置使用config实现实时更新
  16. // @RefreshScope
  17. // @ConfigurationProperties("zuul")
  18. // public ZuulProperties zuulProperties() {
  19. // return new ZuulProperties();
  20. // }
  21.  
  22. }

访问:

启动两个网关  81和82

Spring Cloud之Zuul网关集群的更多相关文章

  1. spring cloud 通过zuul网关去请求的时候报404的几个原因。

    spring cloud 中 zuul 网关的那些坑: 1.检查你的服务是否正常启动. 2.检查你的服务是否正常注册到注册中心. 3.zuul网关的路由规则是会把你注册在注册中心的serviceId ...

  2. Spring Cloud(Dalston.SR5)--Config 集群配置中心

    Spring Cloud Config 是一个全新的项目,用来为分布式系统中的基础设施和微服务应用提供集中化的外部配置支持,他分为服务端和客户端两个部分.服务端也称为分布式配置中心,是一个独立的微服务 ...

  3. Spring Cloud Eureka 注册中心集群搭建,Greenwich 最新版!

    Spring Cloud 的注册中心可以由 Eureka.Consul.Zookeeper.ETCD 等来实现,这里推荐使用 Spring Cloud Eureka 来实现注册中心,它基于 Netfl ...

  4. Spring Cloud Turbine微服务集群实时监控

    本文代码下载地址: https://gitlab.com/mySpringCloud/turbine SpringBoot版本:1.5.9.RELEASE (稳定版) SpringCloud版本:Ed ...

  5. Spring Cloud系列-Zuul网关集成JWT身份验证

    前言 这两三年项目中一直在使用比较流行的spring cloud框架,也算有一定积累,打算有时间就整理一些干货与大家分享. 本次分享zuul网关集成jwt身份验证 业务背景 项目开发少不了身份认证,j ...

  6. Spring Cloud之Zuul网关路由

    前端请求先通过nginx走到zuul网关服务,zuul负责路由转发.请求过滤等网关接入层的功能,默认和ribbon整合实现了负载均衡 比如说你有20个服务,暴露出去,你的调用方,如果要跟20个服务打交 ...

  7. SpringCLoud之搭建Zuul网关集群

    1.使用技术 Springboot,SpringCloud,Zuul,Nignx 2.目的 使用Zuul搭建微服务高可用的网关 3.项目创建 3.1 创建注册中心(略) 3.2 创建一个hello-s ...

  8. Spring Cloud项目之断路器集群监控Hystrix Dashboard

    微服务(Microservices Architecture)是一种架构风格,一个大型复杂软件应用由一个或多个微服务组成.系统中的各个微服务可被独立部署,各个微服务之间是松耦合的.每个微服务仅关注于完 ...

  9. 【spring cloud】spring cloud中启动eureka集群时候,发生端口已经绑定的报错The Tomcat connector configured to listen on port 8000 failed to start. The port may already be in use or the connector may be misconfigured.

    在分别设置 进行微服务eureka集群启动时候,执行命令行启动jar包时候,报错前面一个端口8000已经被使用,而我这里启动的配置文件中端口号是8001,怎么会导致端口冲突呢?? 但是报错我的端口冲突 ...

随机推荐

  1. 不可忽略的apache 的 Keep Alive

    转载链接:http://hi.baidu.com/jx_iben/item/d5fe91feed74495ec9f337f1 在网页开发过程中,Keep-Alive是HTTP协议中非常重要的一个属性. ...

  2. jenkins和gitlab版本

  3. python学习 05 函数switch功能

    1.python没有switch功能,利用字典实现 如果用if else,可行但是效率不高

  4. 关于移动端border 1像素在不同分辨率下边显示粗细不一样的处理

    最近开发发现一个很有趣的问题  就是我如果给一个元素加上一个像素的 border 在不同的分辨率的情况下显示的不同 在高清屏幕(尤其是ios 喽 不鄙视国产) 据说在6plus下会变成3px  这个我 ...

  5. 写shader注意的一些报错

    1.Shader warning in 'Custom/1': Both vertex and fragment programs must be present in a CGPROGRAM. Ex ...

  6. Lumen开发:结合Redis实现消息队列(1)

    1.简介 Lumen队列服务为各种不同的后台队列提供了统一的API.队列允许你推迟耗时任务(例如发送邮件)的执行,从而大幅提高web请求速度. 1.1 配置 .env文件的QUEUE_DRIVER选项 ...

  7. linux下apache php配置redis

    1.安装redis 第一步: 下载:https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz 上传phpredis-2.2.4.tar.gz ...

  8. python 之前函数补充(__del__, item系列, __hash__, __eq__) , 以及模块初体验

    __str__ :  str(obj) ,  需求必须实现了 __str__, 要求这个方法的返回值必须是字符串  str  类型 __repr__ (意为原型输出):  是 __str__ 的备胎( ...

  9. hdu3579(线性同余方程组)

    Hello Kiki Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  10. Spring框架结构

    在processOn思维导图上看的一个程序员写的,挺不错的,分享出来,便于学习和回顾.