linux poison RSS
linux poison Email

Speed up web site using HTTP accelerator - Varnish

Varnish is a state-of-the-art, high-performance web accelerator. It uses the advanced features in Linux 2.6, FreeBSD 6/7 and Solaris 10 to achieve its high performance.

Some of the Varnish features include:
  * A modern design
  * VCL - a very flexible configuration language
  * Load balancing with health checking of backends
  * Partial support for ESI
  * URL rewriting
  * Graceful handling of “dead” back-ends

Varnish Installation:
To use the varnish repository under Ubuntu Linux, open up the terminal and type following commands
curl http://repo.varnish-cache.org/debian/GPG-key.txt | apt-key add -
echo "deb http://repo.varnish-cache.org/debian/ $(lsb_release -s -c) varnish-2.1" >> /etc/apt/sources.list
apt-get update
apt-get install varnish
Varnish Configuration:
Varnish has a concept of “backend” or “origin” servers. A backend server is the server providing the content Varnish will accelerate.

First task is to tell Varnish where it can find its content. Start your favorite text editor and open the varnish default configuration file (/etc/varnish/default.vcl).

Somewhere in the top there will be a section that looks a bit like this.:

backend default {
     .host = "127.0.0.1";
     .port = "8080";
}

Varnish can have several backends defined and can you can even join several backends together into clusters of backends for load balancing purposes.

Now, you also need to setup your web-server to listen on port '8080' and restart your web server.
Finally, you also need to start your varnish server using command ..

varnishd -a :80 -b localhost:8080 -T localhost:8090 -s file,/var/lib/varnish/poison/vanish.cache,2G
-a :80 defines the port for Varnish to run on.
-b localhost:8080 defines the port and host of the webserver you want to cache
-T localhost:8090 defines the port and host for the Varnish terminal to run in
-s file,/var/lib/varnish/poison/vanish.cache,4G defines the cache file, and the size limit.


Above is very simple varnish setup, check out the varnish documentation for more detail and complex setup.


2 comments:

Post a Comment

Related Posts with Thumbnails