美文网首页
Varnish系列之四:负载均衡的架构与实现

Varnish系列之四:负载均衡的架构与实现

作者: 平平淡淡的猪 | 来源:发表于2018-04-03 16:32 被阅读0次

    vcl中定义调度器说明:

        1. 轮询方式

    backend appServer1 {

        .host = "172.16.100.52";

        .port = "80";

        .probe = {

            .url = "/test.html";

            .expected_response = 200;

        }

    }

    backend appServer2 {

        .host = "172.16.100.53";

        .port = "80";

    }

    import directors;

    sub vcl_init {

        new rr = directors.round_robin();

        rr.add_backend(appServer1);

        rr.add_backend(appServer2);

    }

    sub vcl_recv {

        set req.backend_hint = rr.backend();

        ......

    }

        2. hash方式

    backend appServer1 {

        .host = "172.16.100.52";

        .port = "80";

    }

    backend appServer2 {

        .host = "172.16.100.53";

        .port = "80";

    }

    import directors;

    sub vcl_init {

        new hash = directors.hash();

        hash.add_backend(appServer1, 1.0);

        hash.add_backend(appServer2, 1.0);

    }

    sub vcl_recv {

        set req.backend_hint = hash.backend(req.http.X-Forwarded-For);

        ......

    }

    说明:当varnish前端用nginx做反代时,在nginx中需要做如下配置:

                proxy_pass http://varnish_server_ip:port;

                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    相关文章

      网友评论

          本文标题:Varnish系列之四:负载均衡的架构与实现

          本文链接:https://www.haomeiwen.com/subject/owkchftx.html