Varnish Squid
          w/	
  puppet	
  
               @ar1	
  
§                   	
                	
 
§  Debian	
                            	
  
§  Amazon	
  Web	
  Services                  	
  
      ú  Solutions	
  Architect	
  
      ú 
LoadBalance:	
     HighSpeed-­‐
    LVS	
             Cache	
  
  HAProxy	
  
(          )	
  
    	
  
 

       	
  
 
              !	
  
       	
  
 
Cache	
  
                                  Shareing	
  
LoadBalance:	
     HighSpeed-­‐    Sibling	
  
    LVS	
             Cache	
  
  HAProxy	
  
Request URI test-­‐a.example.jp   	
  
                           	
  




    varnish    cache       	
  




                       cache      squid   	
  
squid           cache       	
  




        cache     sibling          	
  




                                          HTTPD 	
  
Config:	
  squid	
  
[sibling.conf]	
  cache_peer	
  10.2.1.26	
  sibling	
  80	
  3130	
  

[squid.conf]	
  
http_port	
  8801	
  accel	
  defaultsite=test-­‐a-­‐origin.example.jp	
  
cache_peer	
  test-­‐a-­‐origin.example.jp	
  parent	
  80	
  0	
  originserver	
  name=test-­‐a-­‐origin_example_jp	
  
acl	
  test-­‐a-­‐origin_example_jp	
  dstdomain	
  test-­‐a-­‐origin.example.jp	
  
http_access	
  allow	
  test-­‐a-­‐origin_example_jp	
  
cache_peer_access	
  test-­‐a-­‐origin_example_jp	
  allow	
  test-­‐a-­‐origin_example_jp	
  
cache_peer_access	
  test-­‐a-­‐origin_example_jp	
  deny	
  all	
  
http_port	
  8802	
  accel	
  defaultsite=test-­‐k.example.jp	
  
cache_peer	
  test-­‐k.example.jp	
  parent	
  80	
  0	
  originserver	
  name=test-­‐k_example_jp	
  
acl	
  test-­‐k_example_jp	
  dstdomain	
  test-­‐k.example.jp	
  
http_access	
  allow	
  test-­‐k_example_jp	
  
cache_peer_access	
  test-­‐k_example_jp	
  allow	
  test-­‐k_example_jp	
  
cache_peer_access	
  test-­‐k_example_jp	
  deny	
  all	
  
http_port	
  8803	
  accel	
  defaultsite=test-­‐a.example.jp	
  
cache_peer	
  test-­‐a.example.jp	
  parent	
  80	
  0	
  originserver	
  name=test-­‐a_example_jp	
  
acl	
  test-­‐a_example_jp	
  dstdomain	
  test-­‐a.example.jp	
  
http_access	
  allow	
  test-­‐a_example_jp	
  
cache_peer_access	
  test-­‐a_example_jp	
  allow	
  test-­‐a_example_jp	
  
cache_peer_access	
  test-­‐a_example_jp	
  deny	
  all	
  
	
  
Config:	
  varnish	
  
