Setting up Varnish

Install

curl -s https://packagecloud.io/install/repositories/varnishcache/varnish70/script.deb.sh | bash
cat /etc/apt/sources.list.d/varnishcache_varnish70.list
apt install varnish

Setup

dd if=/dev/random of=/etc/varnish/secret bs=512 count=1
chmod 400 /etc/varnish/secret

here the admin interface listens only locally

cp -i /lib/systemd/system/varnish.service /etc/systemd/system/
vi /etc/systemd/system/varnish.service

ExecStart=/usr/sbin/varnishd \
    -a :80 \
    -T localhost:6082 \
    -S /etc/varnish/secret \
    -p feature=+http2 \
    -f /etc/varnish/default.vcl \
    -s default,3G

systemctl daemon-reload

no need for localhost:8443,PROXY unless you do Hitch

Good grace cache

mv -i /etc/varnish/default.vcl /etc/varnish/default.vcl.dist
    grep -vE '^[[:space:]]*#|^$' default.vcl.dist > /etc/varnish/default.vcl.clean
    grep -vE '^[[:space:]]*#|^$' default.vcl.dist > /etc/varnish/default.vcl
vi /etc/varnish/default.vcl
#vi /etc/varnish/goodgrace.vcl

vcl 4.1;

backend default {
    .host = "BACKEND-SERVER";
    .port = "80";
}

sub vcl_req_cookie {
    return;
}

sub vcl_recv {
}

sub vcl_backend_response {
    set beresp.grace = 2m;
    set beresp.keep = 8m;
}

sub vcl_deliver {
}

Ready to go

varnishd -C -f /etc/varnish/default.vcl >/dev/null 2>&1 && echo config ok

systemctl restart varnish
systemctl status varnish # enabled?
netstat -lntup | grep varnish

Acceptance

locally

curl -I localhost

and remotely

curl -I https://SOME-WEB-SITE/

memory usage should grow (last column)

    top -b -n1 | grep varnishd

TODO

Advanced usage

draft

    varnishadm

    param.show
    ban.list

    varnishtop -b -i TxURL
    varnishtop -i RxURL

    varnishncsa -F '%U%q %{Varnish:hitmiss}x' -n NAME -w requests.log

    varnishstat

Resources

install/setup

Introduction and how to install Varnish Cache on Linux https://www.geekersdigest.com/introduction-and-how-to-install-varnish-cache-on-linux/

varnishcache’s repos https://packagecloud.io/varnishcache/

Installing and configuring Varnish¶ https://www.varnish-software.com/wiki/content/tutorials/varnish/varnish_ubuntu.html

INSTALL AND TEST VARNISH IN 5 STEPS https://info.varnish-software.com/blog/install-and-test-varnish-in-5-steps

https://code.uplex.de/varnishcache/pkg-varnish-cache/commit/27ab9fbb7d2c33030d3a342cf58f01d02a2a8a45

vcl syntax

https://book.varnish-software.com/3.0/VCL_Basics.html

https://stackoverflow.com/questions/20718681/how-to-stop-varnish-from-caching-sitemap –> return pass

advanced

Hghly Available Caching Cluster with Varnish and HAProxy in AWS https://icicimov.github.io/blog/server/Hghly-Available-Caching-Cluster-with-Varnish-and-HAProxy-in-AWS/

acceptance

https://www.getpagespeed.com/server-setup/varnish/cache-status-check

storage

https://info.varnish-software.com/blog/understanding-varnish-cache-memory-usage

https://serverfault.com/questions/130185/store-varnish-cache-in-hard-disk

http://varnish-cache.org/docs/trunk/phk/notes.html

hit & miss

https://docs.varnish-software.com/tutorials/hit-miss-logging/


HOME | GUIDES | LECTURES | LAB | SMTP HEALTH | HTML5 | CONTACT
Copyright © 2024 Pierre-Philipp Braun