准备包:
wget && tar zxvf varnish-4.0.0-tp1.tar.gz && cd varnish-4.0.0-tp1
安装:
root@d1:/opt/1/varnish-4.0.0-tp1# ./autogen.sh
+ libtoolize --copy --force
libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, `build-aux'.
libtoolize: copying file `build-aux/ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4'.
libtoolize: copying file `m4/libtool.m4'
libtoolize: copying file `m4/ltoptions.m4'
libtoolize: copying file `m4/ltsugar.m4'
libtoolize: copying file `m4/ltversion.m4'
libtoolize: copying file `m4/lt~obsolete.m4'
+ aclocal -I m4
+ autoheader
+ automake --add-missing --copy --foreign
+ autoconf
安装、编译:
export PKG_CONFIG_PATH=/usr/lib/pkgconfig:$PKG_CONFIG_PATH;./autogen.sh && ./configure --prefix=/usr/local/varnish --enable-debugging-symbols --enable-developer-warnings --enable-dependency-tracking --with-jemalloc;make
make install
#############################################
varnish-3.0.4-4.0.0 编译都出错误。
varnishadm.c:48:33: error: editline/readline.h:No such file or directory
解决:
apt-get install -y ncurses*
apt-get install -y libedit*
Centos6.2 x86_64环境
yum -y install ncurses-devel
rpm -ivh ftp://rpmfind.net/linux/centos/6.4/os/x86_64/Packages/libedit-devel-2.11-4.20080712cvs.1.el6.x86_64.rpm
再重新configure 解决3.04/3.05问题
#############################################
root@d1:/usr/local/varnish/sbin# ./varnishd -V
varnishd (varnish-4.0.0-tp1 revision b9226c1)
Copyright (c) 2006 Verdens Gang AS
Copyright (c) 2006-2011 Varnish Software AS
建立缓存目录
useradd -s /sbin/nologin varnish
mkdir -p /usr/local/varnish/cache
mkdir -p /usr/local/varnish/log
chown -R varnish:varnish /usr/local/varnish/log
chown -R varnish:varnish /usr/local/varnish/cache
启动主服务
/usr/local/varnish/sbin/varnishd -P /usr/local/varnish/run/varnish.pid -a 10.10.18.244:80 -T 127.0.0.1:3500 -f /usr/local/varnish/etc/vcl.conf -u varnish -g varnish -n /usr/local/varnish/cache/ -s malloc,1G -P client_http11=on
启动日志管理
/usr/local/varnish/bin/varnishncsa -n /usr/local/varnish/cache/ -w /usr/local/varnish/logs/varnish.log &
测试(此图片已经在mongodb中):
[root@vm-250 ~]# curl -I
HTTP/1.1 200 OK
Server: nginx/1.5.8
Content-Type: jpg
Expires: Thu, 31 Dec 2037 23:55:55 GMT
Cache-Control: max-age=315360000, public
Date: Thu, 16 Jan 2014 02:53:00 GMT
X-Varnish: 32806 22
Age: 349
Via: 1.1 varnish
Content-Length: 2807
Connection: keep-alive
[root@vm-250 ~]# curl -I
HTTP/1.1 200 OK
Server: nginx/1.5.8
Content-Type: jpg
Expires: Thu, 31 Dec 2037 23:55:55 GMT
Cache-Control: max-age=315360000, public
Date: Thu, 16 Jan 2014 06:28:11 GMT
X-Varnish: 32798 3
Age: 15
Via: 1.1 varnish
X-Cache: MISS from
Content-Length: 2807
Connection: keep-alive
如何判断是否是经过缓存的呢??
首先可以看Age字段,如果是大于0的话,说明是从缓存命中的。其次查看X-Varnish字段,如果是两个数字例如X-Varnish:32798 3
代表的是Varnish两次请求id(req.xid):一个为发起请求的id,另外一个是获取缓存的id,而缓存未命中或者pass到后端的情况都是一个数值(当然你可以在deliver过程中修改这些头信息或者直接隐藏掉)?
注意!? 如果后端程序设置了类似这样的头信息Cache-Control:?max-age=300?会重置默认的缓存时间TTL,当然你可以在配置文件中重置这个时间
####################################################
#去掉 varnish 中的一些头信息(如果你不想保留的话,建议保留 Age,方便查看)
remove resp.http.X-Varnish;
remove resp.http.Via;
return (deliver);
[root@vm-250 ~]# curl -I
HTTP/1.1 200 OK
Server: nginx/1.5.8
Content-Type: jpg
Expires: Thu, 31 Dec 2037 23:55:55 GMT
Cache-Control: max-age=315360000, public
Date: Thu, 16 Jan 2014 06:39:33 GMT
-------------------------
X-Varnish: 32774 3
Age: 6
-------------------------
X-Cache: MISS from
Content-Length: 2807
Connection: keep-alive
检测性能:
root@d1:/usr/local/varnish/etc# /usr/local/varnish/bin/varnishstat -n /usr/local/varnish/cache/
Uptime mgt: 0+00:11:00
Uptime child: 0+00:11:00
NAME CURRENT CHANGE AVERAGE AVG_10 AVG_100 AVG_1000
MAIN.uptime 660 1.00 1.00 1.00 1.00 1.00
MAIN.sess_conn 10 0.00 . 0.00 0.00 0.00
MAIN.client_req 97 0.00 . 0.00 0.00 0.00
MAIN.cache_hit 93 0.00 . 0.00 0.00 0.00
MAIN.cache_miss 4 0.00 . 0.00 0.00 0.00
MAIN.backend_conn 2 0.00 . 0.00 0.00 0.00
MAIN.backend_reuse 2 0.00 . 0.00 0.00 0.00
MAIN.backend_toolate 1 0.00 . 0.00 0.00 0.00
MAIN.backend_recycle 4 0.00 . 0.00 0.00 0.00
MAIN.fetch_length 4 0.00 . 0.00 0.00 0.00
MAIN.pools 2 0.00 . 2.00 2.00 2.00
MAIN.threads 200 0.00 . 200.00 200.00 200.00
MAIN.threads_created 200 0.00 . 0.00 0.00 0.00
MAIN.n_object 4 0.00 . 4.00 4.00 4.00
MAIN.n_objectcore 6 0.00 . 6.00 6.00 6.00
MAIN.n_objecthead 6 0.00 . 6.00 6.00 6.00
MAIN.n_backend 1 0.00 . 1.00 1.00 1.00
MAIN.s_sess 10 0.00 . 0.00 0.00 0.00
MAIN.s_req 97 0.00 . 0.00 0.00 0.00
MAIN.s_fetch 4 0.00 . 0.00 0.00 0.00
MAIN.s_hdrbytes 30909 0.00 46.00 0.00 0.00 0.00
MAIN.s_bodybytes 2142154 0.00 3245.00 0.00 0.00 0.00
MAIN.backend_req 4 0.00 . 0.00 0.00 0.00
MAIN.n_vcl 1 0.00 . 0.00 0.00 0.00
MAIN.bans 1 0.00 . 1.00 1.00 1.00
MGT.uptime 660 1.00 1.00 1.00 1.00 1.00
SMA.s0.c_req 7 0.00 . 0.00 0.00 0.00
SMA.s0.c_bytes 1993075 0.00 3019.00 0.00 0.00 0.00
SMA.s0.g_alloc 7 0.00 . 7.00 7.00 7.00
SMA.s0.g_bytes 1993075 0.00 . 1993075.00 1993075.00 1993075.00
SMA.s0.g_space 1071748749 0.00 . 1071748749.0 1071748749.0 1071748749.0
0
4.0版本的配置文件语法与以往的语法有一定的区别,需要注意一下。
官方地址:
阅读(3745) | 评论(0) | 转发(0) |