varsh4.1 安装清除cache

yum install automake autoconf ncurses-devel libxslt groff pkgconfig python-docutils readline-devel -y
yum install gcc gcc-c++ make openssl-devel pcre-devel -y
useradd -s /sbin/nologin varnish

mkdir -p /data/varnish/cache
mkdir /data/varnish/log
mkdir /data/varnish/etc
chown -R varnish:varnish /data/varnish/cache
chown -R varnish:varnish /data/varnish/log

export PKG_CONFIG_PATH=/usr/lib64/pkgconfig
tar xf varnish-4.1.0.tar.gz
cd varnish-4.1.0
./configure --prefix=/data/varnish/ --enable-dependency-tracking --enable-developer-warnings --enable-debugging-symbols
make
make install

#,--enable-developer-warnings是指启用提示警告,默认情况下是NO,--enable-debugging-symbols是调试一些bug信息的标志。

/data/varnish/bin/varnishlog -a -w /tmp/varnish.log #启动日志
/data/varnish/sbin/varnishd -f /data/varnish/etc/default.vcl -s malloc,1024m -T 127.0.0.1:2000 -a 0.0.0.0:80
#
varnishadm "ban req.url ~ ." #清除所有缓存
varnishadm "ban req.url ~ .jpg" #清除jpg格式的文件


if (req.url ~ "^[^?]*\.(bmp|bz2|mp3|css|doc|eot|flv|gif|gz|ico|jpeg|jpg|apk|js|less|pdf|png|rtf|swf|txt|woff|xml)(\?.*)?$") {
unset req.http.Cookie;
return (hash);
}

#缓存静态文件

#-----------------------------------------------------------------------------------------------#

if (req.http.Accept-Encoding) {
if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|ogg)$") {
# No point in compressing these
unset req.http.Accept-Encoding;
} elsif (req.http.Accept-Encoding ~ "gzip") {
set req.http.Accept-Encoding = "gzip";
} elsif (req.http.Accept-Encoding ~ "deflate") {
set req.http.Accept-Encoding = "deflate";
} else {
# unkown algorithm
unset req.http.Accept-Encoding;
}
}

# Large static files should be piped, so they are delivered directly to the end-user without
# waiting for Varnish to fully read the file first.
# TODO: once the Varnish Streaming branch merges with the master branch, use streaming here to avoid locking.
if (req.url ~ "^[^?]*\.(rar|tar|tgz|gz|wav|zip)(\?.*)?$") {
unset req.http.Cookie;
return (pipe);
}

#不缓存这些格式的文件



#-----------------------清除指定域名的缓存-------------------------#
#!/bin/bash

if [ $# == 0 ];then
echo "请传入一个域名作为参数,例如: $0 source.cinyi.com"
else
/data/varnish/bin/varnishadm ban req.http.host == "$1"
fi
[ $? == 0 ]&&echo "$1 缓存清除成功"


posted @ 2016-11-22 15:34  fengjian1585  阅读(193)  评论(0编辑  收藏  举报