<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[运维进行时]]></title> 
<link>https://blog.liuts.com/index.php</link> 
<description><![CDATA[互联网运维与架构]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[运维进行时]]></copyright>
<item>
<link>https://blog.liuts.com/post/176/</link>
<title><![CDATA[配置调优IIS6+gzip+varnish-2.0.6[原创]]]></title> 
<author>root &lt;admin@yourname.com&gt;</author>
<category><![CDATA[Varnish]]></category>
<pubDate>Fri, 25 Dec 2009 15:20:24 +0000</pubDate> 
<guid>https://blog.liuts.com/post/176/</guid> 
<description>
<![CDATA[ 
	<strong>一、启用IIS6 Gzip模块</strong><br/>1.1、在 "IIS 管理器" 中，打开 "网站 > 属性" 对话框，切换到 "服务" 页卡，选中压缩应用程序文件(社区页面不做静态文件的压缩)压缩选项。<a href="https://blog.liuts.com/attachment.php?fid=40" target="_blank"><img src="https://blog.liuts.com/attachment.php?fid=40" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/>1.2、新增一个服务扩展，路径为 "c:&#92;windows&#92;System32&#92;inetsrv&#92;gzip.dll"。添加完成后，允许该扩展使用。<br/><a href="https://blog.liuts.com/attachment.php?fid=41" target="_blank"><img src="https://blog.liuts.com/attachment.php?fid=41" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/>1.3、用记事本打开 "%windir%&#92;system32&#92;inetsrv&#92;MetaBase.xml"，找到 "IIsCompressionScheme"，按下述方法修改、保存。(建议修改前先做备份)如果需要压缩动态文件，则将 HcDoDynamicCompression设置为"TRUE"，并在HcScriptFileExtensions中增加您要压缩的动态文件后缀名，如asp (由于我要优化的系统中，做了shtml->asp的URL Rewrite，所以将 shtml、asp 也加入了)。<br/>如果需要压缩静态文件，则将HcDoStaticCompression和HcDoOnDemandCompression设置为 "TRUE"，并在HcFileExtensions中增加您需要压缩的静态文件后缀名，如xml、css等。HcDynamicCompressionLevel和HcOnDemandCompLevel表示需要的压缩率，数字(0~9)越小压缩率越低。<br/><textarea name="code" class="xml" rows="15" cols="100">
<IIsCompressionScheme&nbsp;&nbsp;Location ="/LM/W3SVC/Filters/Compression/deflate"
&nbsp;&nbsp;&nbsp;&nbsp;HcCompressionDll="%windir%&#92;system32&#92;inetsrv&#92;gzip.dll"
&nbsp;&nbsp;&nbsp;&nbsp;HcCreateFlags="0"
&nbsp;&nbsp;&nbsp;&nbsp;HcDoDynamicCompression="TRUE"
&nbsp;&nbsp;&nbsp;&nbsp;HcDoOnDemandCompression="FALSE"
&nbsp;&nbsp;&nbsp;&nbsp;HcDoStaticCompression="FALSE"
&nbsp;&nbsp;&nbsp;&nbsp;HcDynamicCompressionLevel="9"
&nbsp;&nbsp;&nbsp;&nbsp;HcFileExtensions="htm
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;html
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;txt"
&nbsp;&nbsp;&nbsp;&nbsp;HcOnDemandCompLevel="10"
&nbsp;&nbsp;&nbsp;&nbsp;HcPriority="1"
&nbsp;&nbsp;&nbsp;&nbsp;HcScriptFileExtensions="asp
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;shtml"
&nbsp;&nbsp;>
</IIsCompressionScheme>
<IIsCompressionScheme&nbsp;&nbsp;Location ="/LM/W3SVC/Filters/Compression/gzip"
&nbsp;&nbsp;&nbsp;&nbsp;HcCompressionDll="%windir%&#92;system32&#92;inetsrv&#92;gzip.dll"
&nbsp;&nbsp;&nbsp;&nbsp;HcCreateFlags="1"
&nbsp;&nbsp;&nbsp;&nbsp;HcDoDynamicCompression="TRUE"
&nbsp;&nbsp;&nbsp;&nbsp;HcDoOnDemandCompression="FALSE"
&nbsp;&nbsp;&nbsp;&nbsp;HcDoStaticCompression="FALSE"
&nbsp;&nbsp;&nbsp;&nbsp;HcDynamicCompressionLevel="0"
&nbsp;&nbsp;&nbsp;&nbsp;HcFileExtensions="htm
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;html
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;txt"
&nbsp;&nbsp;&nbsp;&nbsp;HcOnDemandCompLevel="10"
&nbsp;&nbsp;&nbsp;&nbsp;HcPriority="1"
&nbsp;&nbsp;&nbsp;&nbsp;HcScriptFileExtensions="asp
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;shtml"
&nbsp;&nbsp;>
</textarea><br/>1.5、<strong>测试</strong><br/>使用HttpWatch Professional 6.0.14看看启用 GZip 后的效果。<br/><a href="https://blog.liuts.com/attachment.php?fid=47" target="_blank"><img src="https://blog.liuts.com/attachment.php?fid=47" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/><strong>二、安装配置Vanish 2.0.6（最新版）</strong><br/>2.1、安装<br/>(略)<br/><br/><strong>2.2、调优sysctl.conf</strong><br/>(略)<br/><br/><strong>2.3、修改varnish配置</strong><br/>vi /usr/local/varnish/etc/vcl.conf<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content"><br/>backend wwwserver &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .host = "192.168.100.5";<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .port = "80";<br/>&#125;<br/>acl purge &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "localhost";<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "127.0.0.1";<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "192.168.0.0"/16;<br/>&#125;<br/>sub vcl_recv &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (req.request == "PURGE") &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!client.ip ~ purge) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; error 405 "Not allowed.";<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lookup;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#125;<br/>if (req.http.host ~ "^(cache.sina.com.cn)") &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set req.backend = wwwserver;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (req.request != "GET" && req.request != "HEAD") &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pipe;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lookup;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; error 404 "sina.com.cn.cn cache server";<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lookup;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#125;<br/>&#125;<br/>sub vcl_hit &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (req.request == "PURGE") &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set obj.ttl = 0s;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; error 200 "Purged.";<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#125;<br/>&#125;<br/>sub vcl_miss &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (req.request == "PURGE") &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; error 404 "Not in cache.";<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#125;<br/>&#125;<br/>sub vcl_fetch &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (req.request == "GET" && req.url ~ "&#92;.(txt&#124;js)$") &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set obj.ttl = 3600s;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set obj.ttl = 300s;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#125;<br/>&#125;<br/>sub vcl_deliver &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (obj.hits > 0) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set resp.http.X-Cache = "HIT";<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125; else &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set resp.http.X-Cache = "MISS";<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&#125;<br/></div></div><br/><br/><strong>2.4命中率分析</strong><br/><a href="https://blog.liuts.com/attachment.php?fid=42" target="_blank"><img src="https://blog.liuts.com/attachment.php?fid=42" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/><strong>2.5、现象分析</strong><br/>1) <strong>名词解释</strong><br/>Cache hits：缓存命中<br/>Cache hits for pass：从背端服务器获取数据但无法被缓存<br/>Cache misses：非命中<br/>2) <strong>分析</strong><br/>发现缓存结果数据比较奇怪的现象，不能缓存的对象还比命中的对象多得多，非命中数在正常值内。<br/>3）<strong>排查过程</strong><br/>3.1、CURL命令测试，如curl -I http://www.sina.com.cn/index.shtml -H Accept-Encoding:gzip,defalte<br/><a href="https://blog.liuts.com/attachment.php?fid=43" target="_blank"><img src="https://blog.liuts.com/attachment.php?fid=43" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/><strong>结果分析</strong>：发现每次response header中set Cookie都不一样,如此varnish会认为每次请求的都是不同对象，这一点跟squid有区别，squid会直接忽略cookie的判断。同样可以从X-cache：MISS中看到该对象没有被命中及不被Cache Hit。Content-Encoding:gzip，说明varnish已经支持了http1.1，成功将backend server 的gzip结果返回给客户端。<br/><br/>3.2、<strong>删除Varnish cookie请求</strong><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content"><br/>sub vcl_fetch &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; remove obj.http.Set-Cookie;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (req.request == "GET" && req.url ~ "&#92;.(txt&#124;js)$") &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set obj.ttl = 3600s;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set obj.ttl = 300s;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#125;<br/>&#125;<br/></div></div><br/>3.3、<strong>继续测试</strong><br/><a href="https://blog.liuts.com/attachment.php?fid=44" target="_blank"><img src="https://blog.liuts.com/attachment.php?fid=44" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/>[图1]<br/><br/><a href="https://blog.liuts.com/attachment.php?fid=45" target="_blank"><img src="https://blog.liuts.com/attachment.php?fid=45" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/>[图2]<br/><br/><strong>结果分析</strong>:上图1为第一次请求URL，Vanish返回结果中可以看出没有被命中，属正常。图2为第二次请求同一URL，发现此次已经被HIT了。另两次response.head已经没有response cookie了，问题解决。<br/>再看看Varnish缓存状态：<br/><a href="https://blog.liuts.com/attachment.php?fid=46" target="_blank"><img src="https://blog.liuts.com/attachment.php?fid=46" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/><strong>结果分析</strong>:结果已正常，Cache hits for pass已经没有了，命中率还是比较理想的。<br/><br/><span style="color: #FF0000;">注</span>：Varnish2.x版本后的语法、启动方式、优化项等与1.x相差有较大的差异，在以后实战中慢慢去体会到吧。<br/>Tags - <a href="https://blog.liuts.com/tags/varnish/" rel="tag">varnish</a> , <a href="https://blog.liuts.com/tags/gzip/" rel="tag">gzip</a>
]]>
</description>
</item><item>
<link>https://blog.liuts.com/post/176/#blogcomment4</link>
<title><![CDATA[[评论] 配置调优IIS6+gzip+varnish-2.0.6[原创]]]></title> 
<author>reset &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Sat, 26 Dec 2009 05:53:00 +0000</pubDate> 
<guid>https://blog.liuts.com/post/176/#blogcomment4</guid> 
<description>
<![CDATA[ 
	你好，我安装过这个版本，启动没问题，但访问奇慢无比，后来换成1.1的就没问题了。怎么回事？？
]]>
</description>
</item><item>
<link>https://blog.liuts.com/post/176/#blogcomment5</link>
<title><![CDATA[[评论] 配置调优IIS6+gzip+varnish-2.0.6[原创]]]></title> 
<author>reset &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Sat, 26 Dec 2009 08:53:08 +0000</pubDate> 
<guid>https://blog.liuts.com/post/176/#blogcomment5</guid> 
<description>
<![CDATA[ 
	搞定了，谢谢！！多多向你学习。
]]>
</description>
</item><item>
<link>https://blog.liuts.com/post/176/#blogcomment7</link>
<title><![CDATA[[评论] 配置调优IIS6+gzip+varnish-2.0.6[原创]]]></title> 
<author>zzh &lt;zzhcool@126.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Mon, 28 Dec 2009 02:30:00 +0000</pubDate> 
<guid>https://blog.liuts.com/post/176/#blogcomment7</guid> 
<description>
<![CDATA[ 
	为什么我想转载你的文章，图片都提示防盗链啊？怎么复制粘贴也不行
]]>
</description>
</item>
</channel>
</rss>