<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    java技術研究

    統(tǒng)計

    留言簿(3)

    閱讀排行榜

    評論排行榜

    Varnish安裝部署文檔

    網(wǎng)上的文檔寫的有些問題,只可以參考,可以按住我下邊的總結的,安裝外圍包,然后再編譯安裝即可

     

    wget -c http://repo.varnish-cache.org/source/varnish-3.0.2.tar.gz

    yum instll -y automake
    yum instll -y autoconf
    yum instll -y libtool
    yum instll -y ncurses-devel
    yum instll -y libxslt
    yum instll -y groff
    yum instll -y pcre-devel
    yum instll -y pkgconfig
    yum instll -y automake
    yum instll -y  automake
    yum install -y autoconf
    yum install -y libtool
    yum install -y ncurses-devel
    yum install -y libxslt
    yum install -y groff
    yum install -y pcre-devel
    yum install -y pkgconfig
    groupadd www
    useradd www -g www -s /sbin/nologin

    yum -y install patch make gcc gcc-c++ gcc-g77 flex bison file
    yum -y install libtool libtool-libs autoconf kernel-devel
    yum -y install libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel
    yum -y install freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel
    yum -y install glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel
    yum -y install ncurses ncurses-devel curl curl-devel e2fsprogs
    yum -y install e2fsprogs-devel krb5 krb5-devel libidn libidn-devel
    yum -y install openssl openssl-devel vim-minimal nano sendmail
    yum -y install fonts-chinese gettext gettext-devel
    yum -y install ncurses-devel
    yum -y install gmp-devel pspell-devel
    yum -y install unzip

    cd /varnish

    ./configure --prefix=/opt/varnish

    make ;make install

    啟動:

    /opt/varnish/sbin/varnishd -f /opt/varnish/etc/varnish/killwin.vcl -a 42.121.12.4:80 -s malloc,256m  -T 127.0.0.1:2000 -p http_resp_hdr_len=8192
    下邊的網(wǎng)絡轉載的

     

     

     

     

    簡述:Varnish是一款高性能的開源HTTP加速器,挪威最大的在線報紙 Verdens Gang 使用3臺Varnish代替了原來的12臺Squid,性能比以前更好。

    系統(tǒng)環(huán)境:
    CentOS release 5.5 (Final) 64-bit

    所需軟件:
    varnish-2.1.4.tar.gz

    Varnish官方網(wǎng)站:

    http://www.varnish-cache.org/

    安裝前準備:

    創(chuàng)建www用戶和組,以及Varnish緩存文件存放目錄(/elain/data/vcache):
    /usr/sbin/groupadd www -g 600
    /usr/sbin/useradd -u 600 -g www www
    mkdir -p /elain/data/vcache
    chmod +w /elain/data/vcache
    chown -R www:www /elain/data/vcache

    創(chuàng)建Varnish日志目錄(/elain/logs/varnish):
    mkdir -p /elain/logs/varnish
    chmod +w /elain/logs/varnish
    chown -R www:www /elain/logs/varnish

    安裝:
    wget http://cdnetworks-kr-1.dl.sourceforge.net/project/pcre/pcre/8.12/pcre-8.12.tar.gz
    tar zxvf pcre-8.12.tar.gz
    cd pcre-8.12/
    ./configure --prefix=/elain/apps/pcre
    make && make install
    cd ../

    wget http://repo.varnish-cache.org/source/varnish-2.1.5.tar.gz
    tar zxvf varnish-2.1.5.tar.gz
    cd varnish-2.1.5
    export PKG_CONFIG_PATH=/elain/apps/pcre/lib/pkgconfig
    ./configure -prefix=/elain/apps/varnish
    make
    make install
    cd ..

    配置:
    默認配置文件樣板:
    /elain/apps/varnish/etc/varnish/default.vcl

    cd /elain/apps/varnish/etc/varnish/
    cp default.vcl  elain_vcl.conf
    vi elain_vcl.conf
    #############################
    backend www {
    .host = "www.elain.org";
    .port = "80";
    }

    acl purge {
    "localhost";
    "127.0.0.1";
    "172.16.2.0"/24;
    }

    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);
    }

    else {
    lookup;
    }
    return (lookup);
    }

    sub vcl_pipe {
    return (pipe);
    }

    sub vcl_pass {
    return (pass);
    }

    sub vcl_hash {
    set req.hash += req.url;
    if (req.http.host) {
    set req.hash += req.http.host;
    } else {
    set req.hash += server.ip;
    }
    return (hash);
    }

    sub vcl_hit {
    if (!obj.cacheable) {
    return (pass);
    }
    return (deliver);
    }

    sub vcl_miss {
    return (fetch);
    }

    sub vcl_fetch {
    if (!beresp.cacheable) {
    return (pass);
    }
    if (beresp.http.Set-Cookie) {
    return (pass);
    }
    return (deliver);
    }

    sub vcl_deliver {
    return (deliver);
    }

    sub vcl_error {
    set obj.http.Content-Type = "text/html; charset=utf-8";
    synthetic {"
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <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);
    }
    ###################################
    配置文件解釋:
    (1)、Varnish通過反向代理請求后端IP為172.16.2.223,端口為80的web服務器;
    (2)、Varnish允許localhost、127.0.0.1、172.16.2.233 三個來源IP通過PURGE方法清除緩存;
    (3)、Varnish對域名為www.elain.org的請求進行處理,非www.elain.org域名的請求則返回“elain Cache Server”;
    (4)、Varnish對HTTP協(xié)議中的GET、HEAD請求進行緩存,對POST請求透過,讓其直接訪問后端Web服務器。之所以這樣配置,是因為POST請求一般是發(fā)送數(shù)據(jù)給服務器的,需要服務器接收、處理,所以不緩存;
    (5)、Varnish對以.txt和.js結尾的URL緩存時間設置1小時,對其他的URL緩存時間設置為30天。

    啟動Varnish
    ulimit -SHn 65535
    /elain/apps/varnish/sbin/varnishd -f /elain/apps/varnish/etc/varnish/elain_vcl.conf -a 172.16.2.223:80 -s file,/elain/data/vcache,1G -w 1024,51200,10 -t 3600 -T 172.16.2.223:3500

    參數(shù):
    -u 以什么用運行
    -g 以什么組運行
    -f varnish 配置文件
    -a 綁定 IP 和端口
    -s varnish 緩存文件位置與大小
    -w 最小,最大線程和超時時間
    -T varnish 管理端口,主要用來清除緩存

    啟動varnishncsa用來將Varnish訪問日志寫入日志文件:
    /elain/apps/varnish/bin/varnishncsa  -w /elain/logs/varnish.log &

    停止Varnish
    pkill varnish

    配置開機自動啟動Varnish
    vi /etc/rc.local
    在末尾增加以下內容:

    ulimit -SHn 65535
    /elain/apps/varnish/sbin/varnishd -f /elain/apps/varnish/etc/varnish/elain_vcl.conf -a 172.16.2.223:80 -s file,/elain/data/vcache,1G -w 1024,51200,10 -t 3600 -T 172.16.2.223:3500
    /elain/apps/varnish/bin/varnishncsa -n /elain/data/vcache -w /elain/logs/varnish.log &

    優(yōu)化Linux內核參數(shù)
    vi /etc/sysctl.conf
    在末尾增加以下內容:

    net.ipv4.tcp_fin_timeout = 30
    net.ipv4.tcp_keepalive_time = 300
    net.ipv4.tcp_syncookies = 1
    net.ipv4.tcp_tw_reuse = 1
    net.ipv4.tcp_tw_recycle = 1
    net.ipv4.ip_local_port_range = 5000    65000

    sysctl -p

    管理Varnish:
    1、查看Varnish服務器連接數(shù)與命中率:
    /elain/apps/varnish/bin/varnishstat

    2、通過Varnish管理端口進行管理:
    用help看看可以使用哪些Varnish命令:
    /elain/apps/varnish/bin/varnishadm -T 172.16.2.223:3500 help

    [root@vanish ~]# /elain/apps/varnish/bin/varnishadm -T 172.16.2.223:3500 help
    help [command]
    ping [timestamp]
    auth response
    quit
    banner
    status
    start
    stop
    stats
    vcl.load <configname> <filename>
    vcl.inline <configname> <quoted_VCLstring>
    vcl.use <configname>
    vcl.discard <configname>
    vcl.list
    vcl.show <configname>
    param.show [-l] [<param>]
    param.set <param> <value>
    purge.url <regexp>
    purge <field> <operator> <arg> [&& <field> <oper> <arg>]...
    purge.list

    3、通過Varnish管理端口,使用正則表達式批量清除緩存:
    (1)、例:清除類似http://www.elain.org/download/111.html的URL地址):
    /elain/apps/varnish/bin/varnishadm -T 172.16.2.223:3500 url.purge /download/

    (2)、例:清除類似http://www.elain.org/dl 的URL地址:
    /elain/apps/varnish/bin/varnishadm -T 172.16.2.223:3500 url.purge w*$

    (3)、例:清除所有緩存:
    /elain/apps/varnish/bin/varnishadm -T 172.16.2.223:3500 url.purge *$

    Varnish日志切割腳本
    cat /root/scripts/cut_varnish_log.sh

    #!/bin/sh
    # This script run at 00:00
    date=$(date -d "yesterday" +"%Y-%m-%d")
    pkill -9 varnishncsa
    mv /elain/logs/varnish/images.log /elain/logs/varnish/${date}.log
    /elain/apps/varnish/bin/varnishncsa -w /elain/logs/varnish/images.log &
    mkdir -p /elain/logs/varnish/logsbak/
    gzip -c /elain/logs/varnish/${date}.log > /elain/logs/varnish/logsbak/${date}.log.gz
    rm -f /elain/logs/varnish/${date}.log
    rm -f /elain/logs/varnish/logsbak/$(date -d "-1 month" +"%Y-%m*").log.gz

    chmod 700 /root/scripts/cut_varnish_log.sh

    設置在每天00:00定時執(zhí)行:
    crontab -e

    # Info   : 每天切割varnish日志
    # Author : dingtm
    # CTime  : 2011.04.08
    0 0 * * *  /root/scripts/cut_varnish_log.sh

    官方文檔:

    http://www.varnish-cache.org/docs/2.1/

    推薦參考文檔見附件

    posted on 2012-07-24 17:34 小秦 閱讀(1364) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導航:
     
    主站蜘蛛池模板: 99免费在线观看视频| 九九免费久久这里有精品23| 日本一卡精品视频免费| 国产国拍亚洲精品mv在线观看 | 亚洲精品无码永久在线观看男男| 亚洲电影在线免费观看| 亚洲校园春色小说| 真人做人试看60分钟免费视频| 亚洲日本在线免费观看| 中国人xxxxx69免费视频| 亚洲网址在线观看| 成人无码区免费A片视频WWW| 亚洲中文无码mv| 国产国产人免费人成免费视频 | 久久久久亚洲AV无码专区首JN| 免费国产午夜高清在线视频| 亚洲丁香色婷婷综合欲色啪| 久久久久免费看成人影片| 亚洲国产成人精品无码区在线秒播| 免费视频爱爱太爽了| 亚洲国产精品成人综合色在线| 国产成人在线免费观看| 一个人免费观看日本www视频 | 97视频免费观看2区| 亚洲视频免费一区| 亚洲天堂一区二区| 亚洲区精品久久一区二区三区| 84pao强力永久免费高清| 亚洲精品天堂在线观看| 亚洲国产精品无码久久久久久曰 | 综合偷自拍亚洲乱中文字幕| 国产L精品国产亚洲区久久| 特级无码毛片免费视频尤物| 亚洲国产成人综合| 亚洲国产精品专区在线观看 | 免费在线黄色电影| 亚洲jizzjizz在线播放久| 免费在线观看黄网| 91免费国产自产地址入| 老司机福利在线免费观看| 久久丫精品国产亚洲av不卡|