http://www.178linux.com/18401

varnish如何存储缓存对象:

    file: 单个文件;不支持持久机制;

    malloc: 缓存在内存中;

    persistent:基于文件的持久存储;(此方式不建议使用)

vcl:配置缓存系统的缓存机制;【线程中缓存功能的工作机制】

 yum install varnish  安装

[root@vs1 ~]# vim /etc/varnish/varnish.params 
 
# Varnish environment configuration description. This was derived from
# the old style sysconfig/defaults settings
 
# Set this to 1 to make systemd reload try to switch vcl without restart.
RELOAD_VCL=1
 
# Main configuration file. You probably want to change it.
VARNISH_VCL_CONF=/etc/varnish/default.vcl    #读取vcl配置文件的位置
 
# Default address and port to bind to. Blank address means all IPv4
# and IPv6 interfaces, otherwise specify a host name, an IPv4 dotted
# quad, or an IPv6 address in brackets.
# VARNISH_LISTEN_ADDRESS=192.168.1.5
VARNISH_LISTEN_PORT=6081    #监听的服务端口为6081
 
# Admin interface listen address and port
VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1    #监听的管理地址为本机
VARNISH_ADMIN_LISTEN_PORT=6082    #监听的管理端口为6082
 
# Shared secret file for admin interface
VARNISH_SECRET_FILE=/etc/varnish/secret    #密钥文件位置
 
# Backend storage specification, see Storage Types in the varnishd(5)
# man page for details.
VARNISH_STORAGE="file,/var/lib/varnish/varnish_storage.bin,1G"    #缓存以文件的方式的存储位置和大小
#VARNISH_STORAGE="malooc,256M"    #以内存方式缓存,缓存大小为256M
 
# Default TTL used when the backend does not specify one
VARNISH_TTL=120    #联系后端服务器超时时长
 
# User and group for the varnishd worker processes
VARNISH_USER=varnish    #主进程所使用的用户
VARNISH_GROUP=varnish    #主进程所使用的组
 
# Other options, see the man page varnishd(1)    #进程选项,线程池的最大值最小值和超时时长

DAEMON_OPTS="-p thread_pool_min=5 -p thread_pool_max=500 -p thread_pool_timeout=300"

[root@vs1 ~]# varnishadm -S /etc/varnish/secret -T 127.0.0.1:6082
help      
help [<command>]    #获取帮助信息
ping [<timestamp>]    #测试服务器是否正常
auth <response>    #
quit                #退出
banner
status            #显示服务器状态信息
start            #启动子进程
stop            #停止子进程
vcl.load <configname> <filename>    #载入哪个文件为配置文件
vcl.inline <configname> <quoted_VCLstring>
vcl.use <configname>                #使用哪个vcl文件
vcl.discard <configname>            #删除哪个vcl文件
vcl.list                     #列出所有可用的vcl文件
param.show [-l] [<param>]            #显示运行时参数
param.set <param> <value>                
panic.show                     #显示恐慌信息,显示进程或子进程上次挂掉的原因
panic.clear                                        #清除恐慌信息
storage.list                                        #显示缓存信息
vcl.show [-v] <configname>                        #显示vcl文件的详细信息,vcl编译前的样子
backend.list [<backend_expression>]                #显示后端服务器列表
backend.set_health <backend_expression> <state>    #手动上线下线后端服务器
ban <field> <operator> <arg> [&& <field> <oper> <arg>]...    #清理缓存中的缓存对象

ban.list                                             #显示定义的清理缓存规则


配置文件说明:

http://book.varnish-software.com/4.0/chapters/VCL_Basics.html

http://book.varnish-software.com/4.0/_p_w_picpaths/simplified_fsm.svg