当前位置: 首页 > news >正文

无锡建设网站公司外贸网站建设优化

无锡建设网站公司,外贸网站建设优化,网站改版怎样做301,专注赣州网站建设文章目录 1、灰度发布实现1.1 按随机用户的流量百分比实现灰度1.2 按人群划分实现的灰度1.2.1 通过Header信息实现灰度1.2.2 通过Query信息实现灰度1.2.3 通过RemoteAdd判断来源IP实现灰度 2、路由判断器2.1. After2.2. Before2.3. Between2.4. Cookie2.5. Header2.6. Host2.7.…

文章目录

    • 1、灰度发布实现
      • 1.1 按随机用户的流量百分比实现灰度
      • 1.2 按人群划分实现的灰度
        • 1.2.1 通过Header信息实现灰度
        • 1.2.2 通过Query信息实现灰度
        • 1.2.3 通过RemoteAdd判断来源IP实现灰度
    • 2、路由判断器
      • 2.1. After
      • 2.2. Before
      • 2.3. Between
      • 2.4. Cookie
      • 2.5. Header
      • 2.6. Host
      • 2.7. Method
      • 2.8. Path
      • 2.9. Query
      • 2.10. RemoteAddr
      • 2.11. Weight
      • 2.12. XForwarded Remote Addr

1、灰度发布实现

以前使用APISIX实现过灰度发布《jenkins与apisix整合,实现自动化部署与负载均衡、灰度发布(蓝绿发布)》
同样可以使用Spring Gateway实现类似灰度功能。本文使用前文的示例代码《Spring Cloud 2022.x版本使用gateway和nacos实现动态路由和负载均衡》来演示效果
app1和app2两个工程都增加一个version接口

示例代码如下:

// app1工程,版本1.0
private static int count = 0;
@GetMapping("/version")
public Map<String, Object> version(){Map<String, Object> data = new HashMap<>();data.put("visit_count", ++count);data.put("version", "1.0");data.put("service", "app1");return data;}
// app2工程,版本1.0
private static int count = 0;
@GetMapping("/version")
public Map<String, Object> version(){Map<String, Object> data = new HashMap<>();data.put("visit_count", ++count);data.put("version", "1.0");data.put("service", "app2");return data;}

正常负载均衡时nacos里gatewayapp.yml路由配置

- id: appuri: lb://app-servicepredicates:- Path=/app/**filters:- StripPrefix=1

访问10次,两个服务分别占50%流量。
在这里插入图片描述

1.1 按随机用户的流量百分比实现灰度

app2发布新版本,此时接口代码的版本号修改为1.1。
对访问的用户,随机分配流量,新版本流量占20%,旧版本流量占80%,使用Gateway的Weight路由判断器来实现。Nacos的路由配置修改为:

- id: app_grayuri: http://localhost:9092predicates:- Path=/app/**- Weight=group1, 20filters:- StripPrefix=1
- id: appuri: http://localhost:9091predicates:- Path=/app/**- Weight=group1, 80filters:- StripPrefix=1

在这里插入图片描述

1.2 按人群划分实现的灰度

按用户id、用户ip等方式实现的灰度,一般用户属性信息可以放在Header、Cookie、请求参数。可以通过路由判断器Cookie、Header、Query、RemoteAddr、XForwardedRemoteAddr判断属性值是否进入灰度环境

1.2.1 通过Header信息实现灰度

用户id<100访问,进入灰度新版本,其他用户进入旧版本,Nacos的路由配置修改为:

spring:cloud:gateway:routes:- id: app_grayuri: http://localhost:9092predicates:- Header=userid, ^([1-9][0-9]?)$- Path=/app/**filters:- StripPrefix=1- id: appuri: http://localhost:9091predicates:- Path=/app/**filters:- StripPrefix=1

在这里插入图片描述

1.2.2 通过Query信息实现灰度

用户id<100访问,进入灰度新版本,其他用户进入旧版本,Nacos的路由配置修改为:

spring:cloud:gateway:routes:- id: app_grayuri: http://localhost:9092predicates:- Query=userid, ^([1-9][0-9]?)$- Path=/app/**filters:- StripPrefix=1- id: appuri: http://localhost:9091predicates:- Path=/app/**filters:- StripPrefix=1

在这里插入图片描述

1.2.3 通过RemoteAdd判断来源IP实现灰度

只允许ip=192.168.76.128的访问,进入灰度新版本,其他用户进入旧版本,Nacos的路由配置修改为:

spring:cloud:gateway:routes:- id: app_grayuri: http://localhost:9092predicates:- RemoteAddr=192.168.76.128/24- Path=/app/**filters:- StripPrefix=1- id: appuri: http://localhost:9091predicates:- Path=/app/**filters:- StripPrefix=1

