Step1: download the source code
[[email protected] ~]# git clone https://github.com/varnishcache/varnish-cache
Step2: install
[[email Protected] ~]# cd varnish-cache/
[[email Protected] varnish-cache]# sh autogen.sh
[[ emailprotected] varnish-cache]#sh configure
[[emailprotected] varnish-cache]# make
[[emailprotected] varnish-cache]# make install
Step3: Modify the configuration file
[[emailprotected] varnish-cache]# cp /usr/local/varnish/share/doc/varnish/example.vcl /usr/local/varnish/ default.vcl
[[email protected] varnish-cache]# vi /usr/local/varnish/default.vcl
backend default {
.host = “10.10. 1.10”; #Modify the back-end server IP and port
.port = “80”;
}
Step4: Start the service
[[emailprotected] varnish- cache]# /usr/local/sbin/varnishd -f /usr/local/varnish/default.vcl
Debug: Version: varnish-trunk revision d32906f86aeee1fe462ced9897a31c6d40110ea8
Debug: Platform: Linux,3.10.0-957. el7.x86_64,x86_64,-jnone,-sdefault,-sdefault,-hcritbit
Debug : Child (27715) Started
[[emailprotected] varnish-cache]#
Step5: View log
[[emailprotected] varnish-cache]# /usr/ local/bin/varnishlog
* << Request >> 32774
– Begin req 32773 rxreq
– Timestamp Start: 1570369307.901920 0.000000 0.000000
– Timestamp Req: 1570369307.901920 0.000000 0.000000
– VCL_use boot< br>– ReqStart 10.10.1.1 52299 a0
– ReqMethod GET
– ReqURL /index.php/archives/3/
– ReqProtocol HTTP/1.1
– ReqHeader Host: 10.10.1.110
-ReqHeader Connection: keep-alive
– ReqHeader Upgrade-Insecure-Requests: 1
– ReqHeader User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome /77.0.3865.90 Safari/537.36
– ReqHeader Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/ signed-exchange;v=b3
– ReqHeader Referer: http://10.10.1.110/index.php/archives/3/
– ReqHeader Accept-Encoding: gzip, deflate
– ReqHeader Accept-Language : zh-CN,zh;q=0 .9
– ReqHeader X-Forwarded-For: 10.10.1.1
– VCL_call RECV
– ReqUnset Host: 10.10.1.110
– ReqHeader host: 10.10.1.110
– VCL_return hash
– ReqUnset Accept-Encoding: gzip, deflate
– ReqHeader Accept-Encoding: gzip
– VCL_call HASH
– VCL_return lookup
– Hit 32772 98.796069 10.000000 0.000000
– VCL_call HIT
-VCL_return deliver
– RespProtocol HTTP/1.1
– RespStatus 200
– RespReason OK
– RespHeader Date: Sun, 06 Oct 2019 13:41:24 GMT
– RespHeader Server: Apache/ 2.4.6 (CentOS) PHP/5.4.16
– RespHeader X-Powered-By: PHP/5.4.16
– RespHeader X-Pingback: http://10.10.1.110/index.php/action/ xmlrpc
– RespHeader Content-Type: text/html; charset=UTF-8
– RespHeader X-Varnish: 32774 32772
[[emailprotected] varnish-cache]# /usr/ local/bin/varnishstat