CentOSLinuxTutorials

How To Install Varnish Cache on CentOS

Install Varnish Cache on CentOS

In this tutorial, we will show you how to install Varnish Cache on CentOS. For those of you who didn’t know, Varnish is an open-source reverse HTTP proxy, an HTTP accelerator, and a useful tool for speeding up an Apache server. The varnish is also known as front-end web caching software that you put in front of an Apache webserver to speed it up. It makes your website really fast and accelerates your website performance up to 300 – 1000x (which means 80% or more).

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of Varnish Cache on a CentOS server.

Prerequisites

  • A server running one of the following operating systems: CentOS Linux.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Why use Varnish?

  1. To reduce server load, especially CPU works.
  2. To make a website load faster, cached and stored in RAM.
  3. To gain more visitors to your website.

Install Varnish Cache on CentOS

Step 1. To install, first, you must add the varnish yum repository information corresponding to your CentOS/RHEL version to yum:

For CentOS 5.x use:

rpm --nosignature -i http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release-3.0-1.noarch.rpm

For CentOS 6.x use:

rpm --nosignature -i http://repo.varnish-cache.org/redhat/varnish-3.0/el6/noarch/varnish-release-3.0-1.el6.noarch.rpm

Step 2. Type the following command to install Varnish.

yum install varnish

 Step 3. To start Varnish for the first time, type the following command.

service varnish start

 To start Varnish at system start-up, type the following command to make it start at system boots.

chkconfig --level 345 varnish on

Configure Varnish Cache 3.0

Con­fig­ure Var­nish con­fig file (/etc/varnish/default.vcl.)

Commands for Monitoring Varnish Cache

Following are some useful and helpful Varnish Cache commands for monitoring.

# varnishstat : Show varnish statistics.
# varnishlog : Show varnish logs.
# varnishtop : It reads varnishd shared memory logs and presents a most commonly occurring log entries.
# varnishadm : Clear all varnish cache.

Congratulations! You have successfully installed Varnish. Thanks for using this tutorial for installing Varnish Cache on your CentOS system. For additional help or useful information, we recommend you check the official Varnish website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

Save

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button