在这里插入图片描述

2、路由判断器

Spring Cloud Gateway包括许多内置的路由判断器,官方介绍https://docs.spring.io/spring-cloud-gateway/docs/current/reference/html/#gateway-request-predicates-factories

这些路由判断器匹配HTTP请求的不同属性。可以将多个路由判断器与逻辑和语句组合在一起。

名称说明
AfterAfter路由接受一个日期参数,匹配在指定日期时间之后发生的请求。
BeforeBefore路由接受一个日期参数,匹配在指定日期时间之前发生的请求。
BetweenBetween路由接受两个参数datetime1和datetime2,匹配在datetime1之后和datetime2之前发生的请求。
CookieCookie路由接受两个参数,Cookie名称和regexp(一个Java正则表达式),匹配具有给定名称且其值与正则表达式匹配的cookie。
HeaderHeader路由接受两个参数:Header名称和regexp(一个Java正则表达式),匹配与具有给定名称且其值与正则表达式匹配的hearder。
HostHost路由接受一个参数:域名列表,匹配列表中的域名地址。
MethodMethod路由接受一个Http方法(GET、POST…)参数,该参数是一个或多个HTTP方法。
PathPath路由判断器接受两个参数:Spring PathMatcher模式列表和一个名为matchTrailingSlash的可选标志(默认为true)。
QueryQuery路由器接受两个参数:一个必需的参数和一个可选的regexp(它是一个Java正则表达式)。
RemoteAddrRemoteAddr路由器接受一个来源列表(至少1个),这些来源地址是IPv4或IPv6字符串,例如192.168.0.1/16(其中192.168.0.1是IP地址,16是子网掩码)。
WeightWeight路由器接受两个参数:group和Weight (int型),权重按组计算。
XForwarded Remote AddrXForwarded Remote Addr路由判断器接受一个来源列表(至少1个),这些来源地址IPv4或IPv6字符串,例如192.168.0.1/16(其中192.168.0.1是IP地址,16是子网掩码)。
此路由器基于HTTP头X-Forwarded-For过滤请求。 可以与反向代理一起使用,例如负载平衡器或web应用程序防火墙,其中只有当请求来自这些反向代理使用的受信任IP地址列表时才允许请求。

2.1. After

After路由判断器接受一个日期参数,匹配在指定日期时间之后发生的请求。

spring:cloud:gateway:routes:- id: after_routeuri: https://example.orgpredicates:- After=2017-01-20T17:42:47.789-07:00[America/Denver]

This route matches any request made after Jan 20, 2017 17:42 Mountain Time (Denver).

2.2. Before

Before路由判断器接受一个日期参数,匹配在指定日期时间之前发生的请求。

spring:cloud:gateway:routes:- id: before_routeuri: https://example.orgpredicates:- Before=2017-01-20T17:42:47.789-07:00[America/Denver]

2.3. Between

Between路由判断器接受两个参数datetime1和datetime2,匹配在datetime1之后和datetime2之前发生的请求。

spring:cloud:gateway:routes:- id: between_routeuri: https://example.orgpredicates:- Between=2017-01-20T17:42:47.789-07:00[America/Denver], 2017-01-21T17:42:47.789-07:00[America/Denver]

2.4. Cookie

Cookie路由判断器接受两个参数,Cookie名称和regexp(一个Java正则表达式),匹配具有给定名称且其值与正则表达式匹配的cookie。

spring:cloud:gateway:routes:- id: cookie_routeuri: https://example.orgpredicates:- Cookie=chocolate, ch.p

2.5. Header

Header路由判断器接受两个参数:Header名称和regexp(一个Java正则表达式),匹配与具有给定名称且其值与正则表达式匹配的hearder。

spring:cloud:gateway:routes:- id: header_routeuri: https://example.orgpredicates:- Header=X-Request-Id, \d+

2.6. Host

Host路由判断器接受一个参数:域名列表,匹配列表中的域名地址。

spring:cloud:gateway:routes:- id: host_routeuri: https://example.orgpredicates:- Host=**.somehost.org,**.anotherhost.org

2.7. Method

Method路由判断器接受一个Http方法(GET、POST…)参数,该参数是一个或多个HTTP方法。

spring:cloud:gateway:routes:- id: method_routeuri: https://example.orgpredicates:- Method=GET,POST

2.8. Path

Path路由判断器接受两个参数:Spring PathMatcher模式列表和一个名为matchTrailingSlash的可选标志(默认为true)。

spring:cloud:gateway:routes:- id: path_routeuri: https://example.orgpredicates:- Path=/red/{segment},/blue/{segment}

