Varnish is an HTTP accelerator. That means it speeds up the server when there is a high traffic on a particular site. It functions between Client and Sever.
How it works?
Varnish is tool that takes the visitors to the static pages when they do not need any processing work. That means it diverts the non processing load to the static pages and keep the processing load with it. By which it reduces the laod on a server and make the processing of a particular task faster than before. Varnish directly act on the HTTP request so server load reduces to a minimum.
Before installing Varnish you have to understand it.
I am going to make you understand it as easy as possible. Varnish is a software component that stores files or fragmented files in memory by which it reduces the response time of same requests and also helps in reducing consumption of bandwidth of network. It directly works on HTTP requests. So you can understand how suitable it is for a heavy traffic control and speeding up the server response time.
It works between client and server. When there is a huge number of traffic requesting several pages and elements Varnish sits on the server filters the requests. If a request need the server processing it sends it to the server and if a request does not need processing it directs it to the static pages of the server. When the server responds to the requests the Varnish stores the cachable responses and it fetches it for subsequent request by which the server does not have to process the same request again and again. Thus reducing the processing time and work load on server it makes the site faster in server response.
Installing Varnish for Magento 2:
Magento 2 supoports Varnish 5.2 version. So you have to ensure that you are installing it.
I suppose you already have LAMP installed.
Now go to Varnish official site to download it https://varnish-cache.org/.
To start with Varnish you to put this command
$ sudo apt-get update
$ sudo apt-get install varnish
Follow the manual installation process as suggested here:
Now configuring Magento 2 with Varnish:
a) Login to your Magento admin
b) Click STORES> Configuration > ADVANCED > System > Full page cache
c) You will get a Caching Application list, now click on Varnish Caching
d) Enter the value in TTL for public content
e) Enter the values in following fields>
Access list: Put the host name, IP address.
Back end host: This your actual server. Put the host name, IP address and get the port of Varnish.
Back end port: This is the port of your actual server or original server.
f) Now click on Save Configuration
You are done with Varnish configuration.