>

风流浪漫款高质量的开源HTTP加快器,Linux安装配

- 编辑:金沙国际平台登录 -

风流浪漫款高质量的开源HTTP加快器,Linux安装配

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

1.server1下载安装 yum install *
varnish-libs-3.0.5-1.el6.x86_64.rpm 
varnish-3.0.5-1.el6.x86_64.rpm
2.server1(安插varnish的主机上)
vim /etc/sysconfig/varnish
/etc/varnish/default.vcl
/etc/init.d/varnish start
3.server2

搭建后台的httpd服务

vim /var/www/html/index.html

本文由金沙国际平台登录发布,转载请注明来源:风流浪漫款高质量的开源HTTP加快器,Linux安装配