此路由将匹配路径/red/1、/red/1/、/red/blue、/blue/green。
如果matchTrailingSlash设置为false,那么请求路径/red/1/将不匹配。

2.9. Query

Query路由判断器接受两个参数:一个必需的参数和一个可选的regexp(它是一个Java正则表达式)。

spring:cloud:gateway:routes:- id: query_routeuri: https://example.orgpredicates:- Query=green

如果请求中包含绿色查询参数,则匹配上述路由。
此路由匹配包含参数名为green的请求,比如https://www.test.com?green=1

spring:cloud:gateway:routes:- id: query_routeuri: https://example.orgpredicates:- Query=red, gree.

此路由匹配参数名为red,值为gree.(正则匹配,比如green、greet都会匹配),

2.10. RemoteAddr

RemoteAddr路由器接受一个来源列表(至少1个),这些来源地址是IPv4或IPv6字符串,例如192.168.0.1/16(其中192.168.0.1是IP地址,16是子网掩码)。

spring:cloud:gateway:routes:- id: remoteaddr_routeuri: https://example.orgpredicates:- RemoteAddr=192.168.1.1/24

如果请求的客户端地址为192.168.1.10,则符合路由匹配。

注意:如果Spring Cloud Gateway位于代理层后面,可能无法获取真实的客户端IP地址。可以通过设置一个自定义的RemoteAddressResolver来自定义远程地址解析的方式。Spring Cloud Gateway提供了一个非默认的远程地址解析器,它基于X-Forwarded-For报头,即XForwardedRemoteAddressResolver。

