Varnish安装与配置

传说中,Varnish比Squid要快很多倍,我没在实际的生产环境中检查过,但Varnish可以按条件清理缓存,这是Squid不可回避的弱点。

安装环境:

OS:Linux CentOS 5.5

Varnish:Varnish 2.1.2

第一步:下载Varnish

下载地址:http://sourceforge.net/projects/varnish/files/

第二步:基本目录配置

1、创建www用户和组,以及Varnish缓存文件存放目录(/var/vcache):

/usr/sbin/groupadd www -g 48

/usr/sbin/useradd -u 48 -g www www

mkdir -p /data/varnish/vcache

chmod +w /data/varnish/vcache

chown -R www:www /data/varnish/vcache

2、创建Varnish日志目录:

mkdir -p /data/varnish/logs

chmod +w /data/varnish/logs

chown -R www:www /data/varnish/logs

第三步:编译安装

tar zxvf varnish-2.1.2.tar.gz

cd varnish-2.1.2

./configure --prefix=/opt/varnish

make

make install

安装过程中,很可能出现"No package 'libpcre' found"

Varnish需要pcre支持,如果服务器没有安装pcre-devel会提示需要指定prce目录。

Centos服务器上使用yum install pcre-devel安装

第四步:配置

vi /opt/varnish/etc/varnish/www.vcl

输入:附件中 www.vcl 内容

第五步:启动

/opt/varnish/sbin/varnishd -u www -g www -f /opt/varnish/etc/varnish/www.vcl -a 119.254.69.171:80 -s file,/data/varnish/vcache/varnish_cache.data,3G -w 1024,51200,10 -t 3600 -T 127.0.0.1:3500

#启动varnishncsa用来将Varnish访问日志写入日志文件:

/opt/varnish/bin/varnishncsa -w /data/varnish/logs/varnish.log &

第六步:配置开机自动启动Varnish

vi /etc/rc.local

追加:

/opt/varnish/sbin/varnishd -u www -g www -f /opt/varnish/etc/varnish/www.vcl -a 119.254.69.171:80 -s file,/data/varnish/vcache/varnish_cache.data,3G -w 1024,51200,10 -t 3600 -T 127.0.0.1:3500

/opt/varnish/bin/varnishncsa -w /data/varnish/logs/varnish.log &

第七步:如何动态加载配置

/opt/varnish/bin/varnishadm -T 127.0.0.1:3500

vcl.load vcl-03 "/opt/varnish/etc/varnish/www.vcl"

vcl.use vcl-03

第八步:优化Linux内核参数

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

第九步:如何清理缓存

有两种方法:

1、登录系统命令行清理(适合批量操作)

清除所有缓存 # /opt/varnish/bin/varnishadm -T 127.0.0.1:3500 url.purge ^.*$

请注意很多资料说

# /opt/varnish/bin/varnishadm -T 127.0.0.1:3500 url.purge *$

可以清理所有缓存,那是2.0前的版本,2.0后必须严格按照正则规范匹配

2、通过HTTP协议清理

请查看附件index.php

当然也可以用PHP函数exec调用命令行。

附件下载:点击下载安装手册及配置文档

最新评论:

no.13062 tonyhill25ps1620z62 146.185.223.221 2017-12-04 06:14

A Biological Masterpiece, But Subject to Many Ills The human foot is a biological masterpiece. Its strong, flexible, and functional design enables it to do its job well and without complaint—if you take care of it and don't take it for granted. healthThe foot can be compared to a finely tuned race car, or a space shuttle, vehicles whose function dictates their design and structure. And like them, the human foot is complex, containing within its relatively small size 26 bones (the two feet co

no.13006 jamespagnp 146.185.223.221 2017-10-11 14:38

Writing a medical thesis or dissertation is a task done by almost all postgraduate and master's medical students. Dissertation is derived from the Latin word disserto which means discuss. It is essential to write successful medical papers such as medicine essays and medical thesis papers. There are several reasons as to why students write medicine essays. One of the reasons is to promote enhancement of critical judgment, research skills as well as analytical skills. Moreover, medicine essay writ

no.12985 nicoladinicolatmwv 146.185.223.221 2017-10-03 09:43

Writing doctoral dissertation is a prerequisite before a PhD degree conferred to you. It usually entails conducting some form of research. Dissertation writing is therefore not among the simplest form of writing you will come across. Dissertation writing process will normally begin by selecting of a topic or a concept. The topic should be on a relevant field and that which would lead to development of new knowledge in the field. While selecting a topic for dissertation writing, ensures that your

no.12903 laelebeidiorg 146.185.223.114 2017-08-21 07:05

301 Moved Permanently [url=https://www.viagrapascherfr.com/]More info![/url]

no.10178 0exhgoocq 188.143.232.32 2016-06-08 13:26

Woah nelly, how about them appsel!

no.3634 1610230564 114.255.31.253 2013-07-22 14:00

解压密码?博主好人

no.3454 lianghaibing2005 211.99.232.2 2013-04-27 14:16

解压密码是什么

no.2579 287405901 219.159.198.217 2012-03-16 11:57

求解压秘密啊

no.2422 77608487 14.153.233.161 2011-12-29 10:42

no.2397 r.cloucliespen 109.230.216.60 2011-12-15 04:09

Just cause it's simple doesn't mean it's not super helfupl.

发表评论:

邮箱: