UPDATE (08 Dec 2010): a quicker and more maintainable way to install Varnish on Debian can be found on Varnish support pages here.
It basically consists on 4 steps:
-
curl http://repo.varnish-cache.org/debian/GPG-key.txt | apt-key add - -
echo "deb http://repo.varnish-cache.org/debian/ lenny varnish-2.1" >> /etc/apt/sources.list -
apt-get update -
apt-get install varnish
The following instructions are kept for information purpose.
However, a bug in Varnish 2.1.4 for Debian Lenny with Apache makes requests passing Varnish very slow and waiting for the maximum KeepAlive.
Set "KeepAlive Off" in Apache settings or follow the instructions below to install Varnish 2.1.3.
We had to install and set up Varnish on a Debian installation for one of our Drupal sites. Varnish is one of the favorite reverse proxy used within the Drupal community.
Combined with Pressflow, it helps optimizing server resources by providing a very efficient cache for anonymous users. The possibility of Varnish are extensive and a whole post is not enough to explain its possibilities so expect further posts to come.
Some of its advanced use includes load balancing, healthcheck of backends, ESI, url purge and a versatile configuration language VCL.
A very informative video about Varnish his the presentation of the product by one of the key contributor itself, Poul-Henning Kamp, to Drupalcon Copenhagen.
Let's start with the instructions!
1. Varnish installation
~$ cd /usr/local/src/
~$ sudo wget http://sourceforge.net/projects/varnish/files/varnish/2.1.3/varnish-2.1....
~$ sudo tar -zxvf varnish-2.1.3.tar.gz
~$ cd varnish-2.1.3
The following packages are required in order to install varnish monitoring toosl such as varnishhist, varnishtop, varnishstat...
~$ sudo apt-get install pkg-config
~$ sudo apt-get install libpcre3 libpcre3-dev
~$ sudo aptitude install libncurses5-dev
Then finally, run make and make instal:
~$ sudo ./configure --prefix=/usr/local --sysconfdir=/etc --localstatedir=/var/lib --mandir=/usr/share/man
~$ make && make install
Set up the new system user for varnish (you'll have to provide a password etc...):
~$ adduser varnish
Then run ldconfig to set up the symbolic links that are used to load shared libraries properly used by Varnish.
~$ ldconfig
Change the owner of the storage file directory to the new varnish user:
~$ chown -R varnish.varnish /var/lib/varnish/
Start up script.
I've reused the one provided in the latest Ubuntu release and they're compatible with 2.1.3. You can download it here.
~$ cd /etc/init.d
~$ wget http://www.all2e.com/content/download/389/2092/version/1/file/varnish
~$ chmod +x varnish
2. Varnish system configuration
Copy the default Varnish configuration file form the sources to your local default configuration directory.
~$ cp /usr/local/src/varnish-2.1.3/redhat/varnish.sysconfig /etc/default/varnish
Edit "/etc/default/varnish". In this case, Varnish is listening on port 80. We will update Apache configuration to have it listening on port 8080.
~$ vi /etc/default/varnish
DAEMON_OPTS="-a <127.0.0.1>:80 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-u varnish -g varnish \
-s file,/var/lib/varnish/varnish_storage.bin,1G
3. Setting up the Varnish configuration for Pressflow
In order to set up Varnish with Pressflow, you will have to edit /etc/varnish/default.vcl. Vcl is a set of syntax used to control the request done to Varnish. Thanks to Vcl, you can tweak an upcoming request, do several changes to it and let Varnish manage it.
Here’s an example on a simple Varnish configuration file, which can be used with Pressflow: download file here.
As you can see, the most important bit to connect Varnish and Apache is:
backend default {
.host = "127.0.0.1";
.port = "8080";
.connect_timeout = 600s;
.first_byte_timeout = 600s;
.between_bytes_timeout = 600s;
}
This tells Varnish to listen on port 8080 (Apache port in this example).
You can find more example on FourKitchens wiki with a lot of example of vcl tweaks. This is especially necessary if you have some modules which set sessions and may let the page not being cached.
4. Starting Varnish
Now we may test our setup for the first time:
~$ /etc/init.d/varnish start
Varnish will say if it has started correctly.
If you run in trouble here and varnish doesn't start it's always a good idea to take a look at the syslog file
~$ tail -f /var/log/syslog
5. Starting Varnish automatically on reboot
The following command will start varnish automatically on reboot:
~$ update-rc.d varnish defaults 40
6. Bibliography / Links
Varnish installation:
* Varnish installation and setup on ez publish based systems
* Setting up Varnish 2.0.6 on Debian Lenny
Pressflow / Varnish set-up:




Comments
Post new comment