美高梅开户-美高梅官方网站开户

您的位置:美高梅开户 > 服务器运维 > Linux安装配置Varnish,一款高品质的开源HTTP加快器

Linux安装配置Varnish,一款高品质的开源HTTP加快器

发布时间:2019-08-16 03:23编辑:服务器运维浏览(67)

    Linux varnish(一款高质量的开源HTTP加快器),varnish加快器

    Linux安装配置Varnish Web加快器

    Varnish是一款高质量的开源HTTP加快器,它能够来做纯粹的代理服务器,负载均衡,但varnish最关键的功能是缓存加速,也是它最突出的地方。上面介绍在Linux下什么样设置和采取。

    一、环境

    # cat /etc/issue

    CentOS release 6.3 (Final)

    Kernel r on an m

    # getconf LONG_BIT

    64

    二、下载

    cd /usr/local/src/

    wget

    tar xzvf varnish-3.0.1.tar.gz

    三、安装

    cd varnish-3.0.1

    yum install -y automake autoconf libtool ncurses-devel libxslt groff pcre-devel pkgconfig

    ./configure --prefix=/usr/local/varnish

    make

    make install

    四、校验安装

    cd /usr/local/varnish/sbin/

    ./varnishd -V

    五、配置

    # cd /usr/local/varnish/etc/varnish/

    # cp default.vcl default.vcl.bak

    # > default.vcl

    # cat default.vcl

    # This is a basic VCL configuration file for varnish.  See the vcl(7)

    # man page for details on VCL syntax and semantics.

    #

    # Default backend definition.  Set this to point to your content

    # server.

    #

     backend default {

        .host = "115.28.225.216";

        .port = "80";

        ###上边三行为新加配

        .connect_timeout = 1s;

        .first_byte_timeout = 5s;

        .between_bytes_timeout = 2s;

     }

    #

    # Below is a commented-out copy of the default VCL logic.  If you

    # redefine any of these subroutines, the built-in logic will be

    # appended to your code.

     sub vcl_recv {

        if (req.restarts == 0) {

            if (req.http.x-forwarded-for) {

                set req.http.X-Forwarded-For =

                    req.http.X-Forwarded-For ", " client.ip;

            } else {

                set req.http.X-Forwarded-For = client.ip;

            }

        }

        if (req.request != "GET" &&

          req.request != "HEAD" &&

          req.request != "PUT" &&

          req.request != "POST" &&

          req.request != "TRACE" &&

          req.request != "OPTIONS" &&

          req.request != "DELETE") {

            /* Non-RFC2616 or CONNECT which is weird. */

            return (pipe);

        }

        if (req.request != "GET" && req.request != "HEAD") {

            /* We only deal with GET and HEAD by default */

            return (pass);

        }

        if (req.http.Authorization || req.http.Cookie) {

            /* Not cacheable by default */

            return (pass);

        }

        return (lookup);

     }

    #

     sub vcl_pipe {

    #    # Note that only the first request to the backend will have

    #    # X-Forwarded-For set.  If you use X-Forwarded-For and want to

    #    # have it set for all requests, make sure to have:

    #    # set bereq.http.connection = "close";

    #    # here.  It is not set by default as it might break some broken web

    #    # applications, like IIS with NTLM authentication.

        return (pipe);

     }

    #

     sub vcl_pass {

        return (pass);

     }

    #

     sub vcl_hash {

        hash_data(req.url);

        if (req.http.host) {

            hash_data(req.http.host);

        } else {

            hash_data(server.ip);

        }

        return (hash);

     }

    #

     sub vcl_hit {

        return (deliver);

     }

    #

     sub vcl_miss {

        return (fetch);

     }

    #

     sub vcl_fetch {

        if (beresp.ttl <= 0s ||

            beresp.http.Set-Cookie ||

            beresp.http.Vary == "*") {

                    /*

                    * Mark as "Hit-For-Pass" for the next 2 minutes

                    */

                    set beresp.ttl = 120 s;

                    return (hit_for_pass);

        }

        return (deliver);

     }

    #

     sub vcl_deliver {

        return (deliver);

     }

    #

    #美高梅官方网站开户 , sub vcl_error {

    #    set obj.http.Content-Type = "text/html; charset=utf-8";

    #    set obj.http.Retry-After = "5";

    #    synthetic {"

    # <?xml version="1.0" encoding="utf-8"?>

    # <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

    #  ";

    # <html>

    #  <head>

    #    <title>"} obj.status " " obj.response {"</title>

    #  </head>

    #  <body>

    #    <h1>Error "} obj.status " " obj.response {"</h1>

    #    <p>"} obj.response {"</p>

    #    <h3>Guru Meditation:</h3>

    #    <p>XID: "} req.xid {"</p>

    #    <hr>

    #    <p>Varnish cache server</p>

    #  </body>

    # </html>

    # "};

    #    return (deliver);

    # }

    #

     sub vcl_init {

            return (ok);

     }

    #

     sub vcl_fini {

            return (ok);

     }

    六、运行与关闭varnish

    /usr/local/varnish/sbin/varnishd -f /usr/local/varnish/etc/varnish/default.vcl -s malloc,1024m -T 127.0.0.1:200 -a 0.0.0.0:80

    早先参数介绍:
    -f /usr/local/etc/varnish/default.vcl
    以此 –f 选项钦点varnishd使用哪个配置文件。
    -s malloc,1G
    以此 –s 选项用来规定varnish使用的储存类型和积累体量,笔者使用的是malloc类型(malloc是三个C函数,用于分配内部存款和储蓄器空间), 1G 定义多少内部存款和储蓄器被malloced,1G = 1gigabyte。
    -T 127.0.0.1:2000
    Varnish有三个基于文本的管住接口,运营它的话能够在不安歇varnish的气象下来管理varnish。您能够钦赐管理软件监听哪个接口。当然你不能够让举世的人都能访谈您的varnish管理接口,因为他们能够很轻易的经过拜谒varnish管理接口来获得你的root访谈权限。小编推荐只让它监听本机端口。要是您的种类里有您不完全依赖的用户,您能够经过防火墙法规来界定她拜望varnish的军管端口。
    -a 0.0.0.0:8080
    这一句的意趣是制定varnish监听全数IP发给8080端口的http必要,要是在生养条件下,您应该让varnish监听80,那也是默许的。

    pkill varnishd    // 关闭Varnish

    /usr/local/varnish/bin/varnishncsa -w /var/log/varnish.log &    //运维varnishncsa用来将Varnish访问日志写入日志文件;


    Varnish Cache 的架构笔记

    CentOS 5.8下Varnish-2.1.5的安装配置

    RedHat脚本改用CentOS源更新安装Nginx、PHP 5.3、Varnish

    使用Varnish创设Cache服务器笔记

    缓存服务Varnish安装配备

    Varnish 编写翻译安装所需打算

    Linux下Varnish缓存的配置优化

    Varnish基础概念详解


    Varnish 的详实介绍:请点这里
    Varnish 的下载地址:请点这里

    正文永世更新链接地址:

    Web加快器 Varnish是一款高品质的开源HTTP加快器,它可以来做纯粹的代理服务器,负载均衡,但varnish最保养的职能是缓存...

    Varnish

    Varnish是一款高质量的开源HTTP加快器,挪威最大的在线民报告纸 韦尔德ns Gang 使用3台Varnish代替了原本的12台Squid,品质比以前更加好

    常用的命令

    varnishadm ban.url .*$         #清除所有
    varnishadm ban.url /index.html  #清除 index.html 页面缓存
    varnishadm ban.url /admin/$    #清除 admin 目录缓存
    

    部署varnish

    本文由美高梅开户发布于服务器运维,转载请注明出处:Linux安装配置Varnish,一款高品质的开源HTTP加快器

    关键词: 美高梅开户

上一篇:什么用linux远程登入windowsComputer

下一篇:没有了