日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Mac下使用ABTestingGateway快速搭建灰度网关

發布時間:2025/6/17 51 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Mac下使用ABTestingGateway快速搭建灰度网关 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Mac下使用ABTestingGateway快速搭建灰度網關

ABTestingGateway簡介

ABTestingGateway 是新浪開源的一個可以動態設置分流策略的灰度發布系統,工作在7層,基于nginx和ngx-lua開發,使用 redis 作為分流策略數據庫,可以實現動態調度功能。

nginx是目前使用較多的7層服務器,可以實現高性能的轉發和響應;ABTestingGateway 是在 nginx 轉發的框架內,在轉向 upstream 前,根據 用戶請求特征 和 系統的分流策略 ,查找出目標upstream,進而實現分流。

環境搭建

1.安裝openresty

其是由Nginx核心加很多第三方模塊組成,其最大的亮點是默認集成了Lua開發環境,使得Nginx可以作為一個Web Server使用。借助于Nginx的事件驅動模型和非阻塞IO,可以實現高性能的Web應用程序。而且OpenResty提供了大量組件如Mysql、Redis、Memcached等等,使在Nginx上開發Web應用更方便更簡單。目前在京東如實時價格、秒殺、動態服務、單品頁、列表頁等都在使用Nginx+Lua架構,其他公司如淘寶、去哪兒網等。

安裝命令:brew install openresty

brew默認將openresty安裝在/usr/local/Cellar/openresty/目錄下

2.安裝luajit

JIT = Just In Time即時編譯,是動態編譯的一種形式,是一種優化虛擬機運行的技術。
程序運行通常有兩種方式,一種是靜態編譯,一種是動態解釋,即時編譯混合了這二者。Java和.Net/mono中都使用了這種技術。

安裝命令:brew install LuaJIT

brew默認將openresty安裝在/usr/local/Cellar/luajit/目錄下

3.安裝redis

安裝命令:brew install redis

啟動命令:brew services start redis

ABTestingGateway搭建

項目下載:

命令:git clone https://github.com/CNSRE/ABTestingGateway.git

下載后目錄結果如下

repo中的utils/conf文件夾中有灰度系統部署所需的最小示例

運行灰度網關

1. 進入ABTestingGateway目錄 2. 創建logs目錄,mkdir logs 3. 啟動redis 4. # 啟動upstream server,其中stable為默認upstream 4. /usr/local/Cellar/openresty/1.13.6.2/nginx/sbin/nginx -p `pwd` -c conf/stable.conf 5. /usr/local/Cellar/openresty/1.13.6.2/nginx/sbin/nginx -p `pwd` -c conf/beta1.conf 6. /usr/local/Cellar/openresty/1.13.6.2/nginx/sbin/nginx -p `pwd` -c conf/beta2.conf 7. /usr/local/Cellar/openresty/1.13.6.2/nginx/sbin/nginx -p `pwd` -c conf/beta3.conf 8. /usr/local/Cellar/openresty/1.13.6.2/nginx/sbin/nginx -p `pwd` -c conf/beta4.conf# 啟動灰度系統,proxy server,灰度系統的配置也寫在conf/nginx.conf中 9. /usr/local/Cellar/openresty/1.13.6.2/nginx/sbin/nginx -p `pwd` -c conf/nginx.conf

簡單驗證:添加分流策略組

$ curl 127.0.0.1:8080/ab_admin?action=policygroup_set -d '{"1":{"divtype":"uidsuffix","divdata":[{"suffix":"1","upstream":"beta1"},{"suffix":"3","upstream":"beta2"},{"suffix":"5","upstream":"beta1"},{"suffix":"0","upstream":"beta3"}]},"2":{"divtype":"arg_city","divdata":[{"city":"BJ","upstream":"beta1"},{"city":"SH","upstream":"beta2"},{"city":"XA","upstream":"beta1"},{"city":"HZ","upstream":"beta3"}]},"3":{"divtype":"iprange","divdata":[{"range":{"start":1111,"end":2222},"upstream":"beta1"},{"range":{"start":3333,"end":4444},"upstream":"beta2"},{"range":{"start":7777,"end":2130706433},"upstream":"beta2"}]}}'{"desc":"success ","code":200,"data":{"groupid":0,"group":[0,1,2]}}

分流規則簡介

  • ABTestingGateway灰度系統目前支持的策略有ip段分流、用戶uid段分流、uid尾數分流、uid白名單分流
  • 優先級由數字表示,從1開始,級別為1的策略優先級最高

以下共添加了3個分流規則,分別是用戶uid尾數分流、城市分流、ip段分流,具體請看json中的注釋
stable服務為默認的,未匹配到規則則分流到stable服務器上

{"1": {"divtype": "uidsuffix", "divdata": [{"suffix": "1", //http請求中header X-Uid尾數為1分流到beta1服務器"upstream": "beta1"}, {"suffix": "3", //http請求中header X-Uid尾數為3分流到beta2服務器"upstream": "beta2"}, {"suffix": "5", "upstream": "beta1"}, {"suffix": "0", "upstream": "beta3"}]}, "2": {"divtype": "arg_city", "divdata": [{"city": "BJ", // url上參數city=BJ,分流到beta1"upstream": "beta1"}, {"city": "SH", "upstream": "beta2"}, {"city": "XA", "upstream": "beta1"}, {"city": "HZ", "upstream": "beta3"}]}, "3": {"divtype": "iprange", "divdata": [{"range": {"start": 1111, "end": 2222}, "upstream": "beta1"}, {"range": {"start": 3333, "end": 4444}, "upstream": "beta2"}, {"range": {"start": 7777, "end": 2130706433}, "upstream": "beta2"}]} }

簡單驗證:設置運行時策略

$ curl "127.0.0.1:8080/ab_admin?action=runtime_set&hostname=api.weibo.cn&policygroupid=0"# 分流 $ curl 127.0.0.1:8030 -H 'X-Uid:39' -H 'X-Real-IP:192.168.1.1' this is stable server$ curl 127.0.0.1:8030 -H 'X-Uid:30' -H 'X-Real-IP:192.168.1.1' this is beta3 server$ curl 127.0.0.1:8030/?city=BJ -H 'X-Uid:39' -H 'X-Real-IP:192.168.1.1' this is beta1 server 注意

報錯:

2018/07/11 22:00:39 [error] 65912#7287282: *34 lua entry thread aborted: runtime error: ../lib/lua-resty-core/lib/ngx/semaphore.lua:64: dlsym(RTLD_DEFAULT, ngx_http_lua_ffi_semaphore_new): symbol not found stack traceback: coroutine 0:[C]: in function 'require'.../Nginx/ABTestingGateway/utils/../diversion/diversion.lua:11: in function <.../Nginx/ABTestingGateway/utils/../diversion/diversion.lua:1>, client: 127.0.0.1, server: api.weibo.cn, request: "GET / HTTP/1.1", host: "127.0.0.1:8030"

原因:

brew安裝的openresty版本與ABTestingGateway不一致導致的,將/usr/local/Cellar/openresty/1.13.6.2/lualib (1.13.6.2替換為您安裝的版本)下的相關的lua文件拷貝覆蓋ABTestingGateway/lualib下的文件,重啟nginx即可

總結

以上是生活随笔為你收集整理的Mac下使用ABTestingGateway快速搭建灰度网关的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。