歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux教程

Ubuntu 9.10下varnish的安裝和配置

環境:Ubuntu 9.10; squid監聽173.26.100.214:80 ; varnish監聽173.26.100.214:81
1.安裝
*在http://sourceforge.net/projects/varnish/files/varnish/2.0.4/varnish-2.0.4.tar.gz下載varnish2.0.4.
*tar zxvf  varnish-2.0.4.tar.gz
*在解壓後的varnish-2.0.4目錄下,運行./autogen.sh
*./configure --prefix [指定的目錄以下記為dir]  --enable-developer-warnings  --enable-debugging-symbols
*make
*make install
2.配置
創建cache目錄:
mkdir -p /cache/varnish/V  && chown -R  777 /cache
編寫啟動腳本,下面是我的啟動腳本:
#!/bin/sh
#file:start.sh
date -u
/usr/local/varnish/sbin/varnishd -a 173.26.100.214:81  -s file,/cache/varnish/V,1024m  -f /usr/local/varnish/etc/varnish/default.vcl  -p thread_pool_max=1500  -p thread_pools=5  -p listen_depth=512  -p client_http11=on
在dir/etc/varnish/default.vcl下修改配置,下面是我配置的一部分:
backend default {
.host = "173.26.100.214";
.port = "80";
}     /*squid做後端*/
sub vcl_recv {
if (req.request != "GET" &&
req.request != "HEAD" &&
req.request != "PUT" &&
req.request != "POST" &&
req.request != "TRACE" &&
req.request != "OPTIONS" &&
req.request != "DELETE") {
/* Non-RFC2616 or CONNECT which is weird. */
return (pipe);
}
if (req.request != "GET" && req.request != "HEAD") {
/* We only deal with GET and HEAD by default */
return (pass);
}
if (req.http.Authorization || req.http.Cookie) {
/* Not cacheable by default */
return (pass);
}
return (lookup);
}

sub vcl_pipe {
return (pipe);
}

sub vcl_pass {
return (pass);
}

sub vcl_hash {
set req.hash += req.url;
if (req.http.host) {
set req.hash += req.http.host;
} else {
set req.hash += server.ip;
}
return (hash);
}

sub vcl_hit {
if (!obj.cacheable) {
return (pass);
}
return (deliver);
}

sub vcl_miss {
return (fetch);
}

sub vcl_fetch {
if (!obj.cacheable) {
return (pass);
}
if (obj.http.Set-Cookie) {
return (pass);
}
set obj.prefetch = -30s;
return (deliver);
}

sub vcl_deliver {
return (deliver);
}

sub vcl_discard {
/* XXX: Do not redefine vcl_discard{}, it is not yet supported */
return (discard);
}

sub vcl_prefetch {
/* XXX: Do not redefine vcl_prefetch{}, it is not yet supported */
return (fetch);
}

sub vcl_timeout {
/* XXX: Do not redefine vcl_timeout{}, it is not yet supported */
return (discard);
}

sub vcl_error {
set obj.http.Content-Type = "text/html; charset=utf-8";
synthetic {"
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>"} obj.status " " obj.response {"</title>
</head>
<body>
<h1>Error "} obj.status " " obj.response {"</h1>
<p>"} obj.response {"</p>
<h3>Guru Meditation:</h3>
<p>XID: "} req.xid {"</p>
<address>
<a href="http://www.varnish-cache.org/">Varnish</a>
</address>
</body>
</html>
"};
return (deliver);
}
經測試,varnish做代理的訪問速度比squid最快大10倍多
Copyright © Linux教程網 All Rights Reserved