Two-Minute Tech Tuesdays - Installing Varnish on CentOS & Red Hat Enterprise Linux

 

In this week's 2 Minute Tech Tuesday, we'll be talking about installing Varnish on CentOS and Red Hat Enterprise Linux

 

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 CentOS and Red Hat Enterprise Linux

If you're planning to install Varnish on a CentOS 8 system or a Red Hat Enterprise Linux 8 system, run the following command to disable the local Varnish module:
sudo dnf module disable varnish
You will then source the etc os-release file, which will make some operating system related variables available:
. /etc/os-release

If you're using CentOS, install the epel-release package using the following command. It will make dependencies required by the Varnish installation, available.

sudo yum install epel-release

However, if you're using Red Hat Enterprise Linux, the epel-release package won't be available locally, so you'll need to fetch it from a remote RPM package of which the end point contains a version ID string. That represents the version of your operating system. If you're using Red Hat Enterprise Linux 8 or CentOS 8, this will be devalued.

sudo yum install https://dl.fedoraproject.org/pub/
epel/epel-release-latest-${VERSION_ID%%.*}.noarch.rpm

Now it's time to register the package repository. We do this by adding the following configuration to a specific repo file that is read by the yum package manager:

sudo tee /etc/yum.repos.d/
varnishcache_varnish60lts.repo > /dev/null <<-EOF
[varnishcache_varnish60lts]
name=varnishcache_varnish60lts
baseurl=https://packagecloud.io/varnishcache/
varnish60lts/el/${VERSION_ID%%.*}/$(arch)
repo_gpgcheck=0
gpgcheck=0
enabled=1
gpgkey=https://packagecloud.io/varnishcache/
varnish60lts/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300
EOF

It contains the URL of our package repository, which has some variables that need to be parsed. In the example above, a 64 bit x86 system running on Enterprise Linux 8 would be the string.

Once we have the location of our package repository in order, and the yum package manager is aware of that, it's simply a matter of calling yum install varnish to install Varnish, with all it's dependencies.

sudo yum install varnish

Even though we've installed Varnish, our work is not done yet. We need to enable the system V service for Varnish. This will ensure Varnish automatically gets restarted after a server reboot.

sudo systemctl install varnish

After enabling the system V service for Varnish, we now have to edit it:

sudo systemctl edit --full varnish

An editor will open and present us with full service including varnishd runtime parameters. We do this because we want to modify some of these parameters:

ExecStart=/usr/sbin/varnishd \
-a :80 \
-a localhost:8443,PROXY \
-p feature=+http2 \
-s malloc,29

We want to change the listening port from 6081 to 80, and we want to upgrade the allocated memory from 256 megabytes to 2 gigabytes.

After performing these changes, save the file, exit the editor and your configuration is set. The only thing we need to do is sudo systemctl restart varnish.

sudo systemctl restart varnish

Now you know how to install a supported and stable version of Varnish on CentOS and Red Hat Enterprise Linux systems. Stay tuned for next week's episode where we'll dive into Varnish Cloud.

varnish_6_by_example_download

Topics: varnish installation, 2MTT, installing varnish on Red Hat Enterprise Linux, installing varnish on centOS

9/21/21 3:58 PM 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