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简单的灰度发布系统的更多相关文章

  1. nginx+lua+redis实现灰度发布_test

    nginx+lua+redis实现灰度发布: 灰度发布是指在黑白之间能够平滑过渡的一种方式 AB test就是一种灰度发布方式,让一部分用户继续用A,一部分用户开始用B,如果用户对B没有什么反对意见, ...

  2. 利用nginx+lua+memcache实现灰度发布

    一.灰度发布原理说明 灰度发布在百度百科中解释: 灰度发布是指在黑与白之间,能够平滑过渡的一种发布方式.AB test就是一种灰度发布方式,让一部分用户继续用A,一部分用户开始用B,如果用户对B没有什 ...

  3. 新浪的动态策略灰度发布系统:ABTestingGateway

    原文链接:http://www.open-open.com/lib/view/open1439889185239.html ABTesingGateway 是一个可以动态设置分流策略的灰度发布系统,工 ...

  4. 基于nginx+lua+redis高性能api应用实践

    基于nginx+lua+redis高性能api应用实践 前言 比较传统的服务端程序(PHP.FAST CGI等),大多都是通过每产生一个请求,都会有一个进程与之相对应,请求处理完毕后相关进程自动释放. ...

  5. 01 . OpenResty简介部署,优缺点,压测,适用场景及用Lua实现服务灰度发布

    简介 OpenResty 是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库.第三方模块以及大多数的依赖项.用于方便地搭建能够处理超高并发.扩展性极高的动态 ...

  6. nginx 根据IP 进行灰度发布

    灰度发布,简单来说,就是根据各种条件,让一部分用户使用旧版本,另一部分用户使用新版本. nginx 的语法本身可以看作是一门小型的编程语言,通过简单的编程,可以轻松实现基于IP的灰度发布. 需求:搭建 ...

  7. 基于nginx + lua实现的反向代理动态更新

    大家都知道,nginx是当前应用非常广泛的web服务器,热度因为他的高并发高性能高可靠性,且轻量级!牛逼的不行,不多说这些. 今天要介绍的是,如何基于nginx和lua脚本,也就是在openresty ...

  8. 基于springcloud gateway + nacos实现灰度发布(reactive版)

    什么是灰度发布? 灰度发布(又名金丝雀发布)是指在黑与白之间,能够平滑过渡的一种发布方式.在其上可以进行A/B testing,即让一部分用户继续用产品特性A,一部分用户开始用产品特性B,如果用户对B ...

  9. php简单手机商品发布系统

    原本还说学学angular2的,没想到上一公司呆了两月就走了,现在在这个公司做了一个小型的商品发布系统,,php实现的,比较简单,功能不多,是以手机模板发布商品网站的,需要的可以拿去 http://p ...

随机推荐

  1. MVC模式下My97DatePicker日期控件引用注意事项

    My97DatePicker日期控件之前在用webform模式开发的时候,只要 <script language="javascript" type="text/j ...

  2. MySQL之终端(Terminal)管理MySQL(转)

    前言:MySQL有很多的可视化管理工具,比如“mysql-workbench”和“sequel-pro-”. 现在我写MySQL的终端命令操作的文章,是想强化一下自己对于MySQL的理解,总会比使用图 ...

  3. About Health Monitor Checks

    About Health Monitor Checks Health Monitor checks (also known as checkers, health checks, or checks) ...

  4. 经典 SQL

    经典sql   总结一些经常用到或碰到的SQL语句,希望能与大家分享,同时也希望大家能提供更多的精妙SQL语句..... 1.delete table1 from (select * from tab ...

  5. C语言中两个相等的char值比较 结果为false

    unsigned char appendChar1[] = {0xD3, 0xD0, 0xCF, 0xDE, 0xB9, 0xAB, 0xCB, 0xBE}; char appendChar2[] = ...

  6. [Linked List]Reverse Nodes in k-Group

    Total Accepted: 48614 Total Submissions: 185356 Difficulty: Hard Given a linked list, reverse the no ...

  7. python-摩尔斯电码查询器

    主程序代码:morse_query.py #-*- coding: UTF-8 -*- ' __date__ = '2016/4/5' from Tkinter import * class mors ...

  8. 05-3. 求a的连续和(15)

    输入两个整数a和n,a的范围是[0,9],n的范围是[1,8],求数列之和S = a+aa+aaa+...+aaa...a(n个a). 如a为2.n为8时输出的是2+22+222+...+222222 ...

  9. Qt中添加OpenCV库

    配置在Qt中的OpenCV,看了很多“教程”,最终成功.记一下过程. 本机配置: window7 32位系统: qt-opensource-windows-x86-mingw492-5.5.1: Op ...

  10. 读懂系统负载(Load Avg)的含义 | Devops

    有过运维Linux服务器的选手,想必对于系统平均负载(load averages)参数不会陌生吧,我们可以通过top, htop, uptime这些命令找到它们(如下图),那么我们又改如何理解它们呢, ...