Building a Varnish VMOD on Debian

From the tutorials department, here are some quick notes on how to install a Varnish VMOD from source.

This is slightly complicated because Varnish demands that a VMOD must be built against the same git commit (or release) as the one that is running. This will be relaxed in future versions.

Current setup is a standalone Varnish VM on Debian Wheezy with Varnish installed from varnish package archives (3.0.4-1~wheezy.)

1. Get the vmod

lkarsten@lb1:~$ git clone https://github.com/lkarsten/libvmod-cookie.git
Cloning into 'libvmod-cookie'...
remote: Counting objects: 253, done.
remote: Compressing objects: 100% (131/131), done.
remote: Total 253 (delta 132), reused 232 (delta 112)
Receiving objects: 100% (253/253), 49.51 KiB, done.
Resolving deltas: 100% (132/132), done.
lkarsten@lb1:~$

2. Get and configure the source tree for the running Varnish

Verify first that you have the necessary package repositories enabled:

lkarsten@lb1:~$ grep varnish /etc/apt/sources.list
deb http://repo.varnish-cache.org/debian/ wheezy varnish-3.0
deb-src http://repo.varnish-cache.org/debian/ wheezy varnish-3.0
lkarsten@lb1:~$

After that, continue with the juicy parts:

lkarsten@lb1:~$ apt-get source varnish 
Reading package lists... Done 
Building dependency tree 
Reading state information... Done 
NOTICE: 'varnish' packaging is maintained in the 'Git' version control system at: 
git://git.debian.org/pkg-varnish/pkg-varnish.git 
Need to get 2,060 kB of source archives. 
Get:1 http://repo.varnish-cache.org/debian/ wheezy/varnish-3.0 varnish 3.0.4-1 (dsc) [2,334 B] 
Get:2 http://repo.varnish-cache.org/debian/ wheezy/varnish-3.0 varnish 3.0.4-1 (tar) [2,044 kB] 
Get:3 http://repo.varnish-cache.org/debian/ wheezy/varnish-3.0 varnish 3.0.4-1 (diff) [14.1 kB] 
Fetched 2,060 kB in 0s (11.4 MB/s) 
gpgv: keyblock resource `/home/lkarsten/.gnupg/trustedkeys.gpg': file open error 
gpgv: Signature made Fri 14 Jun 2013 11:56:48 CEST using RSA key ID 87218D9C 
gpgv: Can't check signature: public key not found 
dpkg-source: warning: failed to verify signature on ./varnish_3.0.4-1.dsc 
dpkg-source: info: extracting varnish in varnish-3.0.4 
dpkg-source: info: unpacking varnish_3.0.4.orig.tar.gz 
dpkg-source: info: applying varnish_3.0.4-1.diff.gz 
lkarsten@lb1:~$
lkarsten@lb1:~$ cd varnish-3.0.4
lkarsten@lb1:~/varnish-3.0.4$ ./autogen.sh
[..]
lkarsten@lb1:~/varnish-3.0.4$ ./configure --prefix=/usr
[..]
lkarsten@lb1:~/varnish-3.0.4$ make

If configure or make fails, you might need some additional packages. Run an apt-get build-dep varnish and work from there. (if editline fails on you, remember to rerun configure after installing it)

3. Build and install the vmod

lkarsten@lb1:~$ cd libvmod-cookie/
lkarsten@lb1:~/libvmod-cookie$ ./autogen.sh
+ aclocal -I m4
+ libtoolize --copy --force
libtoolize: putting auxiliary files in `.'.
libtoolize: copying file `./ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4'.
libtoolize: copying file `m4/libtool.m4'
libtoolize: copying file `m4/ltoptions.m4'
libtoolize: copying file `m4/ltsugar.m4'
libtoolize: copying file `m4/ltversion.m4'
libtoolize: copying file `m4/lt~obsolete.m4'
+ autoheader
+ automake --add-missing --copy --foreign
configure.ac:8: installing `./config.guess'
configure.ac:8: installing `./config.sub'
configure.ac:11: installing `./install-sh'
configure.ac:11: installing `./missing'
src/Makefile.am: installing `./depcomp'
+ autoconf
lkarsten@lb1:~/libvmod-cookie$ 
lkarsten@lb1:~/libvmod-cookie$ ./configure VARNISHSRC=~/varnish-3.0.4/
[..]
# and finally
lkarsten@lb1:~/libvmod-cookie$ make
[..]
libtool: link: ( cd ".libs" && rm -f "libvmod_cookie.la" && ln -s "../libvmod_cookie.la" "libvmod_cookie.la" )
make[2]: Leaving directory `/home/lkarsten/libvmod-cookie/src'
make[2]: Entering directory `/home/lkarsten/libvmod-cookie'
rst2man README.rst vmod_cookie.3
make[2]: Leaving directory `/home/lkarsten/libvmod-cookie'
make[1]: Leaving directory `/home/lkarsten/libvmod-cookie'
lkarsten@lb1:~/libvmod-cookie$ 
lkarsten@lb1:~/libvmod-cookie$ sudo make install
[..]
/bin/mkdir -p '/usr/local/share/man/man3'
 /usr/bin/install -c -m 644 vmod_cookie.3 '/usr/local/share/man/man3'
make[2]: Leaving directory `/home/lkarsten/libvmod-cookie'
make[1]: Leaving directory `/home/lkarsten/libvmod-cookie'
lkarsten@lb1:~/libvmod-cookie$

At this point you should have the two vmod files available for Varnish:

lkarsten@lb1:~/libvmod-cookie$ ls -l /usr/lib/varnish/vmods/
total 64
-rwxr-xr-x 1 root root 966 Jul 29 11:11 libvmod_cookie.la
-rwxr-xr-x 1 root root 41538 Jul 29 11:11 libvmod_cookie.so
-rw-r--r-- 1 root root 16128 Jun 17 13:38 libvmod_std.so
lkarsten@lb1:~/libvmod-cookie$

And you are done!

“import cookie” should now work without issue in your /etc/varnish/default.vcl.

Advertisement
This entry was posted in stuff and tagged , , , , . Bookmark the permalink.

7 Responses to Building a Varnish VMOD on Debian

  1. Pingback: Building a Varnish VMOD on Debian | Debian-News.net - Your one stop for news about Debian

  2. Pingback: Building a Varnish VMOD on Debian - Debian Info

  3. Matt Collier says:

    Thank you very much for your tutorial. I did encounter a problem compiling a different VMOD. I have documented my findings here: http://resilientresonance.com/content/installing-variable-support-vmod-varnish-cache Some of your readers might find this information helpful.

    • Martin Blix Grydeland says:

      On Debian one should make sure that the libvarnishapi-dev package is installed before starting this howto. That will ensure that the pkgconfig file is present and one will not encounter the vmod directory problems that Matt describes.

      Martin

  4. Andreas Dobrick says:

    Can anybody provide help in getting vmod cookie and memcached varnish 4 ready? I changed the include file to cache/cache.h and changed the include in makefile.am.

    I still get same error:
    configure: error: in `/usr/src/varnish-4-vmod/libvmod-cookie’:
    configure: error: “/usr/src/varnish-4-vmod/varnish-4.0.1” is not a Varnish source directory

    Thanks in advance for your help.

    • Hi Andreas.

      At least for the cookie vmod, that has been ported to 4.0. Are you using the master or the 3.0 branch? The 4.0 stuff is in master.

      -Lasse

      • Andreas Dobrick says:

        Hi Lasse.

        Thanks for your quite fast reply. Your are right.

        Any idea why my build (make) is failing? It seems tehre is an issue with config in src/vmod_cookie.vcc:


        make all-recursive
        make[1]: Entering directory ‘/usr/src/varnish-4-vmod/libvmod-cookie’
        Making all in src
        make[2]: Entering directory ‘/usr/src/varnish-4-vmod/libvmod-cookie/src’
        ../src/vmod_cookie.vcc
        ../src/vmod_cookie.vcc: Zeile 1: cookie: Kommando nicht gefunden. (command not found)
        ../src/vmod_cookie.vcc: Zeile 2: init_function: Kommando nicht gefunden. (command not found)
        ../src/vmod_cookie.vcc: Zeile 3: Syntaxfehler beim unerwarteten Wort `(‘
        ../src/vmod_cookie.vcc: Zeile 3: `$Function VOID parse(STRING)’
        Makefile:661: recipe for target ‘vcc_if.c’ failed
        make[2]: *** [vcc_if.c] Error 2
        make[2]: Leaving directory ‘/usr/src/varnish-4-vmod/libvmod-cookie/src’
        Makefile:498: recipe for target ‘all-recursive’ failed
        make[1]: *** [all-recursive] Error 1
        make[1]: Leaving directory ‘/usr/src/varnish-4-vmod/libvmod-cookie’
        Makefile:365: recipe for target ‘all’ failed
        make: *** [all] Error 2

        Thank you for you help.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s