쿵쿵일지
docker 세팅 본문
맥에서 brew로 간단하게 docker 설치
brew install docker boot2docker
boot2docker를 사용하는 이유는 docker가 ubuntu만 지원하기 때문에
VM을 사용하지 않고 경량화된 가상환경을 만들기 위해 boot2docker를 만들었다. 개발환경으로 사용하기는 충분
메모리, 포트 , 원본서버
varnishd -s malloc,4G -a :80 -b 10.1.2.3:80 -> 디폴트 설정이고 장점을 잘 살릴려면 원하는 형식으로 잘 설정해야한다.
VCL이라는 varnish언어가 있고 이 언어를 통해서 입맛에 맡게 잘 설정해야 한다. 이 varnish 언어를 통해 작성하면 -> C program으로 바뀌고 -> 이게 varnish link로 바뀐다.
vcl.list -> vcl을 여러개 저장해놓고 리스트를 통해 여러개 중에서 한개를 선택할 수 있기 때문에 vcl.list를 통해 확인한다.
vcl.load -> vcl list중 하나를 로드한다
vcl.use -> 런타임 중에 vcl 을 바꿀 수 있다.
vcl_recv,
varnish 관련 영상 : http://deview.kr/2013/detail.nhn?topicSeq=3
docker images -> docker image 확인
docker ps -> docker 현재 떠잇는 인스턴스 확인
docker rmi -f imageID
docker rm -f containerId
docs
https://docs.docker.com/
hit_for_pass
A hit_for_pass object is made to optimize the fetch procedure against a backend server.
vcl 작성
import std;
backend default {
.host = "display.coupang.com";
.port = "80";
.probe = {
.url = "/hello";
.timeout = 2s;
.interval = 30s;
.window = 5;
.threshold = 3;
}
}
sub vcl_recv {
# Called at the beginning of a request, after the complete request has been received and parsed.
# Its purpose is to decide whether or not to serve the request, how to do it, and, if applicable, which backend to use.
# display는 purge 필요 없음 (ttl이 1s 이기 때문)
if (req.restarts == 0) {
if (req.http.X-Forwarded-For) {
set req.http.X-Forwarded-For = req.http.X-Forwarded-For + ", " + client.ip;
} else {
set req.http.X-Forwarded-For = client.ip;
}
}
if (req.request != "GET" && req.request != "HEAD" && req.request != "PUT" && req.request != "POST" &&
req.request != "TRACE" && req.request != "OPTIONS" && req.request != "PATCH" && req.request != "DELETE") {
return (pipe);
}
if (req.request != "GET" && req.request != "HEAD") {
return (pass);
}
# probe를 통해서만 이 값을 사용할 수 있다.
# 200 응답이 아닐 때만 grace모드를 길게 가져간다. 복구를 위해
if (req.backend.healthy) {
set req.grace = 30s;
} else {
set req.grace = 3h;
}
# cookie 있으면 기본적으로 캐쉬하지 않음
unset req.http.Cookie;
if (req.url ~ "^/api/") {
return(lookup);
}
return(pass);
}
sub vcl_pipe {
#브라우저와 varnish 사이의 연결 지속 시간 지정 (default 5s)
set bereq.http.connection = "close";
return (pipe);
}
sub vcl_pass {
return (pass);
}
sub vcl_hash {
hash_data(req.url);
if (req.http.host) {
hash_data(req.http.host);
} else {
hash_data(server.ip);
}
return (hash);
}
sub vcl_hit {
return (deliver);
}
sub vcl_miss {
return (fetch);
}
sub vcl_fetch {
# Called after a document has been successfully retrieved from the backend.
if (req.restarts < 3 && beresp.status >= 500 && beresp.status <= 599){
std.log("vcl_fetch\treq.xid:" + req.xid + "\responseStatus:" + beresp.status + "\turl:" + bereq.url);
return(restart);
}
if (req.restarts < 4 && beresp.status == 500 || beresp.status == 502 || beresp.status == 503) {
std.log("vcl_fetch\treq.xid:" + req.xid + "\responseStatus:" + beresp.status + "\turl:" + bereq.url + "\tsaintmode");
set beresp.saintmode = 10s;
return(restart);
}
if (beresp.status != 200) {
std.log("vcl_fetch\treq.xid:" + req.xid + "\responseStatus:" + beresp.status + "\turl:" + bereq.url + "\thit_for_pass");
return (hit_for_pass);
}
# cookie 있으면 기본적으로 캐쉬하지 않음
unset beresp.http.set-cookie;
remove beresp.http.Vary;
set beresp.grace = 3h;
set beresp.ttl = 1s;
return (deliver);
}
sub vcl_deliver {
# Called before a cached object is delivered to the client.
unset resp.http.Server;
unset resp.http.X-Varnish;
# 브라우저와 Varnish 사이의 연결 지속 시간 (default 5s)
set resp.http.connection = "close";
return (deliver);
}
sub vcl_error {
# Called when we hit an error, either explicitly or implicitly due to backend or internal errors.
std.log("vcl_error\treq.xid:" + req.xid + "\tresponseStatus:" + obj.status + "\turl:" + req.url + "\thit_for_pass");
set obj.http.Content-Type = "text/html; charset=utf-8";
set obj.http.Retry-After = "5";
synthetic {"\{code:"+obj.status+"; message:"+obj.status+"\}"};
return (deliver);
}
sub vcl_init {
return (ok);
}
sub vcl_fini {
return (ok);
}