sub	
  vcl_recv	
  {	
                                                                                                     backend	
  proxy5_test_a_origin_example_jp	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  if	
  (req.http.If-­‐Modified-­‐Since)	
  {	
                                               	
  	
  .host	
  =	
  "10.2.1.26";	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  error	
  304;	
                                            	
  	
  .port	
  =	
  "8801";	
  
	
  	
  	
  	
  	
  	
  	
  	
  }	
                                                                                        	
  	
  .connect_timeout	
  =	
  30ms;	
  
	
  	
  	
  	
  	
  	
  	
  	
  if	
  (req.http.host	
  ==	
  "test-­‐a-­‐origin.example.jp"){	
                           }	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  set	
  req.backend	
  =	
  test_a_origin_example_jp;	
     	
  	
  	
  	
  	
  	
  
	
                                                                                                                         backend	
  proxy5_test_k_example_jp	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  }	
  elsif	
  (req.http.host	
  ==	
  "test-­‐k.example.jp"){	
                            	
  	
  .host	
  =	
  "10.2.1.26";	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  set	
  req.backend	
  =	
  test_k_example_jp;	
            	
  	
  .port	
  =	
  "8802";	
  
	
                                                                                                                         	
  	
  .connect_timeout	
  =	
  30ms;	
  
	
  	
  	
  	
  	
  	
  	
  	
  }	
  elsif	
  (req.http.host	
  ==	
  "test-­‐a.example.jp"){	
                            }	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  set	
  req.backend	
  =	
  test_a_example_jp;	
            	
  	
  	
  	
  	
  	
  
	
                                                                                                                         backend	
  proxy5_test_a_example_jp	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  }	
  else	
  {	
                                                                           	
  	
  .host	
  =	
  "10.2.1.26";	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  set	
  req.backend	
  =	
  default;	
                      	
  	
  .port	
  =	
  "8803";	
  
	
  	
  	
  	
  	
  	
  	
  	
  }	
                                                                                        	
  	
  .connect_timeout	
  =	
  30ms;	
  
}	
                                                                                                                        }	
  
	
                                                                                                                         	
  
Config:	
  varnish(2)	
  
backend	
  proxy5	
  {	
                                          director	
  test_a_origin_example_jp	
  round-­‐robin	
  {	
  
	
  	
  .host	
  =	
  "10.2.1.26";	
                              	
  	
  	
  	
  	
  	
  	
  	
  {	
  .backend	
  	
  	
  	
  	
  	
  =	
  proxy5_test_a_origin_example_jp;	
  }	
  
	
  	
  .port	
  =	
  "80";	
                                     	
  	
  	
  	
  	
  	
  	
  	
  {	
  .backend	
  	
  	
  	
  	
  	
  =	
  proxy4_test_a_origin_example_jp;	
  }}	
  
	
  	
  .connect_timeout	
  =	
  30ms;}	
                         director	
  test_k_example_jp	
  round-­‐robin	
  {	
  
backend	
  proxy4_test_a_origin_example_jp	
  {	
                 	
  	
  	
  	
  	
  	
  	
  	
  {	
  .backend	
  	
  	
  	
  	
  	
  =	
  proxy5_test_k_example_jp;	
  }	
  
	
  	
  .host	
  =	
  "10.2.1.27";	
                              	
  	
  	
  	
  	
  	
  	
  	
  {	
  .backend	
  	
  	
  	
  	
  	
  =	
  proxy4_test_k_example_jp;	
  }}	
  
	
  	
  .port	
  =	
  "8801";	
                                   director	
  test_a_example_jp	
  round-­‐robin	
  {	
  
	
  	
  .connect_timeout	
  =	
  30ms;}	
  	
  	
  	
  	
  	
     	
  	
  	
  	
  	
  	
  	
  	
  {	
  .backend	
  	
  	
  	
  	
  	
  =	
  proxy5_test_a_example_jp;	
  }	
  
backend	
  proxy4_test_k_example_jp	
  {	
                        	
  	
  	
  	
  	
  	
  	
  	
  {	
  .backend	
  	
  	
  	
  	
  	
  =	
  proxy4_test_a_example_jp;	
  }}	
  
	
  	
  .host	
  =	
  "10.2.1.27";	
                              director	
  default	
  round-­‐robin	
  {	
  
	
  	
  .port	
  =	
  "8802";	
                                   	
  	
  	
  	
  	
  	
  	
  	
  {	
  .backend	
  	
  	
  	
  	
  	
  =	
  proxy5;	
  }	
  
	
  	
  .connect_timeout	
  =	
  30ms;}	
                         	
  	
  	
  	
  	
  	
  	
  	
  {	
  .backend	
  	
  	
  	
  	
  	
  =	
  proxy4;	
  }}	
  
