Two-Minute Tech Tuesdays - Installing Varnish on Debian and Ubuntu

In this week's 2 Minute Tech Tuesday, we'll be talking about installing Varnish on Debian and Ubuntu Linux systems.

 

 

We won't be just installing any version of Varnish, it will be a specific one: Varnish Cache 6.0 LTS. As the LTS indicates, it's the long-term supported and stable version of Varnish. It's still open source, but it's not maintained by the open-source community. It's maintained by us at Varnish Software, and we provide frequent bug fixes and also feature backports from the upstream versions.

 

How to install Varnish on Debian and Ubuntu

Installing Varnish on a Debian or Ubuntu Linux system will be done using the apt package manager. Before we can start installing, we need to make sure all the dependencies are in place.

  1. The first step is updating the package list with sudo apt-get update so we have the most recent information on all packages and package versions. Once we've done that, we can install a couple of software dependencies required for the installation procedure:
    sudo apt-get install debian-archive-keyring \
    curl gnupg apt-transport-https
  2. After that, we can use some of these dependencies to make preparations. In this case, we're loading the GPG key from the packagecloud.io repository into the package manager:
    curl -s -L https://packagecloud.io/varnishcache/varnish60lts/gpgkey | sudo  apt-key add -
  3. Next up, we need to source the /etc/os-release file to enable some of the operating system and distribution-related variables which we'll use in the next step. 
  4. And in this step, we'll use those variables to compose the location of the package repository, and that will be stored into a specific file that is loaded by the apt package manager. The variables that we use from the OS release file are ID and the distribution code name. That could be Ubuntu Focal on an Ubuntu system or Debian Buster on a Debian system:
    sudo tee /etc/apt/sources.list.d/varnishcache_varnish60lts.list > /dev/null <<-EOF
    deb https://packagecloud.io/varnishcache/
    varnish60lts/$ID/ $DISTRIB_CODENAME main
    EOF
  5. We also need to make sure that our version of the packages are prioritized over other packages that might be available in the operating system, and that might have a higher version number. This information is stored in a specific preferences file:
    sudo tee /etc/apt/preferences.d/varnishcache > /dev/null <<-EOF
    Package: varnish varnish-* hitch
    Pin: release o=packagecloud.io/varnishcache/*
    Pin-Priority: 1000
    EOF
  6. Once all this metadata is in place, we need to update the package list again with sudo apt-get update varnish, ensuring that our package repository is taken into account as well. And then we can install Varnish using sudo apt-get install varnish command. 

  7. Once Varnish is installed, we need to ensure that the service is enabled and survives any potential restarts, with sudo systemctl enable varnish. Then it's a matter of editing the service file using the system CTL edit commands and this will open up an editor and display the runtime information. The part of this information that is of particular interest to us is the varnishd command and its runtime parameters. We can edit those, for example ensuring that it listens on port 80 and that it has 2GB of memory instead of 256MB. 

  8. Save the service file, close the editor and run sudo systemctl restart varnish to restart Varnish and to finalize the entire install procedure.

Now you know how to install a supported and stable version of Varnish on Debian and Ubuntu Linux systems. Stay tuned for next week's episode where we'll do the same thing, but for CentOS and Red Hat Enterprise Linux systems.

varnish_6_by_example_download

Topics: varnish installation, installing Varnish on Ubuntu, how to install Varnish on Ubuntu, 2MTT

9/14/21 2:49 AM by Thijs Feryn

All things Varnish related

The Varnish blog is where the our team writes about all things related to Varnish Cache and Varnish Software...or simply vents.

SUBSCRIBE TO OUR BLOG

Recent Posts

Posts by Topic

see all