zoukankan      html  css  js  c++  java
  • 使用openresty实现按照流量百分比控制的灰度分流控制

    安装好以后直接就可以配置实践了,openresty将lua都集成好了,nginx配置文件无需特殊声明引入lua file。

    1.nginx.conf 添加两个灰度发布的环境 #grey 灰度环境地址 #prd生产环境地址

    http块操作

        upstream grey {
            server 127.0.0.1:8080;
        }
    
        upstream prd {
            server 139.162.116.84:8080;
        }
    

    server块操作,添加对应location

        location @grey{
            proxy_pass http://grey  
        }
    
       
    
        location @prd{
            proxy_pass http://prd  
        }
        
        # 在server 里根location指定lua文件
        location / {
            default_type 'text/html';
            content_by_lua_file /root/openresty/nginx/conf/lua_conf/grey.lua;
        }
    
    [root@luka77 lua_conf]# cat penresty/nginx/conf/lua_conf/grey.lua
    foreign_env = 'grey'
    china_env = 'prd'
    --流量比率
    abtest_num = 50   
    local num = math.random(100);
    if (num <= abtest_num) then
       ngx.log(ngx.INFO,'use foreign environment',foreign_env)
       ngx.exec("@"..foreign_env)
    else
       ngx.log(ngx.INFO,'use foreign environment',china_env)
       ngx.exec("@"..china_env)
    end
    
  • 相关阅读:
    IPUtil
    MD5Util
    MyBatis环境配置及入门
    淘宝主页(静态页面)第3天
    淘宝主页(静态页面)第二天
    淘宝主页(静态页面)第1天
    力扣20 有效的括号
    力扣1 two sum
    JAVA可变参数
    JAVA环形队列
  • 原文地址:https://www.cnblogs.com/sanduzxcvbnm/p/11325561.html
Copyright © 2011-2022 走看看