backend	
  proxy4_test_a_example_jp	
  {	
                        sub	
  vcl_error{	
  
	
  	
  .host	
  =	
  "10.2.1.27";	
                              	
  	
  	
  	
  	
  	
  	
  	
  if	
  (obj.status	
  ==	
  304)	
  {	
  
	
  	
  .port	
  =	
  "8803";	
                                   	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  return(deliver);}}	
  
	
  	
  .connect_timeout	
  =	
  30ms;}	
                         sub	
  vcl_fetch{	
  
backend	
  proxy4	
  {	
                                          	
  	
  	
  	
  	
  	
  	
  	
  unset	
  beresp.http.X-­‐Cache;	
  
	
  	
  .host	
  =	
  "10.2.1.27";	
                              	
  	
  	
  	
  	
  	
  	
  	
  unset	
  beresp.http.X-­‐Cache-­‐Lookup;	
  
	
  	
  .port	
  =	
  "80";	
                                     	
  	
  	
  	
  	
  	
  	
  	
  unset	
  beresp.http.Via;	
  
	
  	
  .connect_timeout	
  =	
  30ms;}	
                         	
  	
  	
  	
  	
  	
  	
  	
  unset	
  beresp.http.Server;}	
  
	
                                                                	
  
Config:	
  puppet	
  
"   $bport	
  =	
  [8801,8802,8803]	
  

