ABTestingGateway灰度发布一些整理
abtestingwalk 的配置整理
原理:
nginx是目前使用较多的7层服务器,可以实现高性能的转发和响应;ABTestingGateway 是在 nginx 转发的框架内,在转向 upstream 前,根据 用户请求特征 和 系统的分流策略 ,查找出目标upstream,进而实现分流。
在以往的基于 nginx 实现的灰度系统中,分流逻辑往往通过 rewrite 阶段的 if 和 rewrite 指令等实现,优点是性能较高,缺点是功能受限、容易出错,以及转发规则固定,只能静态分流。针对这些缺点,我们设计实现了ABTestingGateway,
采用 ngx-lua 实现系统功能,通过启用lua-shared-dict和lua-resty-lock作为系统缓存和缓存锁,系统获得了较为接近原生nginx转发的性能。
一个应用的配置文件可以放在任意位置,不一定在原始的安装目录,启动的时候找到这个配置文件启动即可
例如
集成了abtesting之后1,启动redis(在ab,业务nginx,ab配置中有集成redis自动用他的锁,redis的配置在ab目录中),2,启动upstream(业务系统),
3,启动业务系统(ab系统的脚本在vip业务系统的nginx配置关联上,就有了切面(ab的脚本拦截监听)(一个大的nginx关联好了一切,用这个脚本启动nginx)),
这些中间件启动配置都在ab的目录中,加上配置即可联合abtest
版本不一致的解决原因:
brew安装的openresty版本与ABTestingGateway不一致导致的,将/usr/local/Cellar/openresty/1.13.6.2/lualib (1.13.6.2替换为您安装的版本)下的相关的lua文件拷贝覆盖ABTestingGateway/lualib下的文件,重启nginx即可
repo中的utils/conf文件夹中有灰度系统部署所需的最小示例
1. git clone https://github.com/SinaMSRE/ABTestingGateway
2. cd /path/to/ABTestingGateway/utils
#启动redis数据库
3. redis-server conf/redis.conf
#启动upstream server(业务系统),其中stable为默认upstream
4. /usr/local/nginx/sbin/nginx -p `pwd` -c conf/stable.conf
5. /usr/local/nginx/sbin/nginx -p `pwd` -c conf/beta1.conf
6. /usr/local/nginx/sbin/nginx -p `pwd` -c conf/beta2.conf
7. /usr/local/nginx/sbin/nginx -p `pwd` -c conf/beta3.conf
8. /usr/local/nginx/sbin/nginx -p `pwd` -c conf/beta4.conf
#启动灰度系统,proxy server,灰度系统的配置也写在conf/nginx.conf中
9. /usr/local/nginx/sbin/nginx -p `pwd` -c conf/nginx.conf
9. /usr/local/nginx/sbin/nginx -p `pwd` -c conf/nginx.conf
=======总配置文件的http配置===========
#user www www;
worker_processes auto;
# worker_cpu_affinity auto;# openresty-1.9.15
worker_rlimit_nofile 102400;
error_log logs/error.log;
pid logs/nginx.pid;
events {
use epoll;
worker_connections 10240;
}
http {
server_tokens off;
sendfile on;
tcp_nodelay on;
tcp_nopush on;
keepalive_timeout 0;
charset utf-8;
include mime.types;
default_type application/json;
log_format main '[$time_local]`$http_x_up_calling_line_id`"$request"`"$http_user_agent"`$staTus`[$remote_addr]`$http_x_log_uid`"$http_referer"`$request_time`$body_bytes_sent`$http_x_forwarded_proto`$http_x_forwarded_for`$http_host`$http_cookie`$upstream_response_time`xd';
client_header_buffer_size 4k;
large_client_header_buffers 8 4k;
server_names_hash_bucket_size 128;
client_max_body_size 8m;
client_header_timeout 30s;
client_body_timeout 30s;
send_timeout 30s;
lingering_close off;
gzip on;
gzip_vary on;
gzip_min_length 1000;
gzip_comp_level 6;
gzip_types text/plain text/xml text/css application/javascript application/json;
gzip_http_version 1.0;
#index index.html index.shtml index.php;
# include upstream.conf;
include upstream.conf; ## 不同的upstream配置 里面有具服务的rip--具体业务服务
include default.conf; ##abTestingwalking本身的配置
include vhost.conf; ## 项目nginx配置文件vip(在ab项目中加载进来项目nginx配置文件,方便修改操作,相当于abtestingwalk是项目nginx的切面(前置通知))
# lua_code_cache on;
lua_code_cache off;
lua_package_path "../?.lua;../lib/?.lua;../lib/lua-resty-core/lib/?.lua;;";
lua_need_request_body on;
}
==========不同upstream的配置===========
upstream beta2 {
server 127.0.0.1:8021 weight=10 fail_timeout=1 max_fails=3;
keepalive 256;
}
upstream beta3 {
server 127.0.0.1:8022 weight=10 fail_timeout=1 max_fails=3;
keepalive 256;
}
upstream beta1 {
server 127.0.0.1:8020 weight=1 fail_timeout=10 max_fails=1;
keepalive 1000;
}
upstream beta4 {
server 127.0.0.1:8023 weight=1 fail_timeout=10 max_fails=1;
keepalive 1000;
}
upstream stable {
server 127.0.0.1:8040 weight=1 fail_timeout=10 max_fails=1;
}
=============ABtestinggateway本身的设置======================
server {
listen 8080;
server_name localhost 127.0.0.1;
access_log logs/ip-access.log main;
error_log logs/admin.log error;
location / {
root html;
index index.html index.htm;
}
#location /nginx_status {
#stub_status on;
#access_log off;
#allow 127.0.0.1;
#}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
set $redis_host '127.0.0.1';
set $redis_port '6379';
set $redis_uds '/var/run/redis.sock';
set $redis_connect_timeout 10000;
set $redis_dbid 0;
set $redis_pool_size 1000;
set $redis_keepalive_timeout 90000;
location /ab_admin {
content_by_lua_file '../admin/ab_action.lua';
}
}
===================nginx应用项目配置(对外提供服务的vip)========================
lua_shared_dict api_root_sysConfig 1m;
lua_shared_dict kv_api_root_upstream 100m;
lua_shared_dict api_abc_sysConfig 1m;
lua_shared_dict kv_api_abc_upstream 100m;
server {
listen 8030;
server_name api.weibo.cn mapi.weibo.com;
access_log logs/vhost_access.log main;
error_log logs/vhost_error.log;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
set $redis_host '127.0.0.1';
set $redis_port '6379';
set $redis_uds '/var/run/redis.sock';
set $redis_connect_timeout 10000;
set $redis_dbid 0;
set $redis_pool_size 1000;
set $redis_keepalive_timeout 90000;
location ~* /abc/(i|f)/ {
set $hostkey $server_name.abc;
set $sysConfig api_abc_sysConfig;
set $kv_upstream kv_api_abc_upstream;
set $backend 'stable';
rewrite_by_lua_file '../diversion/diversion.lua';
proxy_pass http://$backend;
}
location / {
error_log logs/vhost_error.log debug;
set $hostkey $server_name;
set $sysConfig api_root_sysConfig;
set $kv_upstream kv_api_root_upstream;
set $backend 'stable';
rewrite_by_lua_file '../diversion/diversion.lua';
proxy_pass http://$backend;
}
}
=======具体服务地址=====
beta1.conf
==============其他文件================
参考:
http://www.cnblogs.com/beautiful-code/p/6278779.html
https://github.com/CNSRE/ABTestingGateway
https://blog.csdn.net/hueason/article/details/81054093