Skip to content

Commit 6654012

Browse files
authored
Merge pull request #240 from sumory/v0.7.0-dev
V0.7.0
2 parents d3ca8e5 + 36b9702 commit 6654012

File tree

88 files changed

+8251
-203
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+8251
-203
lines changed

.github/issue_template.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
针对`Orange使用`的提问, 对于简单几句话描述不清的问题, 请使用以下格式, 不符合格式或描述含糊不清的issue将不予回复。
1+
针对`Orange使用`的提问,对于简单几句话描述不清的问题,请使用以下格式,不符合格式或描述含糊不清的issue将不予回复。根据问题模板填写好后,提问之前请去除模板的无用内容。
2+
3+
##### 使用的Orange版本
4+
5+
如v0.7.0
26

37
##### 需求或场景
48

@@ -10,13 +14,13 @@
1014

1115
##### 具体的配置
1216

13-
在插件里做了什么配置, 可以截图, 一定要描述清楚你的配置
17+
在插件里做了什么配置,可以截图,一定要描述清楚你的配置
1418

1519
##### 期望的结果
1620

17-
按你选用的插件和所做的配置, 你期望的结果是什么? 比如访问了哪个URL, 参数都是什么, 期望的输出是什么
21+
按你选用的插件和所做的配置,你期望的结果是什么?比如访问了哪个URL,参数都是什么,期望的输出是什么
1822

1923
##### 错误的结果
2024

21-
描述实际的结果, 比如错误的输出或截图
25+
描述实际的结果,比如错误的输出或截图
2226

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
### v0.7.0 2019
2+
3+
- 支持通过cookie、随机数、HTTP method进行拦截过滤
4+
- 新增取余的方式进行匹配规则
5+
- 新增kafka、balancer、consul_balancer、persist log、node插件
6+
- 修复一些已知bug:后台页面展示异常
7+
- 对后台页面、balancer等模块的代码和文档说明的重构
8+
- 修复了issue#160,解决balancer开关未打开时出现invalid URL prefix in "" 的错误
9+
- 修复了issue#162,解决选择器类型为1时continue=false的错误
10+
- 修复了issue#233,解决proxy read timeout配置无效的问题
11+
- 修复了issue#236,解决忽略大小写进行匹配鉴权值的问题
12+
- 修改Makefile
13+
- 使用指定版的依赖
14+
15+
116
### v0.6.4 2017.05.16
217

318
- 修复issue#110, 解决在添加/删除规则后本地js cache未更新,之后立刻更改选择器配置造成的规则丢失bug

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ init-config:
88
@ test -f conf/nginx.conf || (cp conf/nginx.conf.example conf/nginx.conf && echo "copy nginx.conf")
99
@ test -f conf/orange.conf || (cp conf/orange.conf.example conf/orange.conf && echo "copy orange.conf")
1010

