本文详细介绍了应用Nginx完成灰度释放。原文根据示例代码非常详细,对大家的学习培训或者工作都有一定的参考价值。有必要的朋友陪我去了解一下。
灰度是一种可以在白色和黑色之间平滑连接的出版方式。Test是一种灰度发布方式,允许一部分客户再次使用A,一部分客户刚开始使用B,如果客户对B没有抵触建议,就会逐渐扩大,将所有客户转移到B。
灰度的发布可以保证整个系统软件的稳定性,在原有灰度的情况下,可以发现问题并进行调整,保证其影响力。
通常,灰度释放有三种方法:
本文重点解读基于Cookie和homewardIP的简单灰度出版。NginxLUA等方法涉及内容太多,本文不发表。
A/B测试步骤
Nginx根据Cookie完成灰度发布
根据Cookie,检查Cookie键值作为版本。如果Cookie值V1共享给hilinux_01,如果是V2,则共享给hilinux_02。如果Cookie值不匹配,默认设置将是hilinux_01匹配的网络服务器。
两个网络服务器定义为:
用if命令完成。
upstreamhilinux_01{ server192.168.1.100:8080max_fails=1fail_timeout=60; } upstreamhilinux_02{ server192.168.1.200:8080max_fails=1fail_timeout=60; } upstreamdefault{ server192.168.1.100:8080max_fails=1fail_timeout=60; } server{ listen80; server_namewww.hi-linux.com; access_loglogs/www.hi-linux.com.logmain; #matchcookie set$group"default"; if($http_cookie~*"version=V1"){ set$grouphilinux_01; } if($http_cookie~*"version=V2"){ set$grouphilinux_02; } location/{ proxy_passhttp://$group; proxy_set_headerHost$host; proxy_set_headerX-Real-IP$remote_addr; proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for; indexindex.htmlindex.htm; } }用map命令完成
在Nginx中配备了投影,$COOKIE_version可以分析COOKIE中的版本字段名。$group是自变量,{}是投影标准。
如果有V1版本的客户浏览,$group相当于hilinux_01。服务器中的应用将被发送到http://hilinux_01。要浏览V2版本的客户,$group相当于hilinux_02。服务器中的应用将被发送到http://hilinux_02。如果Cookie值不匹配,默认设置将是hilinux_01匹配的网络服务器。
upstreamhilinux_01{ server192.168.1.100:8080max_fails=1fail_timeout=60; } upstreamhilinux_02{ server192.168.1.200:8080max_fails=1fail_timeout=60; } upstreamdefault{ server192.168.1.100:8080max_fails=1fail_timeout=60; } map$COOKIE_version$group{ ~*V1$hilinux_01; ~*V2$hilinux_02; defaultdefault; } server{ listen80; server_namewww.hi-linux.com; access_loglogs/www.hi-linux.com.logmain; location/{ proxy_passhttp://$group; proxy_set_headerHost$host; proxy_set_headerX-Real-IP$remote_addr; proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for; indexindex.htmlindex.htm; } }Nginx根据返回的IP
完成灰度释放
如果是内部IP,那么反向代理到hilinux_02(预公布自然环境);否则,反向代理到hilinux_01(工作环境)。
upstreamhilinux_01{ server192.168.1.100:8080max_fails=1fail_timeout=60; } upstreamhilinux_02{ server192.168.1.200:8080max_fails=1fail_timeout=60; } upstreamdefault{ server192.168.1.100:8080max_fails=1fail_timeout=60; } server{ listen80; server_namewww.hi-linux.com; access_loglogs/www.hi-linux.com.logmain; set$groupdefault; if($remote_addr~"211.118.119.11"){ set$grouphilinux_02; } location/{ proxy_passhttp://$group; proxy_set_headerHost$host; proxy_set_headerX-Real-IP$remote_addr; proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for; indexindex.htmlindex.htm; } }如果只有每台web服务器,可以根据不同的IP设置不同的URL和根目录,达到同样的目的。
server{ listen80; server_namewww.hi-linux.com; access_loglogs/www.hi-linux.com.logmain; set$rootdir"/var/www/html"; if($remote_addr~"211.118.119.11"){ set$rootdir"/var/www/test"; } location/{ root$rootdir; } }在解释完最基本的完成灰度释放的方式后,如果想做更粗粒度的灰度释放,请参考ABTestingGateway的新项目。
ABTestingGateway是新浪网开源系统的一款动态路由系统软件。ABTestingGateway是一款灰度出版系统软件,可以动态设置分色对策。它在7楼工作。按照nginx和ngx-lua开发设计,以redis作为分离对策的数据库查询,可以完成动态生产调度功能。
测试网关:https://github.com/CNSRE/ABTestingGateway
参见文本文档
http://www.google.com
http://www.jianshu.com/p/88f206f48278
http://。
关于应用Nginx完成灰度发布的这篇文章到此为止。有关Nginx灰度发布的大量内容,请搜索您以前的文章或再次访问下面的相关文章。期待你以后更多的应用!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)