Varnish 로드밸런싱 설정

varnish 로드밸런싱 설정

1 라운드로빈[ | ]

vcl 4.0;
import directors;

backend server1 {
    .host = "192.168.0.10";
    .port = "8080";
}
backend server2 {
    .host = "192.168.0.11";
    .port = "8080";
}

sub vcl_init {
    new rrdir = directors.round_robin();
    rrdir.add_backend(server1);
    rrdir.add_backend(server2);
}

sub vcl_recv {
    set req.http.X-Forwarded-For = client.ip;
    set req.backend_hint = mydir.backend();
}
→ ( sub vcl_init ) mydir라는 라운드로빈 디렉터를 만들고 백엔드서버 2개 등록
→ ( sub vcl_recv ) 모든 트래픽을 mydir로 보냄

2 해시 스티키 세션[ | ]

vcl 4.0;
import std;
import directors;
import cookie;
import header;

backend server1 {
    .host = "192.168.0.10";
    .port = "8080";
}
backend server2 {
    .host = "192.168.0.11";
    .port = "8080";
}

sub vcl_init {
	new hdir = directors.hash();
	hdir.add_backend(server1, 1);
	hdir.add_backend(server2, 1);
}

sub vcl_recv {
	cookie.parse(req.http.cookie);
	if(!cookie.isset("sticky")) {
		set req.http.sticky = std.random(1, 4);
		cookie.set("sticky", req.http.sticky);
	}
	set req.http.X-Forwarded-For = client.ip;
	set req.backend_hint = hdir.backend(cookie.get("sticky"));
}

sub vcl_deliver {
	if (req.http.placement) {
		header.append(resp.http.Set-Cookie, "sticky=" + req.http.placement
			+ "; Expires=" + cookie.format_rfc1123(now, 120m) + ";");
	}
}

3 같이 보기[ | ]

4 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}