11+
deps:init-config
12+
mkdir -p resty
13+
wget https://github.com/ledgetech/lua-resty-http/archive/v0.13.zip
14+
unzip lua-resty-http-0.13.zip
15+
yes|cp -fr lua-resty-http-0.13/lib/resty/* resty/
16+
rm -fr lua-resty-http-0.13.zip lua-resty-http-0.13.zip
17+
wget https://github.com/doujiang24/lua-resty-kafka/archive/v0.06.zip
18+
unzip lua-resty-kafka-0.06.zip
19+
yes|cp -fr lua-resty-kafka-0.06/lib/resty/* resty
20+
rm -fr lua-resty-kafka-0.06.zip lua-resty-kafka-0.06
21+
1122
test:
1223
@echo "to be continued..."
1324

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ Find more about Orange on its [website](http://orange.sumory.com/docs). There is
8282
- [@spacewander](https://github.com/spacewander)
8383
- [@noname007](https://github.com/noname007)
8484
- [@itchenyi](https://github.com/itchenyi)
85+
- [@Near-Zhang](https://github.com/Near-Zhang)
86+
- [@khlipeng](https://github.com/khlipeng)
87+
- [@wujunze](https://github.com/wujunze)
8588

8689
### See also
8790

README_zh.md

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<a href="./README_zh.md" style="font-size:13px">中文</a> | <a href="./README.md" style="font-size:13px">English</a> | <a href="http://orange.sumory.com" style="font-size:13px">Website</a>
77

8-
Orange是一个基于OpenResty的API网关。除Nginx的基本功能外,它还可用于API监控、访问控制(鉴权、WAF)、流量筛选、访问限速、AB测试、动态分流等。它有以下特性:
8+
Orange是一个基于OpenResty的API网关。除Nginx的基本功能外,它还可用于API监控、访问控制(鉴权、WAF)、流量筛选、访问限速、AB测试、静/动态分流等。它有以下特性:
99

1010
- 提供了一套默认的Dashboard用于动态管理各种功能和配置
1111
- 提供了API接口用于实现第三方服务(如个性化运维需求、第三方Dashboard等)
@@ -16,23 +16,27 @@ Orange是一个基于OpenResty的API网关。除Nginx的基本功能外,它还
1616

1717
#### 安装依赖
1818

19-
- OpenResty: 版本应在1.9.7.3+
20-
- Orange的监控插件需要统计http的某些状态数据,所以需要编译OpenResty时添加`--with-http_stub_status_module`
21-
- 由于使用了*_block指令,所以OpenResty的版本最好在1.9.7.3以上.
22-
- [lor](https://github.com/sumory/lor)框架
19+
- OpenResty: 版本应在1.11.2+
20+
- Orange的监控插件需要统计HTTP的状态数据,所以编译OpenResty时需要添加`--with-http_stub_status_module`
21+
- [Lor](https://github.com/sumory/lor)框架
2322
- 若使用的Orange版本低于v0.6.2则应安装lor v0.2.*版本
2423
- 若使用的Orange版本高于或等于v0.6.2则应安装lor v0.3.0+版本
2524
- MySQL
26-
- 配置存储和集群扩展需要MySQL支持。从0.2.0版本开始,Orange去除了本地文件存储的方式,目前仅提供MySQL存储支持.
25+
- 配置存储和集群扩展需要MySQL支持
26+
- 使用luarocks安装一些第三方库
27+
- luarocks install https://luarocks.org/manifests/steved/penlight-1.5.4-1.rockspec
28+
- luarocks install https://luarocks.org/manifests/kong/lua-resty-dns-client-2.2.0-1.rockspec
29+
- luarocks install https://luarocks.org/lua-resty-http-0.13-0.src.rock
30+
- luarocks install https://luarocks.org/manifests/luarocks/luasocket-3.0rc1-2.rockspec
2731

2832
#### 数据表导入MySQL
2933

3034
- 在MySQL中创建数据库,名为orange
31-
- 将与当前代码版本配套的SQL脚本(如install/orange-v0.6.4.sql)导入到orange库中
35+
- 将与当前代码版本配套的SQL脚本(如install/orange-v0.7.0.sql)导入到orange库中
3236

3337
#### 修改配置文件
3438

35-
Orange有**两个**配置文件,一个是`conf/orange.conf`,用于配置插件、存储方式和内部集成的默认Dashboard,另一个是`conf/nginx.conf`用于配置Nginx(OpenResty).
39+
Orange有**两个**配置文件,一个是`conf/orange.conf`,用于配置插件、存储方式和内部集成的默认Dashboard,另一个是`conf/nginx.conf`用于配置Nginx.
3640

3741
orange.conf的配置如下,请按需修改:
3842

@@ -41,16 +45,7 @@ orange.conf的配置如下,请按需修改:
4145
"plugins": [ //可用的插件列表,若不需要可从中删除,系统将自动加载这些插件的开放API并在7777端口暴露
4246
"stat",
4347
"monitor",
44-
"redirect",
45-
"rewrite",
46-
"rate_limiting",
47-
"property_rate_limiting",
48-
"basic_auth",
49-
"key_auth",
50-
"signature_auth",
51-
"waf",
52-
"divide",
53-
"kvstore"
48+
".."
5449
],
5550

5651
"store": "mysql",//目前仅支持mysql存储
@@ -67,8 +62,7 @@ orange.conf的配置如下,请按需修改:
6762
"pool_config": {
6863
"max_idle_timeout": 10000,
6964
"pool_size": 3
70-
},
71-
"desc": "mysql configuration"
65+
}
7266
},
7367

7468
"dashboard": {//默认的Dashboard配置.
@@ -101,9 +95,14 @@ conf/nginx.conf里是一些nginx相关配置,请自行检查并按照实际需
10195

10296
#### 安装
10397

104-
如果使用的是v0.5.0以前的版本则无需安装, 只要将Orange下载下来放到合适的位置即可。
98+
1) 使用方式一
99+
100+
无需安装, 只要将Orange下载下来, 根据需要修改一下`orange.conf``nginx.conf`配置,然后使用`start.sh`脚本即可启动。
101+
默认提供的nginx.conf和start.sh都是最简单的配置,只是给用户一个默认的配置参考,用户应该根据实际生产要求自行添加或更改其中的配置以满足需要。
105102

106-
如果使用的是v0.5.0及以上的版本, 可以通过`make install`将Orange安装到系统中。 执行此命令后, 以下两部分将被安装:
103+
2) 使用方式二
104+
105+
可以通过`make install`将Orange安装到系统中(默认安装到/usr/local/orange)。 执行此命令后, 以下两部分将被安装:
107106

108107
```
109108
/usr/local/orange #orange运行时需要的文件
@@ -112,9 +111,9 @@ conf/nginx.conf里是一些nginx相关配置,请自行检查并按照实际需
112111

113112
#### 启动
114113

115-
在v0.5.0以下版本中, 一个简单的shell脚本用来启动/重启orange, 执行`sh start.sh`即可。可以按需要仿照start.sh编写运维脚本, 本质上就是启动/关闭Nginx。
114+
若采用方式一安装,则执行`sh start.sh`即可启动。可以按需要仿照start.sh编写运维脚本, 本质上就是启动/关闭Nginx。
116115

117-
除此之外, 从v0.5.0开始, 如果执行过`make install`将Orange安装到系统后, 还可以通过`orange`命令来管理, 执行`orange help`查看有哪些命令可以使用:
116+
若采用方式二`make install`安装,则可以通过命令行工具`orange`来管理, 执行`orange help`查看有哪些命令可以使用:
118117

119118
```
120119
Usage: orange COMMAND [OPTIONS]
@@ -130,13 +129,11 @@ version Show the version of Orange
130129
help Show help tips
131130
```
132131

133-
134132
Orange启动成功后, dashboard和API server也随之启动:
135133

136134
- 内置的Dashboard可通过`http://localhost:9999`访问
137135
- API Server默认在`7777`端口监听,如不需要API Server可删除nginx.conf里对应的配置
138136

139-
140137
### 文档
141138

142139
- 项目文档: [官网](http://orange.sumory.com/docs)
@@ -154,11 +151,16 @@ Orange启动成功后, dashboard和API server也随之启动:
154151
- [@spacewander](https://github.com/spacewander)
155152
- [@noname007](https://github.com/noname007)
156153
- [@itchenyi](https://github.com/itchenyi)
154+
- [@Near-Zhang](https://github.com/Near-Zhang)
155+
- [@khlipeng](https://github.com/khlipeng)
156+
- [@wujunze](https://github.com/wujunze)
157+
158+
157159

158160
### See also
159161

160162
Orange的插件设计参考自[Kong](https://github.com/Mashape/kong).
161163

162164
### License
163165

164-
[MIT](./LICENSE)
166+
[MIT](./LICENSE) License

bin/cmds/register.lua

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
local logger = require("bin.utils.logger")
2+
local http = require("resty.http")
3+
local io = require("orange.utils.io")
4+
local json = require("orange.utils.json")
5+
6+
local _M = {}
7+
8+
9+
_M.help = [[
10+
Usage: orange register
11+
12+
Register current node to cluster
13+
14+
Examples:
15+
orange register
16+
]]
17+
18+
19+
local function base64_encode(source_str)
20+
local b64chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
21+
local s64 = ''
22+
local str = source_str
23+
24+
while #str > 0 do
25+
local bytes_num = 0
26+
local buf = 0
27+
28+
for byte_cnt = 1, 3 do
29+
buf = (buf * 256)
30+
if #str > 0 then
31+
buf = buf + string.byte(str, 1, 1)
32+
str = string.sub(str, 2)
33+
bytes_num = bytes_num + 1
34+
end
35+
end
36+
37+
for group_cnt = 1, (bytes_num + 1) do
38+
local b64char = math.fmod(math.floor(buf / 262144), 64) + 1
39+
s64 = s64 .. string.sub(b64chars, b64char, b64char)
40+
buf = buf * 64
41+
end
42+
43+
for fill_cnt = 1, (3 - bytes_num) do
44+
s64 = s64 .. '='
45+
end
46+
end
47+
48+
return s64
49+
end
50+
51+
function _M.execute(origin_args)
52+
53+
local err
54+
55+
-- format and parse args
56+
local args = {
57+
orange_conf = origin_args.orange_conf,
58+
prefix = origin_args.prefix
59+
}
60+
for i, v in pairs(origin_args) do
61+
if i == "o" and not args.orange_conf then args.orange_conf = v end
62+
if i == "p" and not args.prefix then args.prefix = v end
63+
end
64+
65+
-- use default args if not exist
66+
-- if not args.prefix then args.prefix = command_util.pwd() end
67+
if not args.prefix then args.prefix = "/usr/local/orange" end
68+
if not args.orange_conf then args.orange_conf = args.prefix .. "/conf/orange.conf" end
69+
70+
if args then
71+
logger:info("args:")
72+
for i, v in pairs(args) do
73+
logger:info("\t%s:%s", i, v)
74+
end
75+
logger:info("args end.")
76+
end
77+
78+
xpcall(function()
79+
80+
-- 读取 orange 配置文件
81+
local orange_conf_text = io.read_file(args.orange_conf)
82+
local orange_conf = json.decode(orange_conf_text)
83+
84+
if #orange_conf.api.credentials[1] ~= 0 then
85+
logger:error("not configure api username and password")
86+
return
87+
end
88+
89+
local credential = orange_conf.api.credentials[1]
90+
91+
local httpc = http.new()
92+
93+
-- 设置超时时间 200 ms
94+
httpc:set_timeout(200)
95+
96+
local url = "http://127.0.0.1:7777"
97+
local authorization = base64_encode(string.format("%s:%s", credential.username, credential.password))
98+
local path = '/node/register'
99+
100+
local resp, err = httpc:request_uri(url, {
101+
method = "POST",
102+
path = path,
103+
headers = {
104+
["Authorization"] = authorization
105+
}
106+
})
107+
108+
httpc:close()
109+
110+
if not err then
111+
if resp.status == 200 then
112+
logger:success("Orange register to cluster.")
113+
else
114+
logger:error(resp.body)
115+
end
116+
else
117+
logger:error(err)
118+
end
119+
120+
end, function(e)
121+
logger:error("Could not register Orange, error: %s", e)
122+
err = e
123+
end)
124+
125+
if err then
126+
error(err)
127+
end
128+
end
129+
130+
131+
return _M

bin/main.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ local cmds = {
99
reload = "Reload the config of Orange",
1010
store = "Init/Update/Backup Orange store",
1111
version = "Show the version of Orange",
12+
register = "Register the node",
1213
help = "Show help tips"
1314
}
1415

conf/orange.conf.example

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
"property_rate_limiting",
1111
"basic_auth",
1212
"key_auth",
13+
"hmac_auth",
1314
"signature_auth",
1415
"waf",
1516
"divide",
16-
"kvstore"
17+
"kvstore",
18+
"balancer"
1719
],
1820
"store": "mysql",
1921
"store_mysql": {

0 commit comments

Comments
 (0)