Skip to content

Commit

Permalink
add demo in utils/conf/nginx.conf
Browse files Browse the repository at this point in the history
  • Loading branch information
BG2BKK committed Apr 26, 2016
1 parent b13a150 commit abfe516
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 49 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

* nginx是目前使用较多的7层服务器,可以实现高性能的转发和响应;ABTestingGateway 是在 nginx 转发的框架内,在转向 upstream 前,根据 用户请求特征 和 系统的分流策略 ,查找出目标upstream,进而实现分流。

* ABTestingGateway 是新浪微博内部的动态路由系统 dygateway 的一部分,主要功能是:
* ABTestingGateway 是新浪微博内部的动态路由系统 dygateway 的一部分,因此本文档中的 dygateway 主要是指其子功能 ABTestingGateway。主要功能是:

ab功能简介
-------------------
Expand Down
3 changes: 0 additions & 3 deletions admin/policy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ local getPolicy = function()
local errinfo = ERRORINFO.PARAMETER_ERROR
local desc = 'postData is not a json string'
local response = doresp(errinfo, desc)

log:errlog(dolog(errinfo, desc))
ngx.say(response)
return nil
Expand Down Expand Up @@ -123,7 +122,6 @@ _M.check = function(option)

local response
if not valid then

log:errlog(dolog(err, desc))
response = doresp(err, desc)
else
Expand Down Expand Up @@ -199,7 +197,6 @@ _M.del = function(option)

local status, info = xpcall(pfunc, handler)
if not status then

local response = doerror(info)
ngx.say(response)
return false
Expand Down
4 changes: 3 additions & 1 deletion admin/runtime.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ local runtimeLib = prefixConf.runtimeInfoPrefix
local policyLib = prefixConf.policyLibPrefix
local domain_name = prefixConf.domainname
local divtypes = systemConf.divtypes

local fields = systemConf.fields

local runtimeGroupModule = require('abtesting.adapter.runtimegroup')
Expand Down Expand Up @@ -229,9 +228,12 @@ _M.runtimeset = function(option, policyId)
return false
end


local response = doresp(ERRORINFO.SUCCESS)
ngx.say(response)
return true
end



return _M
11 changes: 5 additions & 6 deletions utils/conf/default.conf
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
server
{
server {
listen 8080;
# server_name 172.16.15.103 127.0.0.1 localhost;
server_name localhost 127.0.0.1;
access_log /data1/l7/ip-access.log main;
error_log /data1/l7/admin.log;
access_log logs/ip-access.log main;
error_log logs/admin.log error;
location / {
root html;
index index.html index.htm;
Expand Down Expand Up @@ -46,8 +45,8 @@ server
set $redis_pool_size 1000;
set $redis_keepalive_timeout 90000;

location = /ab_admin {
content_by_lua_file '/usr/local/dygateway/luacode/ab/admin/ab_action.lua';
location /ab_admin {
content_by_lua_file '/usr/local/dygateway/admin/ab_action.lua';
}

}
12 changes: 5 additions & 7 deletions utils/conf/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
user www www;
#user www www;
worker_processes auto;
worker_cpu_affinity auto;
worker_rlimit_nofile 102400;
Expand Down Expand Up @@ -49,15 +49,13 @@ http {


# include upstream.conf;
include /etc/nginx/ups/upstream.conf;
include upstream.conf;
include default.conf;
include vhost.conf;


lua_code_cache on;
lua_package_path "/usr/local/dygateway/luacode/ab/?.lua;/usr/local/dygateway/luacode/ab/lib/?.lua;/usr/local/dygateway/luacode/ab/lib/lua-resty-core/lib/?.lua;;";
# lua_code_cache on;
lua_code_cache off;
lua_package_path "/usr/local/dygateway/?.lua;/usr/local/dygateway/lib/?.lua;/usr/local/dygateway/lib/lua-resty-core/lib/?.lua;;";
lua_need_request_body on;

}


33 changes: 14 additions & 19 deletions utils/conf/upstream.conf
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
upstream stable{
keepalive 1000;
server localhost:8040;
upstream beta2 {
server 127.0.0.1:8023 weight=10 fail_timeout=1 max_fails=3;
keepalive 256;
}

upstream beta1 {
keepalive 1000;
server localhost:8020;
upstream beta3 {
server 127.0.0.1:8021 weight=10 fail_timeout=1 max_fails=3;
keepalive 256;
}

upstream beta2 {
keepalive 1000;
server localhost:8021;
upstream beta1 {
server 127.0.0.1:8020 weight=1 fail_timeout=10 max_fails=1;
keepalive 1000;
}

upstream beta3 {
keepalive 1000;
server 127.1.0.1:8022;

# check interval=3000 rise=2 fall=5 timeout=1000 type=http;
# check_http_send "HEAD / HTTP/1.0\r\n\r\n";
# check_http_expect_alive http_2xx http_3xx;
upstream beta4 {
server 127.0.0.1:8023 weight=1 fail_timeout=10 max_fails=1;
keepalive 1000;
}

upstream beta4 {
keepalive 1000;
server localhost:8023;
upstream stable {
server 127.0.0.1:8040 weight=1 fail_timeout=10 max_fails=1;
}

25 changes: 14 additions & 11 deletions utils/conf/vhost.conf
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
lua_shared_dict api_root_sysConfig 1m;
lua_shared_dict kv_api_root_upstream 100m;

lua_shared_dict api_interface_sysConfig 1m;
lua_shared_dict kv_api_interface_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 /data1/l7/vhost_access.log main;
error_log /data1/l7/vhost_error.log;
access_log logs/vhost_access.log main;
error_log logs/vhost_error.log;

uniqueid_prefix 100;

Expand All @@ -26,20 +26,23 @@ server {
set $redis_keepalive_timeout 90000;

location ~* /abc/(i|f)/ {
set $hostkey $server_name.interface;
set $sysConfig api_interface_sysConfig;
set $kv_upstream kv_api_interface_upstream;
set $backend 'v9';
rewrite_by_lua_file '/usr/local/dygateway/luacode/ab/diversion/diversion.lua';
set $hostkey $server_name.abc;
set $sysConfig api_abc_sysConfig;
set $kv_upstream kv_api_abc_upstream;
set $backend 'stable';
rewrite_by_lua_file '/usr/local/dygateway/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 'v8';
rewrite_by_lua_file '/usr/local/dygateway/luacode/ab/diversion/diversion.lua';
set $backend 'stable';
rewrite_by_lua_file '/usr/local/dygateway/diversion/diversion.lua';
proxy_pass http://$backend;
}
}
Expand Down
2 changes: 1 addition & 1 deletion utils/pytool/cmd.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
* dygateway命令脚本说明文档,* 号开头的行是注释,文档前面是接口使用说明
* 所有命令的参数都不应该为空,以一个 | 号隔开

host: 10.13.112.53:8080
host: 127.0.0.1:8080

* del_upstream: stable
* get_upstream:
Expand Down

0 comments on commit abfe516

Please sign in to comment.