2月 132010
varnishはメモリの使い方もとっても素直でマルチコアにも対応していて結構いいパフォーマンスなので
一台で複数のドメインを管理しても問題ないです
じゃぁどのように設定すればいいでしょうか?
以下VCL記述例
sub vcl_recv {
if (req.http.host ~ "^img01.xcir.net$")
#HTTP_HOSTがimg01.xcir.netの場合cl_01へ処理を飛ばす
{set req.backend = cl_01;}
elseif(req.http.host ~ "^img02.xcir.net$")
#HTTP_HOSTがimg02.xcir.netの場合cl_02へ処理を飛ばす
{set req.backend = cl_02;}
}
##########################################################################################
backend cache01_01 {
.host = "192.168.1.111";
#バックエンドアクセスするときはHOSTを設定する
.host_header = "img01.xcir.net";
.port = "80";
#ヘルスチェックの設定
.probe = {
.url = "/healthcheck.gif";
.timeout = 0.3 s;
.window = 8;
.threshold = 3;
}
}
backend cache01_02 {
.host = "192.168.1.112";
.host_header = "img01.xcir.net";
.port = "80";
.probe = {
.url = "/healthcheck.gif";
.timeout = 0.3 s;
.window = 8;
.threshold = 3;
}
}
director cl_01 random {
.retries = 5;
{
.backend = cache01_01;
.weight = 5;
}
{
.backend = cache01_02;
.weight = 5;
}
}
##########################################################################################
backend cache02_01 {
.host = "192.168.1.121";
.host_header = "img02.xcir.net";
.port = "80";
.probe = {
.url = "/healthcheck.gif";
.timeout = 0.3 s;
.window = 8;
.threshold = 3;
}
}
backend cache02_02 {
.host = "192.168.1.122";
.host_header = "img02.xcir.net";
.port = "80";
.probe = {
.url = "/healthcheck.gif";
.timeout = 0.3 s;
.window = 8;
.threshold = 3;
}
}
director cl_02 random {
.retries = 5;
{
.backend = cache02_01;
.weight = 5;
}
{
.backend = cache02_02;
.weight = 5;
}
}
##########################################################################################
sub vcl_fetch {
if(obj.status==404){
#404の場合はTTLを一分に設定する
set obj.ttl=1m;
}
}
.probeが設定されているとヘルスチェックを行い指定URLにアクセスできない場合
ノード切り離しを行います
復帰すればノードに追加します
いくつかのポイントについて
.probeの設定ポイント
.uriはヘルスチェックURLです
画像でもHTMLでもなんでもいいですがこれがないとノード切り離しされますので注意しましょう
vcl_fetchで404を見ている理由
squidでいうnegative_ttlの代わりです
バックエンドがダウンしてたときに変な情報をキャッシュしてもすぐ復帰できるように設定しています
本当はいろいろパフォーマンスをあげるテクニックがあるのですがまたの機会に・・・