Varnish Cache is a, as the name says, a (open source) software which caches content. It serves as a reverse proxy server in front of your real web server, caching all or a defined set of URLs (using a so-called VCL configuration file) in memory. This relieves the backend web server(s) as they get less traffic and as the content is loaded from memory (RAM), the web site loads faster, too.
Differences in Varnish products
If you are new to Varnish, this might be somewhat confusing – that's why we start off with the differences in Varnish products. There are actually two different Varnish products available. Some documentation mentions the one, other docs mention the other.
Varnish Cache is the "original" and open source software. The official website is varnish-cache.org where you'll find downloads, release notes and documentation. Although Varnish Cache is very stable (in most scenarios anyway), it serves as "development upstream" for the commercial Varnish Plus.
Varnish Plus (or Varnish Enterprise)
Varnish Plus, sometimes also mentioned as Varnish Enterprise, is the commercial edition of Varnish Cache. It comes with support from Varnish Software, the company behind Varnish. Additionally to Varnish Cache, Varnish Plus also allows the usage of TLS certificates (Varnish Cache only runs in HTTP mode). Certain modules, called VMODs, are only built for Varnish Plus.
Understanding Varnish's version numbering
Something else, which might be confusing to new Varnish users, is the way the releases are handled. The newest release might not always be the release you'd want to go for. Sounds confusing? Gotcha!
Bleeding edge (development)
In fact the newest releases – as of this writing this is 6.5.1 – are the current development branches of Varnish. They can be understood as bleeding edge releases where new features are implemented. The problem is that these versions are soon to expire and are tagged EOL (end of life). When this happens, you won't get any security updates nor bug fixes anymore. In this case you need to check the Varnish Cache release notes on a regular basis and adjust your package source to use the next version (which will most likely be 6.6.x).
Long term support (LTS)
If you want the most stable version of Varnish Cache, use the LTS version of it. As of this date in February 2021, the current LTS version of Varnish Cache is 6.0.x. New features from the bleeding edge versions are mostly missing, however security and bug fixes discovered in the newer versions are backported into the LTS version.
Installation of Varnish Cache
When using a Debian or Ubuntu Linux, Varnish is already part of the "official" repositories. That's an interesting fact, because the chosen versions are the development/bleeding edge versions.
The upcoming Debian 11 (Bullseye) will likely come with Varnish 6.5.1 . The current Ubuntu LTS version 20.04 installs Varnish 6.2.1. If you are installing either of these two Linux distributions, you usually do this for stability and long term support. One would expect that Varnish's LTS version is packaged there, but that's not the case. That's why you should install Varnish Cache from a separate APT repository.
Installation of Varnish Cache is recommended from the varnishcache repositories on packagecloud.
Installation using APT package manager
Debian-based Linux distributions (Ubuntu is the most famous one) use APT as package manager. Use the following steps to add the varnishcache repository:
$ sudo apt-get update $ sudo apt-get install debian-archive-keyring # for Debian only $ sudo apt-get install curl gnupg apt-transport-https $ curl -L https://packagecloud.io/varnishcache/varnish60lts/gpgkey | sudo apt-key add - $ echo "deb https://packagecloud.io/varnishcache/varnish60lts/ubuntu/ focal main" | sudo tee -a /etc/apt/sources.list.d/varnishcache.list
Make sure you are using the correct release! In the above example Ubuntu focal was used. Refer to the documentation which distributions and versions are supported.
Because both Debian and Ubuntu feature a higher version number of the varnish package, apt needs to be told to use a higher priority on the packagecloud repository. Create /etc/apt/preferences.d/varnish with the following content:
Package: varnish Pin: origin packagecloud.io Pin-Priority: 900
You can now update apt and install the varnish package:
$ sudo apt-get update $ sudo apt-get install varnish
Installation using yum and zypper repositories
For installation on RHEL or CentOS (and other derivatives) using the yum package manager, follow the rpm installation instructions. For SUSE distributions using the zypper package manager, use the zypper installation instructions.
Enable and start Varnish
In a fairly recent Linux distribution, Systemd is most likely the installed init system. After the installation, enable Varnish service and then start Varnish:
$ sudo systemctl enable varnish $ sudo systemctl start varnish
Varnish should now be started with (basic) default settings. The following processes should be running:
varnish 988 0.0 0.0 18916 4288 ? SLs 10:09 0:00 /usr/sbin/varnishd -a :6081 -a localhost:8443,PROXY -p feature=+http2 -f /etc/varnish/default.vcl -s malloc,256m vcache 1000 0.0 0.6 286448 103584 ? SLl 10:09 0:00 \_ /usr/sbin/varnishd -a :6081 -a localhost:8443,PROXY -p feature=+http2 -f /etc/varnish/default.vcl -s malloc,256m
The process launched by varnish (PID 988) is the master process. Child processes with owner vcache are worker processes handling the incoming traffic.
In this example, using the default settings, Varnish Cache is listening on tcp/6081 for HTTP traffic and is using a 256MB memory allocated cache.
Next: How to implement Varnish Cache
You have made it to the end of this article. Thank you for this. You followed the introduction and installation steps and you should have a running Varnish Cache now. The next follow up article will describe how to implement Varnish Cache in front of a web server.