Varnish
What is a reverse proxy?            Forward Proxy                                            Reverse Proxyhttp://en.wikipe...
Install Varnish    curl http://repo.varnish-cache.org/debian/GPG-key.txt | apt-key add -    echo "deb http://repo.varnish-...
Concept of Backend Servers# /etc/varnish/default.vcl   Backend Servers provide thebackend default {            content to ...
Start Varnish       varnishd -F -f /etc/varnish/default.vcl -a 0.0.0.0:8080-F     Run in the foregroud-f /etc/varnish/defa...
VCLVarnish Configuration LanguageUsed to configure how varnish handles requestsCan be used to manipulate headers
How Varnish knows what to cache?Varnish will not cache:  An object coming from the backend server with a Set-Cookieheader....
Purging the cache# /etc/varnish/default.vclacl purge {                            Simple script that will allow only   "lo...
Not just a HTTP Accelerator  Varnish can be setup as a load balancer to distribute therequests across multiple servers
Multiple Backends# /etc/varnish/default.vcl   You can define as many backendsbackend server01 {           as needed   .hos...
Directors# /etc/varnish/default.vcl       Directors are groups ofdirector default round-robin {   backends   {      .backe...
Health Checks# /etc/varnish/varnish.   urlvcl                          URL to checkbackend server01 {        interval   .h...
High Availability● Grace Mode   ○ Instructs Varnish to keep objects past TTL● Saint Mode   ○ Try another server or serve s...
Grace Mode Example# /etc/varnish/default.vcl       set beresp.gracesub vcl_fetch {                    Instructs Varnish to...
Saint Mode Example# /etc/varnish/default.vcl           set beresp.saintmodesub vcl_fetch {                        How long...
Questions?Documentation TOChttps://www.varnish-cache.org/docs/3.0/index.htmlReference Manualhttps://www.varnish-cache.org/...
Upcoming SlideShare
Loading in …5
×

Varnish

3,399 views
3,345 views

Published on

Published in: Education, Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,399
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
29
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Varnish

  1. 1. Varnish
  2. 2. What is a reverse proxy? Forward Proxy Reverse Proxyhttp://en.wikipedia.org/wiki/Proxy_server
  3. 3. Install Varnish curl http://repo.varnish-cache.org/debian/GPG-key.txt | apt-key add - echo "deb http://repo.varnish-cache.org/ubuntu/ $(lsb_release -s -c) varnish-3.0" >> /etc/apt/sources.list apt-get update apt-get install varnishhttps://www.varnish-cache.org/installation/ubuntu
  4. 4. Concept of Backend Servers# /etc/varnish/default.vcl Backend Servers provide thebackend default { content to varnish .host = "127.0.0.1" .port = "80"}
  5. 5. Start Varnish varnishd -F -f /etc/varnish/default.vcl -a 0.0.0.0:8080-F Run in the foregroud-f /etc/varnish/default.vcl Use our default config file-a 0.0.0.0:8080 Listen for requests on port 8080
  6. 6. VCLVarnish Configuration LanguageUsed to configure how varnish handles requestsCan be used to manipulate headers
  7. 7. How Varnish knows what to cache?Varnish will not cache: An object coming from the backend server with a Set-Cookieheader. A request coming from the client with a cookie header
  8. 8. Purging the cache# /etc/varnish/default.vclacl purge { Simple script that will allow only "localhost"; requests from localhost to purge the}sub vcl_recv { cache if (req.request == "PURGE") { if (!client.ip ~ purge) { error 405 "Not allowed."; PURGE is a request method, just like } return (lookup); GET or POST }}sub vcl_hit { if (req.request == "PURGE") { purge; error 200 "Purged."; }}sub vcl_miss { if (req.request == "PURGE") { purge; error 200 "Purged."; }}
  9. 9. Not just a HTTP Accelerator Varnish can be setup as a load balancer to distribute therequests across multiple servers
  10. 10. Multiple Backends# /etc/varnish/default.vcl You can define as many backendsbackend server01 { as needed .host = "127.0.0.1"; .port = "8080"; Each can be different hosts and} different portsbackend server02 { .host = "127.0.0.1"; .port = "8080";}
  11. 11. Directors# /etc/varnish/default.vcl Directors are groups ofdirector default round-robin { backends { .backend = "server01"; } { .backend = "server02"; }}
  12. 12. Health Checks# /etc/varnish/varnish. urlvcl URL to checkbackend server01 { interval .host = "127.0.0.1"; Poll every X .port = "8080"; timeout .probe { Timeout after X .url = "/"; window .interval = 5s; The past X requests .timeout = 1s; threshold .window = 5; How many good probes .threshold = 3; }}
  13. 13. High Availability● Grace Mode ○ Instructs Varnish to keep objects past TTL● Saint Mode ○ Try another server or serve stale content● God Mode ○ Not yet implemented
  14. 14. Grace Mode Example# /etc/varnish/default.vcl set beresp.gracesub vcl_fetch { Instructs Varnish to store set beresp.grace = 30m; objects for n minutes}sub vcl_recv { set req.grace if (!req.backend.healthy) { Instructs Varnish to serve set req.grace = 5m; objects that are n seconds old } else { set req.grace = 15s; }}
  15. 15. Saint Mode Example# /etc/varnish/default.vcl set beresp.saintmodesub vcl_fetch { How long before if (beresp.status == 500) { Varnish can ask that set beresp.saintmode = 10s; server for the URL again. restart; } set beresp.grace set beresp.grace = 5m; Instructs Varnish to} store objects for n minutes
  16. 16. Questions?Documentation TOChttps://www.varnish-cache.org/docs/3.0/index.htmlReference Manualhttps://www.varnish-cache.org/docs/3.0/reference/index.htmlRandom Outburstshttps://www.varnish-cache.org/docs/3.0/phk/index.html

×