日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時(shí)間:2025/6/17 编程问答 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Mac下使用ABTestingGateway快速搭建灰度网关 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Mac下使用ABTestingGateway快速搭建灰度網(wǎng)關(guān)

ABTestingGateway簡(jiǎn)介

ABTestingGateway 是新浪開(kāi)源的一個(gè)可以動(dòng)態(tài)設(shè)置分流策略的灰度發(fā)布系統(tǒng),工作在7層,基于nginx和ngx-lua開(kāi)發(fā),使用 redis 作為分流策略數(shù)據(jù)庫(kù),可以實(shí)現(xiàn)動(dòng)態(tài)調(diào)度功能。

nginx是目前使用較多的7層服務(wù)器,可以實(shí)現(xiàn)高性能的轉(zhuǎn)發(fā)和響應(yīng);ABTestingGateway 是在 nginx 轉(zhuǎn)發(fā)的框架內(nèi),在轉(zhuǎn)向 upstream 前,根據(jù) 用戶(hù)請(qǐng)求特征 和 系統(tǒng)的分流策略 ,查找出目標(biāo)upstream,進(jìn)而實(shí)現(xiàn)分流。

環(huán)境搭建

1.安裝openresty

其是由Nginx核心加很多第三方模塊組成,其最大的亮點(diǎn)是默認(rèn)集成了Lua開(kāi)發(fā)環(huán)境,使得Nginx可以作為一個(gè)Web Server使用。借助于Nginx的事件驅(qū)動(dòng)模型和非阻塞IO,可以實(shí)現(xiàn)高性能的Web應(yīng)用程序。而且OpenResty提供了大量組件如Mysql、Redis、Memcached等等,使在Nginx上開(kāi)發(fā)Web應(yīng)用更方便更簡(jiǎn)單。目前在京東如實(shí)時(shí)價(jià)格、秒殺、動(dòng)態(tài)服務(wù)、單品頁(yè)、列表頁(yè)等都在使用Nginx+Lua架構(gòu),其他公司如淘寶、去哪兒網(wǎng)等。

安裝命令:brew install openresty

brew默認(rèn)將openresty安裝在/usr/local/Cellar/openresty/目錄下

2.安裝luajit

JIT = Just In Time即時(shí)編譯,是動(dòng)態(tài)編譯的一種形式,是一種優(yōu)化虛擬機(jī)運(yùn)行的技術(shù)。
程序運(yùn)行通常有兩種方式,一種是靜態(tài)編譯,一種是動(dòng)態(tài)解釋,即時(shí)編譯混合了這二者。Java和.Net/mono中都使用了這種技術(shù)。

安裝命令:brew install LuaJIT

brew默認(rèn)將openresty安裝在/usr/local/Cellar/luajit/目錄下

3.安裝redis

安裝命令:brew install redis

啟動(dòng)命令:brew services start redis

ABTestingGateway搭建

項(xiàng)目下載:

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

下載后目錄結(jié)果如下

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

運(yùn)行灰度網(wǎng)關(guān)

1. 進(jìn)入ABTestingGateway目錄 2. 創(chuàng)建logs目錄,mkdir logs 3. 啟動(dòng)redis 4. # 啟動(dòng)upstream server,其中stable為默認(rèn)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# 啟動(dòng)灰度系統(tǒng),proxy server,灰度系統(tǒng)的配置也寫(xiě)在conf/nginx.conf中 9. /usr/local/Cellar/openresty/1.13.6.2/nginx/sbin/nginx -p `pwd` -c conf/nginx.conf

簡(jiǎn)單驗(yàn)證:添加分流策略組

$ 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]}}

分流規(guī)則簡(jiǎn)介

  • ABTestingGateway灰度系統(tǒng)目前支持的策略有ip段分流、用戶(hù)uid段分流、uid尾數(shù)分流、uid白名單分流
  • 優(yōu)先級(jí)由數(shù)字表示,從1開(kāi)始,級(jí)別為1的策略?xún)?yōu)先級(jí)最高

以下共添加了3個(gè)分流規(guī)則,分別是用戶(hù)uid尾數(shù)分流、城市分流、ip段分流,具體請(qǐng)看json中的注釋
stable服務(wù)為默認(rèn)的,未匹配到規(guī)則則分流到stable服務(wù)器上

{"1": {"divtype": "uidsuffix", "divdata": [{"suffix": "1", //http請(qǐng)求中header X-Uid尾數(shù)為1分流到beta1服務(wù)器"upstream": "beta1"}, {"suffix": "3", //http請(qǐng)求中header X-Uid尾數(shù)為3分流到beta2服務(wù)器"upstream": "beta2"}, {"suffix": "5", "upstream": "beta1"}, {"suffix": "0", "upstream": "beta3"}]}, "2": {"divtype": "arg_city", "divdata": [{"city": "BJ", // url上參數(shù)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"}]} }

簡(jiǎn)單驗(yàn)證:設(shè)置運(yùn)行時(shí)策略

$ 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 注意

報(bào)錯(cuò):

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不一致導(dǎo)致的,將/usr/local/Cellar/openresty/1.13.6.2/lualib (1.13.6.2替換為您安裝的版本)下的相關(guān)的lua文件拷貝覆蓋ABTestingGateway/lualib下的文件,重啟nginx即可

總結(jié)

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

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。