更新至Varnish 4.0,VCL变更明细说明

提醒:本文最后更新于 2650 天前,文中所描述的信息可能已发生改变,请仔细核实。

@青阳怂恿,更新完Varnish 4后的感觉,感觉貌似不如Varnish 3快速,也有可能是错觉,不过从数据上和测试上,确实不如版本3,虽说安全提高,但是一些功能也用不了了。

只能说是干掉版本号。。。希望Varnish 4以后能更给力一点。。。

如无必要,建议大家不必升级到Varnish 4。

当然也不是全然无优点的,比如vcl显得逻辑更强了,recycle释放内存能力也相对变强这些。

安装很简单:

rpm --nosignature -i http://repo.varnish-cache.org/redhat/varnish-4.0/el6/noarch/varnish-release/varnish-release-4.0-4.el6.noarch.rpm
yum install varnish -y

至于新版本不同,还挺多的。

新版本Varnish4,client/backend分离,新的vanishlog查询语言,安全方面据说有提升。

首先是必须定义版本号: vcl 4.0。VMOD’s更独立化,官方推荐是加载Standard VMOD’s(std)。

另外director已变为VMOD,如需使用,需要import directors。

vcl_fetch函数被vcl_backend_response和vcl_backend_fetch代替,且req.*不再适用vcl_backend_response,只能使用bereq.*。

至于vcl_backend_fetch貌似没哪个doc见到详细用法。

error变更为return(synth(http_code,message)),req.backend成了req.backend_hint,req.request变更为req.method,obj为只读对象了。

vcl_synth采用resp.*,而非原来的obj.*。

vcl_error变更为vcl_backend_error,必须使用beresp.*,而不是obj.*。

关键字"purge;"命令,已被去除。在vcl_recv使用return(purge)。

hit_for_pass通过set beresp.uncacheable = true;来指定。

vcl_recv必须将lookup变更返回hash,vcl_hash必须将hash变更返回lookup,vcl_pass必须将pass变更返回fetch。

req.backend.healty被std.healthy(req.backend)代替,但是设置不了grace,鸡肋,被抛弃了,现在仅能做的就是keepalive的作用了。

req、bereq,resp、beresp之间不同,可被使用的位置不同。

server.port、client.port分别变更为std.port(server.ip)、std.port(client.ip),跟上面healthy一样,需要import std。

session_linger变更为timeout_linger,sess_timeout变更为timeout_idle,sess_workspace被抛弃了。

remove被完全弃用了,不过我一直用unset的说。

return(restart)变更为return(retry),vcl_backend_fetch会被使用到。

自定义sub函数不能以vcl_开头,调用方式call udf。

以上,就是我这次遇到过的问题,应该涵盖了大多数变化。

因为我本身的VCL内容多,所以算是比较麻烦。但好歹顺顺利利过了这关。

转载请注明转自:kn007的个人博客的《更新至Varnish 4.0,VCL变更明细说明