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

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

Nginx 配置:

#user  nobody;
worker_processes 1; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections 1024;
} http {
include mime.types;
default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout 0;
keepalive_timeout 65; #gzip on; upstream backServer{
server 192.168.8.159:81;
server 192.168.8.159:82;
} server {
listen 80;
server_name www.toov5.com; location / { ### 指定上游服务器负载均衡服务器
proxy_pass http://backServer/;
index index.html index.htm; }
} }

  

网关:

yml:

###注册 中心
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8100/eureka/
server: ##api网关端口号
port: 81
###网关名称
spring: ##网关服务名称
application:
name: service-zuul
###网关名称
cloud:
config:
####读取后缀
profile: dev
####读取config-server注册地址
discovery:
service-id: confi ### 配置网关反向代理
zuul:
routes:
api-member: ##随便写的
### 以 /api-member/访问转发到会员服务 通过别名找
path: /api-member/**
serviceId: app-toov5-member ##别名 如果集群的话 默认整合了ribbon 实现轮训 负载均衡
api-order: ##随便写的
### 以 /api-order/访问转发到订单服务
path: /api-order/**
serviceId: app-toov5-order ##别名

  

启动类:

package com.toov5;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy; @SpringBootApplication
@EnableEurekaClient
@EnableZuulProxy //开启网关代理
public class AppGateway {
public static void main(String[] args) {
SpringApplication.run(AppGateway.class, args);
}
// //zuul配置使用config实现实时更新
// @RefreshScope
// @ConfigurationProperties("zuul")
// public ZuulProperties zuulProperties() {
// return new ZuulProperties();
// } }

访问:

启动两个网关  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. OrCAD16.6中对比两份DSN文件的方法

    OrCAD16.6中对比两份改版前后DSN文件的方法 两种方法: (1)第一种用软件对比netlist (2)用orcad自带的对比功能 一.将两份要对比的原理图都生成orTelesis.dll格式的 ...

  2. Eureka 源码编译安装部署---Eureka运行eureka-server服务

    ---恢复内容开始--- 折腾了几天,终于运行好了,两个字:佩服 首先感谢这个大佬的博客支持:https://www.cnblogs.com/lifuping/p/5663127.html 1.首先在 ...

  3. kafka eagle 使用教程

    下载 地址:http://download.smartloli.org/ github:https://github.com/smartloli/kafka-eagle 环境 Windows: 安装J ...

  4. VSCode调试.net core 2.0 输出窗口乱码

    Q:输出窗口乱码 A:修改.vscode文件夹下,tasks.json文件,具体内容见图

  5. 大师养成计划之一:搭建springmvc框架

    搭建spring-mvc框架 搭建spring-mvc框架步骤: 1.搭建web项目spring-mvc1 2.引入jar包 3.配置web.xml 3.1拷贝头文件: <web-app xml ...

  6. CAP理论学习

    CAP理论是对分布式系统的3个特性所下的一个定性的结论,可用于指导分布式系统的设计. CAP理论断言任何基于网络的数据共享系统,最多只能满足数据一致性.可用性.分区容忍性三要素中的两个要素. 在英语中 ...

  7. eclipse 导入maven 父子项目

    你先要确认svn上是否是maven项目,否则要自己重新建一个maven项目然后直接引入目录了.如果确认是maven项目,那么有个两个方案.案一:先用任何client软件将svn下载.然后在eclips ...

  8. Java学习篇之---json-lib(Maven)

    json-lib(Maven) java中用于解释json的主流工具有org.json.json-lib与gson.本篇文章介绍json-lib. 项目中要用到json-lib.在pom.xml文件里 ...

  9. 安装android Studio和运行react native项目(跳坑篇)

    1.需配环境变量,值为sdk的地址. ANDROID_HOME  值:E:\Users\HP\AppData\Local\Android\sdk 2.下载gradle-2.14.1-all.zip 包 ...

  10. 仿百度壁纸client(五)——实现搜索动画GestureDetector手势识别,动态更新搜索keyword

    仿百度壁纸client(五)--实现搜索动画GestureDetector手势识别,动态更新搜索关键字 百度壁纸系列 仿百度壁纸client(一)--主框架搭建,自己定义Tab + ViewPager ...