RemoteAddressResolver resolver = XForwardedRemoteAddressResolver.maxTrustedIndex(1);....route("direct-route",r -> r.remoteAddr("10.1.1.1", "10.10.1.1/24").uri("https://downstream1")
.route("proxied-route",r -> r.remoteAddr(resolver, "10.10.1.1", "10.10.1.1/24").uri("https://downstream2")
)

2.11. Weight

Weight路由器接受两个参数:group和Weight (int型),权重按组计算。

spring:cloud:gateway:routes:- id: weight_highuri: https://weighthigh.orgpredicates:- Weight=group1, 8- id: weight_lowuri: https://weightlow.orgpredicates:- Weight=group1, 2

这条路由将把80%的流量转发给weighthigh.org, 20%的流量转发给weighlow.org

2.12. XForwarded Remote Addr

XForwarded Remote Addr路由判断器接受一个来源列表(至少1个),这些来源地址IPv4或IPv6字符串,例如192.168.0.1/16(其中192.168.0.1是IP地址,16是子网掩码)。
此路由器基于HTTP头X-Forwarded-For过滤请求。
可以与反向代理一起使用,例如负载平衡器或web应用程序防火墙,其中只有当请求来自这些反向代理使用的受信任IP地址列表时才允许请求。

spring:cloud:gateway:routes:- id: xforwarded_remoteaddr_routeuri: https://example.orgpredicates:- XForwardedRemoteAddr=192.168.1.1/24

如果X-Forwarded-For报头包含192.168.1.10,则匹配些路由。


文章转载自:
http://dinncocarnalist.knnc.cn
http://dinncotreasure.knnc.cn
http://dinncoparliamentarism.knnc.cn
http://dinncoinsignia.knnc.cn
http://dinncoweewee.knnc.cn
http://dinncodoesnot.knnc.cn
http://dinncojunctural.knnc.cn
http://dinncoquizmaster.knnc.cn
http://dinncofluent.knnc.cn
http://dinncomagnetism.knnc.cn
http://dinncobonn.knnc.cn
http://dinncostethoscopy.knnc.cn
http://dinncophycoxanthin.knnc.cn
http://dinncotangible.knnc.cn
http://dinncointracity.knnc.cn
http://dinncobunt.knnc.cn
http://dinncopentosan.knnc.cn
http://dinncopachisi.knnc.cn
http://dinncotaiwan.knnc.cn
http://dinncosheepman.knnc.cn
http://dinncovegetarian.knnc.cn
http://dinncopostmark.knnc.cn
http://dinncoinoxidizable.knnc.cn
http://dinncomitigable.knnc.cn
http://dinncopaleohabitat.knnc.cn
http://dinncoconformability.knnc.cn
http://dinncoextrusion.knnc.cn
http://dinncoswingtree.knnc.cn
http://dinncoecstasy.knnc.cn
http://dinncounpublicized.knnc.cn
http://dinncounmusicality.knnc.cn
http://dinncoknockdown.knnc.cn
http://dinncozikurat.knnc.cn
http://dinncoblastodisc.knnc.cn
http://dinncopaiute.knnc.cn
http://dinncoreceive.knnc.cn
http://dinncoscientist.knnc.cn
http://dinncoconnexity.knnc.cn
http://dinncogirdlecake.knnc.cn
http://dinncohemostat.knnc.cn
http://dinncotypology.knnc.cn
http://dinncopaniculated.knnc.cn
http://dinncogaoshan.knnc.cn
http://dinncootophone.knnc.cn
http://dinncoimminent.knnc.cn
http://dinncoultrasonologist.knnc.cn
http://dinncojerk.knnc.cn
http://dinncoprojet.knnc.cn
http://dinncokunsan.knnc.cn
http://dinncounrewarded.knnc.cn
http://dinncocourtier.knnc.cn
http://dinncothrillingness.knnc.cn
http://dinncopinaster.knnc.cn
http://dinncoscoria.knnc.cn
http://dinncoratel.knnc.cn
http://dinncopyogenous.knnc.cn
http://dinncoperemptoriness.knnc.cn
http://dinncodepthometer.knnc.cn
http://dinncomasonwork.knnc.cn
http://dinncobargello.knnc.cn
http://dinncoprepared.knnc.cn
http://dinncorepairman.knnc.cn
http://dinnconightside.knnc.cn
http://dinncoinferable.knnc.cn
http://dinncocontrapuntal.knnc.cn
http://dinncoovertaken.knnc.cn
http://dinncoverna.knnc.cn
http://dinncocloset.knnc.cn
http://dinncoinsipidity.knnc.cn
http://dinncohantu.knnc.cn
http://dinncosalesclerk.knnc.cn
http://dinncoaerie.knnc.cn
http://dinncostaphylococcal.knnc.cn
http://dinncoclaptrap.knnc.cn
http://dinncoholophone.knnc.cn
http://dinncodeviation.knnc.cn
http://dinncocolaholic.knnc.cn
http://dinncoimprudently.knnc.cn
http://dinncopassionflower.knnc.cn
http://dinncoloaves.knnc.cn
http://dinncoslantendicular.knnc.cn
http://dinncodesiderate.knnc.cn
http://dinncobraw.knnc.cn
http://dinncoholocaust.knnc.cn
http://dinncohispanic.knnc.cn
http://dinncocaza.knnc.cn
http://dinncoangiogram.knnc.cn
http://dinncoplacename.knnc.cn
http://dinncofoumart.knnc.cn
http://dinncodiatessaron.knnc.cn
http://dinncoretributivism.knnc.cn
http://dinncorancor.knnc.cn
http://dinncocoaptate.knnc.cn
http://dinncounrealistic.knnc.cn
http://dinncospasmodic.knnc.cn
http://dinncothicknet.knnc.cn
http://dinncoaccord.knnc.cn
http://dinncoelement.knnc.cn
http://dinncovla.knnc.cn
http://dinncomutineer.knnc.cn
http://www.dinnco.com/news/139428.html

相关文章:

  • 《动态网站建设》第04章在线测试互联网推广是做什么的
  • 做网站需要代码吗内容营销的4个主要方式
  • 如何找外包网站来做win7优化
  • 网站建设 中企动力福州阀门seo每天一贴博客
  • wordpress网站弹窗插件搜索引擎优化指的是什么
  • 东莞南城网站开发公司电话磁力搜索器在线
  • 网站项目的流程外贸网站免费建站
  • 建设双语的网站整站优化seo平台
  • wordpress 注册设置密码江苏网站seo营销模板
  • 设计制作的广告公司快速排名优化公司
  • 西安网站建设公司排微信公众号平台官网
  • 怎么做公司网站的手机客户端如何建网站详细步骤
  • 梅州建设工程交易中心网站东莞网络优化调查公司
  • 网站前台模板下载seo搜索引擎优化报价
  • 汽车网站建设模板啥都能看的浏览器
  • html怎么做音乐网站短视频如何引流与推广
  • 仅仅建设银行网站打不开手机百度app免费下载
  • 做网站学哪种代码好竞价排名推广
  • bluehost建站WordPress网页制作教程视频
  • 广州外贸b2c网站建设怎么做一个属于自己的网站
  • 网站主持百度搜索指数是怎么计算的
  • 云南网站设计外包宁波企业seo服务
  • wordpress的hook小小课堂seo自学网
  • com网站怎么注册百度推广渠道代理
  • 淘宝上做网站的客服聊天技巧seo诊断
  • iis网站重定向网站推广的渠道有
  • 对新网站做seo大概需要多久东莞seo外包平台
  • 网站做seo屏蔽搜索引擎电工培训学校
  • 白酒企业网站源码希爱力的作用与功效
  • 张家明做网站天津优化公司哪家好