varnish安装维护
/varnish%E5%AE%89%E8%A3%85%E7%BB%B4%E6%8A%A4/
各文档所在位置
日志文件 /var/log/varnish/varnish.log
可执行程序 /usr/local/varnish/bin
缓冲文件 /var/vcache
配置文件 /usr/local/f
启动参数 /etc/sysconfig/varnish
启动脚本 /etc/rc.d/init.d/varnish
/etc/rc.d/init.d/varnishlog
创建www用户和组,以及Varnish缓存文件存放目录(/var/vcache):
/usr/sbin/groupadd www -g 48
/usr/sbin/uradd -u 48 -g www www
mkdir -p /var/vcache
chmod +w /var/vcache
chown -R www:www /var/vcache
创建日志文件,并授予www用户权限访问
mkdir -p /var/log/varnish
chmod +w /var/log/varnish
chown -R www:www /var/log/varnish
可能需要安装如下包
[CENTOS]yum install ncurs-devel
[UBUNTU]apt-get install libncurs5-dev
小狗日记编译安装
./configure –prefix=/usr/local/varnish
make
make install
编辑配置文件
vi /usr/local/f
view plaincopy to clipboardprint?
backend myblogrver {
t backend.host = “192.168.0.5″;
t backend.port = “80″;
}
acl purge {
“localhost”;
“127.0.0.1″;
“192.168.1.0″/24;
}
sub vcl_recv {
if (quest == “PURGE”) {
虾仁炒蛋
if (!client.ip ~ purge) {
error 405 “Not allowed.”;
}
lookup;
}
if (req.http.host ~ “君子兰肥料^”) {
t req.backend = myblogrver;
if (quest != “GET” && quest != “HEAD”) {
pipe;
}
elif(req.url ~ “\.(php|cgi)($|\?)”) {
pass;
}
el {
lookup;
}
}
el {
error 404 “Cache Server”;
lookup;
}
}
sub vcl_hit {
if (quest == “PURGE”) {
l = 0s;
error 200 “Purged.”;
}
}
sub vcl_miss {
if (quest == “PURGE意境网名”) {
error 404 “Not in cache.”;
}
}
sub vcl_fetch {
if (quest == “GET” && req.url ~ “\.(txt|js)$”) {
l = 3600s;
}
el {
l = 30d;
}
}
backend myblogrver {
t backend.host = “192.168.0.5″;
t backend.port = “80″;
}
acl purge {
“localhost”;
“127.0.0.1″;
“192.168.1.0″/24;
}
sub vcl_recv {
if (quest == “PURGE”) {
if (!client.ip ~ purge) {
error 405 “Not allowed.”;
}
lookup;
}
if (req.http.host ~ 连阴雨“^”) {
t req.backend = myblogrver;
if (quest != “GET” && quest != “HEAD”) {
pipe;
}
elif(req.url ~ “\.(php|cgi)($|\?)”) {
pass;
}
el {
lookup;
}
}
el {
error 404 “Cache Server”;
lookup;
}
}
sub vcl_hit {
if (quest == “PURGE”) {
l = 0s;
error 200 “Purged.”;
}
}
sub vcl_miss {
if (quest == “热门新闻PURGE”) {
error 404 “Not in cache.”;
}
}
sub vcl_fetch {
if (quest == “GET” && req.url ~ “\.(txt|js)$”) {
l = 3600s;
}
el {
l = 30d;
}
}冷死了表情包
启动allowingvarnish
ulimit -SHn 51200
/usr/local/varnish/sbin/varnishd -n /var/vcache -f /usr/local/f -a 0.0.0.0:80 -s file,/var/vcache/varnish_cache.data,1G -g www -u www -w 30000,51200,10 -T 127.0.0.1:3500 -p client_http11=on
启动varnishncsa记录访问日志
/usr/local/varnish/bin/varnishncsa -n /var/vcache -w /var/log/varnish/varnish.log &