Implementation of the CachingService with Varnish.

Installation & Configuration de Varnish

This documentation is mostly outdated. Varnish is now managed through Puppet and the configuration there is the reference.

Installation de Varnish

The version of Varnish which is currently packaged in Debian Stable is 1.0.2. This package currently has a few known errors. For a production site it is therefore currently recommended to build Varnish manually from source instead. For a full list of the known issues for the Debian package, refer to the Debian bugtracker (http://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=varnish;dist=stable).

On créera donc notre propre package à partir des sources. J'ai pris le backport uploadé sur backports.org pour recompiler une version amd64, sur builder.koumbit.net.

Voici la configuration déployée par Puppet dans /etc/default/varnish:

DAEMON_OPTS="-a :80 \
              -f /etc/varnish/puppet.vcl \
              -s file,/var/lib/varnish/$INSTANCE/varnish_storage.bin,1G"

Le fichier /etc/varnish/puppet.vcl va varier selon les frontends, mais pour l'instant il est commun à tous les cache potentiels:

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

backend example {
        set backend.host = "example.koumbit.net";
        set backend.port = "80";
}

sub vcl_recv {
        if (req.http.host ~ "^(.*\.)?example.net$") {
                set req.backend = example;
        }
}

See VarnishMaintenance for more complete configuration examples.

Basic DNS configuration

/etc/bind/db.209.44.112

78 IN PTR cache.koumbit.net. ; cache web (varnish)

/var/alternc/bind/zones/koumbit.net

cache IN A 209.44.112.78

Other configuration examples

More configuration snippets are in the VarnishMaintenance page as they are regularly modified and tweaked depending on the requirements of the site.

Systemd

Starting from jessie, debian uses systemd. This means that /etc/default/varnish is not read anymore, and any daemon options passed to the init script through there previously are now not effective anymore. This can mean that varnish will not bind to any IP, and use the default of 256Mb of cache instead of your setting.

In order to fix this, we copied /lib/systemd/system/varnish.service to /etc/systemd/system/varnish.service and then edited it in order to override the ExecStart line and add the arguments that were set in $DAEMON_OPTS in /etc/default/varnish (don't forget to extrapolate $INSTANCE because systemd won't do it for you).

This was somewhat documented in the debian wiki but that documentation was wrong. Also, since our solution feels like the wrong approach, we didn't modify that wiki page.

Performance tuning

Varnish is very robust. But the bigger you scale the traffic it handles, the more it needs some fine-tuning.

This page informs about some recommendations from the varnish project itself: https://www.varnish-cache.org/trac/wiki/Performance

Most notably:

References


CategoryConfiguration

VarnishConfiguration (last edited 2019-12-02 16:21:22 by kienan)