"   $baccel	
  =	
  ["test-­‐a-­‐origin.example.jp",	
  
    "testk.example.jp",	
  "test-­‐a.example.jp”]	
  

"   $borigin	
  =	
  ["test-­‐a-­‐origin.example.jp",	
  
    "testk.example.jp",	
  "test-­‐a.example.jp”]	
  

"   $siblings	
  =	
  ["10.2.1.26",	
  "10.2.1.27"]	
  

"   $siblings_hosts	
  =	
  ["proxy5",	
  "proxy4"]	
  
Puppet!	
  
"               	
  

"   Cache Expire	
  

"                      	
  

"  
      Varnish 3                      	
  

tokyo.vcl発表資料(varnish+squid)

  • 1.
    Varnish Squid w/  puppet   @ar1  
  • 2.
    §  §  Debian     §  Amazon  Web  Services   ú  Solutions  Architect   ú 
  • 3.
    LoadBalance:   HighSpeed-­‐ LVS   Cache   HAProxy  
  • 4.
    ( )    
  • 5.
       
  • 6.
      !    
  • 7.
  • 8.
    Cache   Shareing   LoadBalance:   HighSpeed-­‐ Sibling   LVS   Cache   HAProxy  
  • 9.
    Request URI test-­‐a.example.jp     varnish cache   cache squid  
  • 10.
    squid cache   cache sibling   HTTPD  
  • 11.
    Config:  squid   [sibling.conf]  cache_peer  10.2.1.26  sibling  80  3130   [squid.conf]   http_port  8801  accel  defaultsite=test-­‐a-­‐origin.example.jp   cache_peer  test-­‐a-­‐origin.example.jp  parent  80  0  originserver  name=test-­‐a-­‐origin_example_jp   acl  test-­‐a-­‐origin_example_jp  dstdomain  test-­‐a-­‐origin.example.jp   http_access  allow  test-­‐a-­‐origin_example_jp   cache_peer_access  test-­‐a-­‐origin_example_jp  allow  test-­‐a-­‐origin_example_jp   cache_peer_access  test-­‐a-­‐origin_example_jp  deny  all   http_port  8802  accel  defaultsite=test-­‐k.example.jp   cache_peer  test-­‐k.example.jp  parent  80  0  originserver  name=test-­‐k_example_jp   acl  test-­‐k_example_jp  dstdomain  test-­‐k.example.jp   http_access  allow  test-­‐k_example_jp   cache_peer_access  test-­‐k_example_jp  allow  test-­‐k_example_jp   cache_peer_access  test-­‐k_example_jp  deny  all   http_port  8803  accel  defaultsite=test-­‐a.example.jp   cache_peer  test-­‐a.example.jp  parent  80  0  originserver  name=test-­‐a_example_jp   acl  test-­‐a_example_jp  dstdomain  test-­‐a.example.jp   http_access  allow  test-­‐a_example_jp   cache_peer_access  test-­‐a_example_jp  allow  test-­‐a_example_jp   cache_peer_access  test-­‐a_example_jp  deny  all    
  • 12.
    Config:  varnish   sub  vcl_recv  {   backend  proxy5_test_a_origin_example_jp  {                  if  (req.http.If-­‐Modified-­‐Since)  {      .host  =  "10.2.1.26";                                  error  304;      .port  =  "8801";                  }      .connect_timeout  =  30ms;                  if  (req.http.host  ==  "test-­‐a-­‐origin.example.jp"){   }                                  set  req.backend  =  test_a_origin_example_jp;                 backend  proxy5_test_k_example_jp  {                  }  elsif  (req.http.host  ==  "test-­‐k.example.jp"){      .host  =  "10.2.1.26";                                  set  req.backend  =  test_k_example_jp;      .port  =  "8802";        .connect_timeout  =  30ms;                  }  elsif  (req.http.host  ==  "test-­‐a.example.jp"){   }                                  set  req.backend  =  test_a_example_jp;                 backend  proxy5_test_a_example_jp  {                  }  else  {      .host  =  "10.2.1.26";                                  set  req.backend  =  default;      .port  =  "8803";                  }      .connect_timeout  =  30ms;   }   }      
  • 13.
    Config:  varnish(2)   backend  proxy5  {   director  test_a_origin_example_jp  round-­‐robin  {      .host  =  "10.2.1.26";                  {  .backend            =  proxy5_test_a_origin_example_jp;  }      .port  =  "80";                  {  .backend            =  proxy4_test_a_origin_example_jp;  }}      .connect_timeout  =  30ms;}   director  test_k_example_jp  round-­‐robin  {   backend  proxy4_test_a_origin_example_jp  {                  {  .backend            =  proxy5_test_k_example_jp;  }      .host  =  "10.2.1.27";                  {  .backend            =  proxy4_test_k_example_jp;  }}      .port  =  "8801";   director  test_a_example_jp  round-­‐robin  {      .connect_timeout  =  30ms;}                            {  .backend            =  proxy5_test_a_example_jp;  }   backend  proxy4_test_k_example_jp  {                  {  .backend            =  proxy4_test_a_example_jp;  }}      .host  =  "10.2.1.27";   director  default  round-­‐robin  {      .port  =  "8802";                  {  .backend            =  proxy5;  }      .connect_timeout  =  30ms;}                  {  .backend            =  proxy4;  }}   backend  proxy4_test_a_example_jp  {   sub  vcl_error{      .host  =  "10.2.1.27";                  if  (obj.status  ==  304)  {      .port  =  "8803";                                  return(deliver);}}      .connect_timeout  =  30ms;}   sub  vcl_fetch{   backend  proxy4  {                  unset  beresp.http.X-­‐Cache;      .host  =  "10.2.1.27";                  unset  beresp.http.X-­‐Cache-­‐Lookup;      .port  =  "80";                  unset  beresp.http.Via;      .connect_timeout  =  30ms;}                  unset  beresp.http.Server;}      
  • 15.
    Config:  puppet   "  $bport  =  [8801,8802,8803]   "   $baccel  =  ["test-­‐a-­‐origin.example.jp",   "testk.example.jp",  "test-­‐a.example.jp”]   "   $borigin  =  ["test-­‐a-­‐origin.example.jp",   "testk.example.jp",  "test-­‐a.example.jp”]   "   $siblings  =  ["10.2.1.26",  "10.2.1.27"]   "   $siblings_hosts  =  ["proxy5",  "proxy4"]  
  • 16.
    Puppet!   "     "   Cache Expire   "     "   Varnish 3