标题:配置调优IIS6+gzip+varnish-2.0.6[原创] 出处:运维进行时 时间:Fri, 25 Dec 2009 23:20:24 +0000 作者:root 地址:https://blog.liuts.com/post/176/ 内容: 一、启用IIS6 Gzip模块 1.1、在 "IIS 管理器" 中,打开 "网站 > 属性" 对话框,切换到 "服务" 页卡,选中压缩应用程序文件(社区页面不做静态文件的压缩)压缩选项。 点击在新窗口中浏览此图片 https://blog.liuts.com/attachment.php?fid=40 1.2、新增一个服务扩展,路径为 "c:\windows\System32\inetsrv\gzip.dll"。添加完成后,允许该扩展使用。 点击在新窗口中浏览此图片 https://blog.liuts.com/attachment.php?fid=41 1.3、用记事本打开 "%windir%\system32\inetsrv\MetaBase.xml",找到 "IIsCompressionScheme",按下述方法修改、保存。(建议修改前先做备份)如果需要压缩动态文件,则将 HcDoDynamicCompression设置为"TRUE",并在HcScriptFileExtensions中增加您要压缩的动态文件后缀名,如asp (由于我要优化的系统中,做了shtml->asp的URL Rewrite,所以将 shtml、asp 也加入了)。 如果需要压缩静态文件,则将HcDoStaticCompression和HcDoOnDemandCompression设置为 "TRUE",并在HcFileExtensions中增加您需要压缩的静态文件后缀名,如xml、css等。HcDynamicCompressionLevel和HcOnDemandCompLevel表示需要的压缩率,数字(0~9)越小压缩率越低。 1.5、测试 使用HttpWatch Professional 6.0.14看看启用 GZip 后的效果。 点击在新窗口中浏览此图片 https://blog.liuts.com/attachment.php?fid=47 二、安装配置Vanish 2.0.6(最新版) 2.1、安装 (略) 2.2、调优sysctl.conf (略) 2.3、修改varnish配置 vi /usr/local/varnish/etc/vcl.conf 引用 backend wwwserver { .host = "192.168.100.5"; .port = "80"; } acl purge { "localhost"; "127.0.0.1"; "192.168.0.0"/16; } sub vcl_recv { if (req.request == "PURGE") { if (!client.ip ~ purge) { error 405 "Not allowed."; } lookup; } if (req.http.host ~ "^(cache.sina.com.cn)") { set req.backend = wwwserver; if (req.request != "GET" && req.request != "HEAD") { pipe; } else { lookup; } } else { error 404 "sina.com.cn.cn cache server"; lookup; } } sub vcl_hit { if (req.request == "PURGE") { set obj.ttl = 0s; error 200 "Purged."; } } sub vcl_miss { if (req.request == "PURGE") { error 404 "Not in cache."; } } sub vcl_fetch { if (req.request == "GET" && req.url ~ "\.(txt|js)$") { set obj.ttl = 3600s; } else { set obj.ttl = 300s; } } sub vcl_deliver { if (obj.hits > 0) { set resp.http.X-Cache = "HIT"; } else { set resp.http.X-Cache = "MISS"; } } 2.4命中率分析 点击在新窗口中浏览此图片 https://blog.liuts.com/attachment.php?fid=42 2.5、现象分析 1) 名词解释 Cache hits:缓存命中 Cache hits for pass:从背端服务器获取数据但无法被缓存 Cache misses:非命中 2) 分析 发现缓存结果数据比较奇怪的现象,不能缓存的对象还比命中的对象多得多,非命中数在正常值内。 3)排查过程 3.1、CURL命令测试,如curl -I http://www.sina.com.cn/index.shtml -H Accept-Encoding:gzip,defalte 点击在新窗口中浏览此图片 https://blog.liuts.com/attachment.php?fid=43 结果分析:发现每次response header中set Cookie都不一样,如此varnish会认为每次请求的都是不同对象,这一点跟squid有区别,squid会直接忽略cookie的判断。同样可以从X-cache:MISS中看到该对象没有被命中及不被Cache Hit。Content-Encoding:gzip,说明varnish已经支持了http1.1,成功将backend server 的gzip结果返回给客户端。 3.2、删除Varnish cookie请求 引用 sub vcl_fetch { remove obj.http.Set-Cookie; if (req.request == "GET" && req.url ~ "\.(txt|js)$") { set obj.ttl = 3600s; } else { set obj.ttl = 300s; } } 3.3、继续测试 点击在新窗口中浏览此图片 https://blog.liuts.com/attachment.php?fid=44 [图1] 点击在新窗口中浏览此图片 https://blog.liuts.com/attachment.php?fid=45 [图2] 结果分析:上图1为第一次请求URL,Vanish返回结果中可以看出没有被命中,属正常。图2为第二次请求同一URL,发现此次已经被HIT了。另两次response.head已经没有response cookie了,问题解决。 再看看Varnish缓存状态: 点击在新窗口中浏览此图片 https://blog.liuts.com/attachment.php?fid=46 结果分析:结果已正常,Cache hits for pass已经没有了,命中率还是比较理想的。 注:Varnish2.x版本后的语法、启动方式、优化项等与1.x相差有较大的差异,在以后实战中慢慢去体会到吧。[emot]stupid[/emot] Generated by Bo-blog 2.1.1 Release