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 (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 through the step-by-step installation of Varnish Cache on a CentOS server.
Why use Varnish?
- To reduce server load, especially CPU works.
- To make a website load faster, because cached and stored in RAM.
- 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
Configure Varnish config file (
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.