基于Nginx&Lua 和Netflix Eureka的微服务网关

栏目: Java · 发布时间: 7年前

内容简介:依赖:lua-resty-http基于Nginx&Lua 和Netflix Eureka的微服务网关。重新架构了内部组件,采用插件模式。

依赖:lua-resty-http

基于Nginx&Lua 和Netflix Eureka的微服务网关。

重新架构了内部组件,采用插件模式。

  • 服务发现
    • Eureka Discovery
    • 抽象discovery,用来支持多种服务发现?规划中…
  • 动态路由
  • 负载均衡
    • 加权轮询
    • 基于响应时间的动态权重轮询?开发中…
  • 简单监控
  • 隔离降级
  • 限流
  • metrics
  • 认证安全?规划中。。。
  • 监控页面?开发中…

架构图:

基于Nginx&Lua 和Netflix Eureka的微服务网关

使用方法

基于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的微服务网关》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

R Cookbook

R Cookbook

Paul Teetor / O'Reilly Media / 2011-3-22 / USD 39.99

With more than 200 practical recipes, this book helps you perform data analysis with R quickly and efficiently. The R language provides everything you need to do statistical work, but its structure ca......一起来看看 《R Cookbook》 这本书的介绍吧!

html转js在线工具
html转js在线工具

html转js在线工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具