内容简介:依赖: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的微服务网关》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Collective Intelligence实战
阿拉克 / 2010-9 / 58.00元
《Collective Intelligence实战》内容简介:在互联网上,利用用户的集体智慧是成功的关键。集体智慧是一种新兴的编程技术,可让您从人们访问web和与web交互的过程中找到有价值的模式、发现这些访问者之间的关系和确定他们的个人偏好及习惯等。《collective Intelligence实战》首先介绍了集体智慧的原则和构建更具交互性网站的思想,然后通过示例开发了一个直接可用的基于Ja......一起来看看 《Collective Intelligence实战》 这本书的介绍吧!