zoukankan      html  css  js  c++  java
  • 使用skipper 扩展fabio 的路由&&http proxy 功能

    skipper 具有强大的http 路由功能,fabio 是一个方便的基于consul 的负载均衡软件,
    我们可以方便的使用skipper 路由功能进行fabio的扩展,使用registrator 进行服务注册

    环境准备

    • docker-compose
    version: "3"
    services:
      fabio:
        image: fabiolb/fabio
        ports:
        - "9999:9999"
        - "9998:9998"
        volumes:
        - "./fabio.properties:/etc/fabio/fabio.properties"
      consul:
        image: consul
        command: agent -config-file=/usr/local/etc/consul/server_agent.json
        volumes:
        - "./consul.json://usr/local/etc/consul/server_agent.json"
        ports:
        - "8500:8500"
      web:
        image: nginx
        ports:
        - "80:80"
        environment:
        - SERVICE_TAGS=urlprefix-/
        - SERVICE_80_CHECK_HTTP=/
        - SERVICE_80_NAME=web-app
        - SERVICE_CHECK_INTERVAL=10s
        - SERVICE_CHECK_TIMEOUT=5s
      ip:
        build: 
          context: ./
          dockerfile: Dockerfile-ip
        image: dalongrong/openresty-ip
      skipper2:
        image: dalongrong/skipper
        environment:
        - SERVICE_TAGS=urlprefix-/ip
        - SERVICE_9090_NAME=skipper
        - SERVICE_9090_CHECK_HTTP=/
        - SERVICE_CHECK_INTERVAL=10s
        - SERVICE_CHECK_TIMEOUT=5s
        ports:
        - "9090:9090"
        volumes:
        - "./router.eskip:/router.eskip"
        command: skipper -enable-ratelimits -enable-prometheus-metrics -routes-file /router.eskip
      registor:
        image: gliderlabs/registrator:latest
        command: consul://consul:8500
        volumes:
        - "/var/run/docker.sock:/tmp/docker.sock"
    • 说明
      对于skipper 的扩展使用的是nginx 重写,同时注册skipper到fabio中
      ip 服务的dockerfile && nginx 配置
      Dockerfile-ip
    FROM openresty/openresty:alpine
    COPY nginx.conf usr/local/openresty/nginx/conf/
    EXPOSE 80

    nginx.conf

    worker_processes 1;
    events {
        worker_connections 1024;
    }
    http {
        include mime.types;
        default_type application/octet-stream;
        sendfile on;
        keepalive_timeout 65;
        gzip on;
        real_ip_header X-Forwarded-For;
        real_ip_recursive on;
        server {
            listen 80;
            server_name localhost;
            charset utf-8;
            location / {
                rewrite ^/ip(.*) $1 break;
                proxy_ignore_client_abort on;
                client_body_buffer_size 10M;
                client_max_body_size 10G;
                proxy_buffers 1024 4k;
                proxy_read_timeout 300;
                proxy_pass http://localhost:88;
             }
            location /alert {
             default_type text/html;
             content_by_lua_block{
                 ngx.say([[<script>alert("error")</script>]])
             }
            }
    
            location /ip2 {
                default_type text/html;
                content_by_lua_block{
                    ngx.say(ngx.var.remote_addr)
                }
            }
            error_page 500 502 503 504 /50x.html;
            location = /50x.html {
                root html;
            }
        }
        server {
            listen 88;
            server_name localhost;
            charset utf-8;
            location / {
                  index index.html index.htm;
             }
            location /alert {
             default_type text/html;
             content_by_lua_block{
                 ngx.say([[<script>alert("error")</script>]])
             }
            }
    
            location /ip2 {
                default_type text/html;
                content_by_lua_block{
                    ngx.say(ngx.var.remote_addr.."from upstream")
                }
            }
            error_page 500 502 503 504 /50x.html;
            location = /50x.html {
                root html;
            }
        }
    }
    • fabio 配置文件
      fabio.properties
    registry.consul.addr = consul:8500
    • skipper router 配置
    hello: Path("/ip/*")->compress("text/html")-> corsOrigin()->setResponseHeader("TOKEN","dalongdemo")->responseCookie("test-session", "abc", 31536000)->
     setRequestHeader("TOKEN","dalongdemo")-> "http://ip";
    root: Path("/") -> status(200) -> <shunt>;

    启动&&测试

    • 启动
    docker-compose up -d

    参考资料

    https://github.com/rongfengliang/fabio-with-skipper
    https://gliderlabs.github.io/registrator/latest/
    https://github.com/fabiolb/fabio
    https://github.com/zalando/skipper

  • 相关阅读:
    libpcap编程实例
    libnet发包例子(tcp udp arp广播)
    C#中一个窗口是一个类呢,还是一个窗口类的实例呢?(转)
    创建一个实例&创建一个线程。。
    (转)C#中的 Interfaces (For 初学者们)
    C#中接口声明属性,但是提示“接口”中不能有属性。
    十万个为什么:现在还没发现“虚函数virtual”和多态性的优点,估计是因为我还没有编程序吧。
    C#中的多态性
    Windows 程序支持 Unicode
    Python 中的函数与类的方法
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/10087754.html
Copyright © 2011-2022 走看看