内容简介:依赖:lua-resty-http基于Nginx&Lua 和Netflix Eureka的微服务网关。重新架构了内部组件,采用插件模式。
依赖:lua-resty-http
基于Nginx&Lua 和Netflix Eureka的微服务网关。
重新架构了内部组件,采用插件模式。
- 服务发现
- Eureka Discovery
- 抽象discovery,用来支持多种服务发现?规划中…
- 动态路由
- 负载均衡
- 加权轮询
- 基于响应时间的动态权重轮询?开发中…
- 简单监控
- 隔离降级
- 限流
- metrics
- 认证安全?规划中。。。
- 监控页面?开发中…
架构图:
使用方法
基于Nginx和Lua module。需要 安装Nginx Lua环境 或者直接下载 openresty 编译安装。
安装和配置ngx-lua-zuul
下载代码到/path/to/nginx/lua/lib/
git clone http://github.com/tietang/ngx-lua-zuul –depth=1
例子Eureka 服务
如果没有Eureka环境,也可以编译安装本例子中的EurekaDemo服务,参考 编译和运行eureka-demo服务 中的相关内容。
部署dicovery例子服务:
下载代码后:
cd /path/to/ngx_lua-zuul/demo/java mvn clean install
将下载的代码中的 lua 文件夹放到部署目录 /path/to/nginx ,修改 /path/to/nginx/lua/ngx_conf/lua.ngx_conf 文件中的 lua_package_path 为你的真实路径:
lua_package_path "/path/to/nginx/lua/lib/?.lua;;";
修改 /path/to/nginx/conf/nginx.conf 文件
http 节点中添加
include "/path/to/lua/ngx_conf/ngx_inlude_http.conf";
server节点中添加
include "/path/to/nginx/lua/ngx_conf/ngx_inlude_server.conf";
参考配置
#user nobody;
worker_processes 2;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
include "/Users/tietang/nginx/nginx/lua/ngx_conf/ngx_inlude_http.conf";
server {
include "/Users/tietang/nginx/nginx/lua/ngx_conf/ngx_inlude_server.conf";
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
location = / {
set $dir $document_root;
root $dir/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
运行测试
启动所有的demo服务:discovery,api,zuul;
启动nginx;
打开浏览器: http://127.0.0.1:8000/api/test/0/0
其测试api参考 编译和运行eureka-demo服务 中的相关内容。
以上所述就是小编给大家介绍的《基于Nginx&Lua 和Netflix Eureka的微服务网关》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
AJAX企业级开发
Davec Johnson、Alexeic White、Andrec Charland / 张祖良、荣浩、高冰 / 人民邮电出版社 / 2008 / 49.00元
本书首先解释了AJAX 为什么在大规模的开发中能有如此广阔的应用前景,接着系统地介绍了当前重要的AJAX 技术和组件。你将看到把数据表、Web 窗体、图表、搜索和过滤连接在一起用于构建AJAX应用程序的框架开发的整个过程;在此基础上,本书给出了已经过证实的AJAX 架构模式,以及来源于实际的.NET 和Java AJAX 应用程序的案例研究。一起来看看 《AJAX企业级开发》 这本书的介绍吧!
RGB转16进制工具
RGB HEX 互转工具
XML、JSON 在线转换
在线XML、JSON转换工具