wget http://ftp.cs.stanford.edu/pub/exim/pcre/pcre-8.33.tar.gz
tar xzf pcre-8.33.tar.gz
cd pcre-8.33
./configure
make && make install
cd ../
varnish-3.0.4报错如下:
varnishadm.c:48:33: error: editline/readline.h: No such file or directory
varnishadm.c: In function 'cli_write':
varnishadm.c:76: warning: implicit declaration of function 'rl_callback_handler_remove'
varnishadm.c:76: warning: nested extern declaration of 'rl_callback_handler_remove'
varnishadm.c: In function 'send_line':
varnishadm.c:179: warning: implicit declaration of function 'add_history'
varnishadm.c:179: warning: nested extern declaration of 'add_history'
varnishadm.c: In function 'varnishadm_completion':
varnishadm.c:216: warning: implicit declaration of function 'rl_completion_matches'
varnishadm.c:216: warning: nested extern declaration of 'rl_completion_matches'
varnishadm.c:216: warning: assignment makes pointer from integer without a cast
varnishadm.c: In function 'pass':
varnishadm.c:233: error: 'rl_already_prompted' undeclared (first use in this function)
varnishadm.c:233: error: (Each undeclared identifier is reported only once
varnishadm.c:233: error: for each function it appears in.)
varnishadm.c:235: warning: implicit declaration of function 'rl_callback_handler_install'
varnishadm.c:235: warning: nested extern declaration of 'rl_callback_handler_install'
varnishadm.c:239: error: 'rl_attempted_completion_function' undeclared (first use in this function)
varnishadm.c:300: warning: implicit declaration of function 'rl_forced_update_display'
varnishadm.c:300: warning: nested extern declaration of 'rl_forced_update_display'
varnishadm.c:303: warning: implicit declaration of function 'rl_callback_read_char'
varnishadm.c:303: warning: nested extern declaration of 'rl_callback_read_char'
make[3]: *** [varnishadm-varnishadm.o] Error 1
make[3]: Leaving directory `/root/lnmp/src/varnish-3.0.4/bin/varnishadm'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/root/lnmp/src/varnish-3.0.4/bin'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/root/lnmp/src/varnish-3.0.4'
make: *** [all] Error 2
报错没找到解决方法,选varnish-3.0.3
代码如下:
wget http://repo.varnish-cache.org/source/varnish-3.0.3.tar.gz
tar xzf varnish-3.0.3.tar.gz
cd varnish-3.0.3
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
./configure --prefix=/usr/local/varnish --enable-debugging-symbols --enable-developer-warnings --enable-dependency-tracking --with-jemalloc
make && make install
/usr/bin/install -m 755 ./redhat/varnish.initrc /etc/init.d/varnish
/usr/bin/install -m 644 ./redhat/varnish.sysconfig /etc/sysconfig/varnish
/usr/bin/install -m 755 ./redhat/varnish_reload_vcl /usr/local/varnish/bin
useradd -M -s /sbin/nologin varnish
sed -i "s@^VARNISH_VCL_CONF=/etc/varnish/default.vcl@#VARNISH_VCL_CONF=/etc/varnish/default.vcl\nVARNISH_VCL_CONF=/usr/local/varnish/etc/varnish/linuxeye.vcl@" /etc/sysconfig/varnish
sed -i "s@^VARNISH_LISTEN_PORT=6081@#VARNISH_LISTEN_PORT=6081\nVARNISH_LISTEN_PORT=80@" /etc/sysconfig/varnish
sed -i "s@^VARNISH_SECRET_FILE=/etc/varnish/secret@#VARNISH_SECRET_FILE=/etc/varnish/secret\nVARNISH_SECRET_FILE=/usr/local/varnish/etc/varnish/secret@" /etc/sysconfig/varnish
sed -i "s@^VARNISH_STORAGE_FILE=/var/lib/varnish/varnish_storage.bin@#VARNISH_STORAGE_FILE=/var/lib/varnish/varnish_storage.bin\nVARNISH_STORAGE_FILE=/usr/local/varnish/var/varnish_storage.bin@" /etc/sysconfig/varnish
sed -i "s@^VARNISH_STORAGE_SIZE.*@VARNISH_STORAGE_SIZE=150M@" /etc/sysconfig/varnish
sed -i "s@^VARNISH_STORAGE=.*@VARNISH_STORAGE="malloc,\${VARNISH_STORAGE_SIZE}"@" /etc/sysconfig/varnish
#对于请求类型是GET,并且请求的URL中包含upload,那么就进行缓存,缓存的时间是300秒,即5分钟
sub vcl_fetch {
if (req.request == "GET" && req.url ~ "^/upload(.*)$") {
set beresp.ttl = 300s;
}</p> <p> if (req.request == "GET" && req.url ~ "\.(png|gif|jpg|jpeg|bmp|swf|css|js|html|htm|xsl|xml|pdf|ppt|doc|docx|chm|rar|zip|ico|mp3|mp4|rmvb|ogg|mov|avi|wmv|txt)$") {
unset beresp.http.set-cookie;
set beresp.ttl = 30d;
}
return (deliver);
}
代码如下:
#下面是添加一个Header标识,以判断缓存是否命中
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT from demo.linuxeye.com";
} else {
set resp.http.X-Cache = "MISS from demo.linuxeye.com";
}
return (deliver);
}