---------2017-08-25 重新编辑格式---------
Orange是一个简单易用的开源API Gateway,它集成了Openresty、Nginx和lor,使用Lua语言开发了nginx插件,可以实现后端服务API路由设置以及反向代理、负载均衡,此外还提供一些API监控功能,但是API鉴权尚不完善,不支持精细的权限配置。配合Docker使用,可以组成轻量级低负载的微服务架构,适合初创公司使用。通过API网关实现对外统一的接口契约格式,使得后端的开发语言对前端完全透明,实现多种后端语言共同开发,例如使用PHP支持一些需要快速上线的业务,而使用Java支持一些持久稳定的业务等,此外在集成其它采购的软件,如OA、CMS等系统时,也可以起到隔离差异和统一访问的作用。
[root@local ~]# yum install openssl-devel
[root@local ~]# yum install pcre-devel
[root@local ~]# wget https://openresty.org/download/openresty-1.11.2.3.tar.gz
[root@local ~]# ./configure -j2 --with-http_stub_status_module
[root@local ~]# gmake
[root@local ~]# gmake install
或者
[root@local ~]# make
[root@local ~]# make install
默认安装目录为
/usr/local/openresty
.bash_profile配置环境变量:
PATH=$PATH:$HOME/bin:/usr/local/openresty/bin:/usr/local/openresty/nginx/sbin
*注:[root@local ~]# orange help
nginx:invalid option: "/usr/local/bin/orange"
[root@local ~]# git clone https://github.com/sumory/lor.git
[root@local ~]# cd lor
[root@local ~]# make install
默认安装目录为:/usr/local/lor
[root@local ~]# git clone https://github.com/sumory/orange.git
[root@local ~]# cd orange
[root@local ~]# make install
由于Orange 是免安装使用,也可以使用start.sh直接启动,因此,实际安装的只是命令行工具,检查命令行工具如下。
[root@beijing5 openresty]# orange help
Orangev0.6.4, OpenResty/Nginx API Gateway.
Usage:orange COMMAND [OPTIONS]
Thecommands are:
stop Stop current Orange
version Show the version ofOrange
restart Restart Orange
reload Reload the config of Orange
store Init/Update/Backup Orange store
help Show help tips
start Start the Orange Gateway
默认安装目录为:/usr/local/orange
主要修改数据库连接相关的配置,并设置dashboard密码登录,初始密码admin/orange_admin。
{
"plugins":[
"stat",
"monitor",
"redirect",
"rewrite",
"rate_limiting",
"property_rate_limiting",
"basic_auth",
"key_auth",
"signature_auth",
"waf",
"divide",
"kvstore"
],
"store":"mysql",
"store_mysql":{
"timeout":5000,
"connect_config":{
"host": "192.168.1.107",
"port": 3306,
"database": "orange",
"user": "orange_dba",
"password": "orange_passwd",
"max_packet_size": 1048576
},
"pool_config":{
"max_idle_timeout": 10000,
"pool_size": 3
},
"desc":"mysql configuration"
},
"dashboard":{
"auth":true,
"session_secret":"y0ji4pdj61aaf3f11c2e65cd2263d3e7e5",
"whitelist":[
"^/auth/login$",
"^/error/$"
]
},
"api":{
"auth_enable":true,
"credentials":[
{
"username":"api_username",
"password":"api_password"
}
]
}
}
error_log./logs/error.log warn;
否则会输出大量的日志记录,此外建议设置crontab定时任务对日志按天切分。
include/usr/local/orange/conf/conf.d/*.conf;