基于nginx+lua简单的灰度发布系统
upstream.conf
upstream grey_1
{
keepalive 1000;
server localhost:8020;
} upstream grey_2
{
keepalive 1000;
server localhost:8021;
}
8020 conf
#vhost conf
server{
listen 8020;
index index.php index.html index.do;
root /var/html/webroot/grey_1; access_log "/data/logs/nginx/access.log" ;
error_log "/data/logs/nginx/error.log" warn; location / {
if ( !-e $request_filename ) {
rewrite ^/(.*) /index.php last;
}
} location ~ \.(php|do)($|/) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
set $path_info $request_uri;
if ( $request_uri ~ ^/(v\d)(\/.*)(\?.*)?$){
set $path_info $2;
break;
} fastcgi_param PATH_INFO $path_info;
}
}
8021 conf
#vhost conf
server{
listen 8021;
index index.php index.html index.do;
root /var/html/webroot/grey_2 access_log "/data/logs/nginx/access.log" ;
error_log "/data/logs/nginx/error.log" warn; location / {
if ( !-e $request_filename ) {
rewrite ^/(.*) /index.php last;
}
} location ~ \.(php|do)($|/) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
set $path_info $request_uri;
if ( $request_uri ~ ^/(v\d)(\/.*)(\?.*)?$){
set $path_info $2;
break;
} fastcgi_param PATH_INFO $path_info;
}
}
nginx.conf
#vhost conf
server{
listen 8000;
index index.php index.html index.do;
root /var/html/www/webroot/index; access_log /data/logs/index_access.log;
error_log /data/logs/index_error.log warn; lua_code_cache off; location /lua { content_by_lua '
ngx.say( "hello" )
';
} location / {
if ( !-e $request_filename ) {
rewrite ^/(.*) /index.php last;
}
} location /grey/ {
default_type 'text/plain';
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Connection "";
proxy_http_version 1.1; set $backend "grey_1";
rewrite_by_lua_file conf/lua/grey.proxy.lua;
proxy_pass http://$backend/?$args; }
grey.proxy.lua
local grey = require "greyrelease.grey" local upstream = grey.get_upstream_by_userid() -- ngx.say( upstream ) ngx.var.backend = upstream
grey.lua
local strings = require "resty.string"
local _M = {}
local hash_standard =
local hash_max_len =
local default_stream = "grey_1"
local search_stream = "grey_2"
local hash_map = {
-- grey_0 = {range_start=0,range_end=9,flow="grey1"},
grey_0 = {range_start=,range_end=,flow="grey1"},
grey_1 = {range_start=,range_end=,flow="grey1"},
grey_2 = {range_start=,range_end=,flow="grey1"},
grey_3 = {range_start=,range_end=,flow="grey1"},
grey_4 = {range_start=,range_end=,flow="grey1"},
grey_5 = {range_start=,range_end=,flow="grey1"},
grey_6 = {range_start=,range_end=,flow="grey1"},
grey_7 = {range_start=,range_end=,flow="grey1"},
grey_8 = {range_start=,range_end=,flow="grey1"},
grey_9 = {range_start=,range_end=,flow="grey1"},
}
function _M.get_upstream_by_userid()
if ngx.var.arg_grey_test == "grey_1" then
return search_stream
elseif ngx.var.arg_grey_test == "grey_2" then
return default_stream
end
local user_id=ngx.var.arg_user_id
local upstream=default_stream
if user_id == nil then
return upstream
end
local hex_string = strings.to_hex( user_id )
local str_len = string.len( hex_string )
local hash_string = ""
if str_len > hash_max_len then
hash_string = string.sub( hex_string,,hash_max_len )
else
hash_string = hex_string
end
local int_mod = math.fmod( hash_string,hash_standard )
for k,v in pairs( hash_map ) do
if v['range_start'] <= int_mod and int_mod < v['range_end'] then
upstream = v['flow']
break
end
end
return upstream
end
return _M
基于nginx+lua简单的灰度发布系统的更多相关文章
- nginx+lua+redis实现灰度发布_test
nginx+lua+redis实现灰度发布: 灰度发布是指在黑白之间能够平滑过渡的一种方式 AB test就是一种灰度发布方式,让一部分用户继续用A,一部分用户开始用B,如果用户对B没有什么反对意见, ...
- 利用nginx+lua+memcache实现灰度发布
一.灰度发布原理说明 灰度发布在百度百科中解释: 灰度发布是指在黑与白之间,能够平滑过渡的一种发布方式.AB test就是一种灰度发布方式,让一部分用户继续用A,一部分用户开始用B,如果用户对B没有什 ...
- 新浪的动态策略灰度发布系统:ABTestingGateway
原文链接:http://www.open-open.com/lib/view/open1439889185239.html ABTesingGateway 是一个可以动态设置分流策略的灰度发布系统,工 ...
- 基于nginx+lua+redis高性能api应用实践
基于nginx+lua+redis高性能api应用实践 前言 比较传统的服务端程序(PHP.FAST CGI等),大多都是通过每产生一个请求,都会有一个进程与之相对应,请求处理完毕后相关进程自动释放. ...
- 01 . OpenResty简介部署,优缺点,压测,适用场景及用Lua实现服务灰度发布
简介 OpenResty 是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库.第三方模块以及大多数的依赖项.用于方便地搭建能够处理超高并发.扩展性极高的动态 ...
- nginx 根据IP 进行灰度发布
灰度发布,简单来说,就是根据各种条件,让一部分用户使用旧版本,另一部分用户使用新版本. nginx 的语法本身可以看作是一门小型的编程语言,通过简单的编程,可以轻松实现基于IP的灰度发布. 需求:搭建 ...
- 基于nginx + lua实现的反向代理动态更新
大家都知道,nginx是当前应用非常广泛的web服务器,热度因为他的高并发高性能高可靠性,且轻量级!牛逼的不行,不多说这些. 今天要介绍的是,如何基于nginx和lua脚本,也就是在openresty ...
- 基于springcloud gateway + nacos实现灰度发布(reactive版)
什么是灰度发布? 灰度发布(又名金丝雀发布)是指在黑与白之间,能够平滑过渡的一种发布方式.在其上可以进行A/B testing,即让一部分用户继续用产品特性A,一部分用户开始用产品特性B,如果用户对B ...
- php简单手机商品发布系统
原本还说学学angular2的,没想到上一公司呆了两月就走了,现在在这个公司做了一个小型的商品发布系统,,php实现的,比较简单,功能不多,是以手机模板发布商品网站的,需要的可以拿去 http://p ...
随机推荐
- 使用HTML5/CSS3制作便签贴
利用HTML5/CSS3,仅用5步就可以制作便签贴效果的HTML页面,效果图如下: (注:图里的文字纯属杜撰,搞笑目的,如有雷同,纯属巧合,谢谢!) 注:该效果可以在Safari, Chrome,Fi ...
- php正则表达式匹配函数
<?php function show($var=null){ if(empty($var)) { echo 'null'; }else if(is_array($var) || is_obj ...
- javascript必知必会之prototype
本博客所有内容采用 Creative Commons Licenses 许可使用. 引用本内容时,请保留 朱涛, 出处 ,并且 非商业 . 点击 RSS 进行订阅.(推荐使用 google reade ...
- C#中Json字符串的各种应用类
在程序中任何事物及信息都可以用对象进行描述和承载,除了比较流行的xml之外,还有一种简洁快速处理目标信息的形式那就是Json格式. 首先Json格式有自己固定的格式:例如person这个对象就可以简单 ...
- 关于各种数据库 Insert时同时取到Id的操作
对数据库的操作,在Insert的同时获取到Id,保证原子性操作.而不是,先取Id,然后再插入到数据库等操作. Oracle: 使用Oracle自带的 Returning into 语句,具体代码示例如 ...
- ubuntu mysql编码设置5.5以后
安装了mysql. 版本:5.5.28 操作系统 :ubuntu 12.10 mysql> show variables like 'character%'; +---------------- ...
- html5的video标签支持的视频格式
- 《UNIX网络编程》UDP客户端服务器:消息回显
udp写的程序相比tcp简单一些,在socket()与bind()之后,不需要connect(),accept()等步骤,直接简化为了sendto()与recvfrom(). 编译运行同前面的tcp. ...
- 利用jQuery打造个性网站
网页结构 编写全局样式(reset.css) /*全局样式*/ body,h1,h2,h3,h4,h5,h6,hr,p,blockquote,dl,dt,dd,ul,ol,li,pre,form,fi ...
- Oracle EBS-SQL (WIP-1):检查非标任务没挂需求.sql
SELECT WE.WIP_ENTITY_NAME, MSI.SEGMENT1, MSI.DESCRIPTION, WDJ.CLASS_CODE, WDJ.START_QUANTITY, WDJ.SC ...