<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>《Ourlinux》杂志</title>
	<atom:link href="http://www.ourlinux.net/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ourlinux.net</link>
	<description>分享经验，分享快乐^_^</description>
	<lastBuildDate>Fri, 11 Nov 2011 02:36:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>跟踪任何缓存软件最重要的度量指标是： 1、缓存命中率 2、总请求率 3、对象平均&#8230;</title>
		<link>http://www.ourlinux.net/2011/11/11/1491.html</link>
		<comments>http://www.ourlinux.net/2011/11/11/1491.html#comments</comments>
		<pubDate>Fri, 11 Nov 2011 02:35:32 +0000</pubDate>
		<dc:creator>bixuan</dc:creator>
				<category><![CDATA[status]]></category>
		<category><![CDATA[LRU]]></category>
		<category><![CDATA[命中率]]></category>
		<category><![CDATA[度量指标]]></category>
		<category><![CDATA[笔记]]></category>

		<guid isPermaLink="false">http://www.ourlinux.net/2011/11/11/1491.html</guid>
		<description><![CDATA[跟踪任何缓存软件最重要的度量指标是： 1、缓存命中率 2、总请求率 3、对象平均大小 4、LRU参考时间（当使用LRU方式时）]]></description>
			<content:encoded><![CDATA[<p>跟踪任何缓存软件最重要的度量指标是：<br />
1、缓存命中率<br />
2、总请求率<br />
3、对象平均大小<br />
4、LRU参考时间（当使用LRU方式时）</p>]]></content:encoded>
			<wfw:commentRss>http://www.ourlinux.net/2011/11/11/1491.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WEB访问怎么样才算足够快？ Jakob Nielsen是web可用性领域知名且&#8230;</title>
		<link>http://www.ourlinux.net/2011/11/10/1490.html</link>
		<comments>http://www.ourlinux.net/2011/11/10/1490.html#comments</comments>
		<pubDate>Thu, 10 Nov 2011 03:13:59 +0000</pubDate>
		<dc:creator>bixuan</dc:creator>
				<category><![CDATA[status]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[准则]]></category>
		<category><![CDATA[响应延迟]]></category>
		<category><![CDATA[笔记]]></category>

		<guid isPermaLink="false">http://www.ourlinux.net/2011/11/10/1490.html</guid>
		<description><![CDATA[WEB访问怎么样才算足够快？ Jakob Nielsen是web可用性领域知名且备受推崇的专家，下面引用的内容论述了“足够快”的问题： 基于Web应用的响应时间准则和其他应用一样。37年来这些准则毫无变化，所以它们也不太可能因新技术的出现而发生改变。 0.1秒：用户直接操作UI中对象的感觉极限。比如，从用户选择表格中的一列到该列高亮或向用户反馈已被选择的时间间隔。理想情况下，它也是对列进行排序的响应时间——这种情况下用户会感到他们正在给表格排序。 1秒：用户随意地在计算机指令空间进行操作而无需过度等待的感觉极限。0.2~1.0秒的延迟意味着会被用户注意到，因此感觉到计算机处于对指令的“处理中”，这有别于直接响应用户行为的指令。例如：如果根据被选择的列对表格进行排序无法在0.1秒内完成，那么必须在1秒内完成，否则用户将感觉到UI变得缓慢且在执行任务中失去“流畅（flow）”的体验。超过1秒的延迟要提示用户计算机正在解决这个问题，例如改变光标的形态。 10秒：用户专注于任务的极限。超过10秒的任何操作都需要一个百分比完成指示器，以及一个方便用户中断操作且有清晰标识的方法。假设用户遭遇超过10秒延迟后才返回到原UI的情况，他们将需要重新适应。在用户的工作中，超过10秒的延迟仅在自然中断时可以接受，比如切换任务时。]]></description>
			<content:encoded><![CDATA[<p>WEB访问怎么样才算足够快？</p>
<p>Jakob Nielsen是web可用性领域知名且备受推崇的专家，下面引用的内容论述了“足够快”的问题：</p>
<p>基于Web应用的响应时间准则和其他应用一样。37年来这些准则毫无变化，所以它们也不太可能因新技术的出现而发生改变。</p>
<p>0.1秒：用户直接操作UI中对象的感觉极限。比如，从用户选择表格中的一列到该列高亮或向用户反馈已被选择的时间间隔。理想情况下，它也是对列进行排序的响应时间——这种情况下用户会感到他们正在给表格排序。</p>
<p>1秒：用户随意地在计算机指令空间进行操作而无需过度等待的感觉极限。0.2~1.0秒的延迟意味着会被用户注意到，因此感觉到计算机处于对指令的“处理中”，这有别于直接响应用户行为的指令。例如：如果根据被选择的列对表格进行排序无法在0.1秒内完成，那么必须在1秒内完成，否则用户将感觉到UI变得缓慢且在执行任务中失去“流畅（flow）”的体验。超过1秒的延迟要提示用户计算机正在解决这个问题，例如改变光标的形态。</p>
<p>10秒：用户专注于任务的极限。超过10秒的任何操作都需要一个百分比完成指示器，以及一个方便用户中断操作且有清晰标识的方法。假设用户遭遇超过10秒延迟后才返回到原UI的情况，他们将需要重新适应。在用户的工作中，超过10秒的延迟仅在自然中断时可以接受，比如切换任务时。</p>]]></content:encoded>
			<wfw:commentRss>http://www.ourlinux.net/2011/11/10/1490.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>新创建了：运维架构师交流QQ群02(127858917)，欢迎加入~</title>
		<link>http://www.ourlinux.net/2011/11/10/1489.html</link>
		<comments>http://www.ourlinux.net/2011/11/10/1489.html#comments</comments>
		<pubDate>Thu, 10 Nov 2011 02:45:09 +0000</pubDate>
		<dc:creator>bixuan</dc:creator>
				<category><![CDATA[status]]></category>
		<category><![CDATA[架构师]]></category>
		<category><![CDATA[运维]]></category>

		<guid isPermaLink="false">http://www.ourlinux.net/2011/11/10/1489.html</guid>
		<description><![CDATA[新创建了：运维架构师交流QQ群02(127858917)，欢迎加入~]]></description>
			<content:encoded><![CDATA[<p>新创建了：运维架构师交流QQ群02(127858917)，欢迎加入~</p>]]></content:encoded>
			<wfw:commentRss>http://www.ourlinux.net/2011/11/10/1489.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title></title>
		<link>http://www.ourlinux.net/2011/10/18/1486.html</link>
		<comments>http://www.ourlinux.net/2011/10/18/1486.html#comments</comments>
		<pubDate>Tue, 18 Oct 2011 14:17:23 +0000</pubDate>
		<dc:creator>bixuan</dc:creator>
				<category><![CDATA[生活日志]]></category>

		<guid isPermaLink="false">http://www.ourlinux.net/?p=1486</guid>
		<description><![CDATA[换了个皮肤，hoho]]></description>
			<content:encoded><![CDATA[<p>换了个皮肤，hoho</p>]]></content:encoded>
			<wfw:commentRss>http://www.ourlinux.net/2011/10/18/1486.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>域名又到期了，NND，咋不通知我呢~~</title>
		<link>http://www.ourlinux.net/2011/06/28/1483.html</link>
		<comments>http://www.ourlinux.net/2011/06/28/1483.html#comments</comments>
		<pubDate>Tue, 28 Jun 2011 01:25:42 +0000</pubDate>
		<dc:creator>bixuan</dc:creator>
				<category><![CDATA[status]]></category>

		<guid isPermaLink="false">http://www.ourlinux.net/2011/06/28/1483.html</guid>
		<description><![CDATA[域名又到期了，NND，咋不通知我呢~~]]></description>
			<content:encoded><![CDATA[<p>域名又到期了，NND，咋不通知我呢~~</p>]]></content:encoded>
			<wfw:commentRss>http://www.ourlinux.net/2011/06/28/1483.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>十二生肖各有缺失：鼠无睛（畏光），牛无牙，虎无项，兔无唇，龙无耳，蛇无足，马无齿&#8230;</title>
		<link>http://www.ourlinux.net/2011/05/04/1482.html</link>
		<comments>http://www.ourlinux.net/2011/05/04/1482.html#comments</comments>
		<pubDate>Wed, 04 May 2011 05:37:26 +0000</pubDate>
		<dc:creator>bixuan</dc:creator>
				<category><![CDATA[status]]></category>

		<guid isPermaLink="false">http://www.ourlinux.net/2011/05/04/1482.html</guid>
		<description><![CDATA[十二生肖各有缺失：鼠无睛（畏光），牛无牙，虎无项，兔无唇，龙无耳，蛇无足，马无齿，羊无瞳（所以天气一暗就得赶快回家，不然会找不到路），猴无腮，鸡无肾（大小便一起排），狗无脾（消化道系统不健全，需要吃其他动物的排泄物，以补其不足，所以狗改不了吃屎），猪无筋（抓猪时可从尾巴抓就好，因为中间无大筋不会回过头来咬人一口）]]></description>
			<content:encoded><![CDATA[<p>十二生肖各有缺失：鼠无睛（畏光），牛无牙，虎无项，兔无唇，龙无耳，蛇无足，马无齿，羊无瞳（所以天气一暗就得赶快回家，不然会找不到路），猴无腮，鸡无肾（大小便一起排），狗无脾（消化道系统不健全，需要吃其他动物的排泄物，以补其不足，所以狗改不了吃屎），猪无筋（抓猪时可从尾巴抓就好，因为中间无大筋不会回过头来咬人一口）</p>]]></content:encoded>
			<wfw:commentRss>http://www.ourlinux.net/2011/05/04/1482.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>晚上公司电影协会组织看《里约大冒险》，太给力了，哈哈~</title>
		<link>http://www.ourlinux.net/2011/04/22/1481.html</link>
		<comments>http://www.ourlinux.net/2011/04/22/1481.html#comments</comments>
		<pubDate>Fri, 22 Apr 2011 10:16:21 +0000</pubDate>
		<dc:creator>bixuan</dc:creator>
				<category><![CDATA[status]]></category>

		<guid isPermaLink="false">http://www.ourlinux.net/2011/04/22/1481.html</guid>
		<description><![CDATA[晚上公司电影协会组织看《里约大冒险》，太给力了，哈哈~]]></description>
			<content:encoded><![CDATA[<p>晚上公司电影协会组织看《里约大冒险》，太给力了，哈哈~</p>]]></content:encoded>
			<wfw:commentRss>http://www.ourlinux.net/2011/04/22/1481.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>身体好！生活好！工作好！这是对兄弟们的要求，也是部门的期望~</title>
		<link>http://www.ourlinux.net/2011/04/22/1480.html</link>
		<comments>http://www.ourlinux.net/2011/04/22/1480.html#comments</comments>
		<pubDate>Fri, 22 Apr 2011 09:57:09 +0000</pubDate>
		<dc:creator>bixuan</dc:creator>
				<category><![CDATA[status]]></category>

		<guid isPermaLink="false">http://www.ourlinux.net/2011/04/22/1480.html</guid>
		<description><![CDATA[身体好！生活好！工作好！这是对兄弟们的要求，也是部门的期望~]]></description>
			<content:encoded><![CDATA[<p>身体好！生活好！工作好！这是对兄弟们的要求，也是部门的期望~</p>]]></content:encoded>
			<wfw:commentRss>http://www.ourlinux.net/2011/04/22/1480.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>刚做了2个测试： 1、nginx+php-cgi fpm 100000 fetc&#8230;</title>
		<link>http://www.ourlinux.net/2011/03/29/1478.html</link>
		<comments>http://www.ourlinux.net/2011/03/29/1478.html#comments</comments>
		<pubDate>Tue, 29 Mar 2011 15:49:46 +0000</pubDate>
		<dc:creator>bixuan</dc:creator>
				<category><![CDATA[status]]></category>
		<category><![CDATA[lighttpd]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[php-cgi]]></category>

		<guid isPermaLink="false">http://www.ourlinux.net/2011/03/29/1478.html</guid>
		<description><![CDATA[刚做了2个测试： 1、nginx+php-cgi fpm 100000 fetches, 100 max parallel, 2e+06 bytes, in 39.5206 seconds 20 mean bytes/connection 2530.33 fetches/sec, 50606.6 bytes/sec msecs/connect: 0.538099 mean, 3000.11 max, 0.106 min msecs/first-response: 38.9175 mean, 402.378 max, 0.313 min HTTP response codes: code 200 &#8212; 100000 2、lighttpd+php-cgi fpm 100000 fetches, 100 max parallel, 2e+06 bytes, in 15.6593 seconds 20 mean [...]]]></description>
			<content:encoded><![CDATA[<p>刚做了2个测试：</p>
<p>1、nginx+php-cgi fpm<br />
100000 fetches, 100 max parallel, 2e+06 bytes, in 39.5206 seconds<br />
20 mean bytes/connection<br />
2530.33 fetches/sec, 50606.6 bytes/sec<br />
msecs/connect: 0.538099 mean, 3000.11 max, 0.106 min<br />
msecs/first-response: 38.9175 mean, 402.378 max, 0.313 min<br />
HTTP response codes:<br />
  code 200 &#8212; 100000</p>
<p>2、lighttpd+php-cgi fpm<br />
100000 fetches, 100 max parallel, 2e+06 bytes, in 15.6593 seconds<br />
20 mean bytes/connection<br />
6385.99 fetches/sec, 127720 bytes/sec<br />
msecs/connect: 3.78652 mean, 3001.08 max, 0.105 min<br />
msecs/first-response: 9.88036 mean, 229.16 max, 0.495 min<br />
HTTP response codes:<br />
  code 200 &#8212; 100000</p>]]></content:encoded>
			<wfw:commentRss>http://www.ourlinux.net/2011/03/29/1478.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>最近加上了网卡丢包的监控，发现BCM5709 驱动：1.9.20d，经常有丢包的&#8230;</title>
		<link>http://www.ourlinux.net/2011/03/24/1477.html</link>
		<comments>http://www.ourlinux.net/2011/03/24/1477.html#comments</comments>
		<pubDate>Thu, 24 Mar 2011 03:35:38 +0000</pubDate>
		<dc:creator>bixuan</dc:creator>
				<category><![CDATA[status]]></category>
		<category><![CDATA[bcm5709]]></category>

		<guid isPermaLink="false">http://www.ourlinux.net/2011/03/24/1477.html</guid>
		<description><![CDATA[最近加上了网卡丢包的监控，发现BCM5709 驱动：1.9.20d，经常有丢包的报警，比例很大。FT..]]></description>
			<content:encoded><![CDATA[<p>最近加上了网卡丢包的监控，发现BCM5709 驱动：1.9.20d，经常有丢包的报警，比例很大。FT..</p>]]></content:encoded>
			<wfw:commentRss>http://www.ourlinux.net/2011/03/24/1477.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>zabbix里如何创建proxy节点？ 详细见：这里&#8230;</title>
		<link>http://www.ourlinux.net/2011/03/09/1476.html</link>
		<comments>http://www.ourlinux.net/2011/03/09/1476.html#comments</comments>
		<pubDate>Wed, 09 Mar 2011 12:36:35 +0000</pubDate>
		<dc:creator>bixuan</dc:creator>
				<category><![CDATA[status]]></category>
		<category><![CDATA[zabbix]]></category>

		<guid isPermaLink="false">http://www.ourlinux.net/2011/03/09/1476.html</guid>
		<description><![CDATA[zabbix里如何创建proxy节点？ 详细见：这里]]></description>
			<content:encoded><![CDATA[<p>zabbix里如何创建proxy节点？</p>
<p>详细见：<a href="http://faq.ourlinux.net/index.php?action=artikel&#038;cat=36&#038;id=8&#038;artlang=zh" target="_blank">这里</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.ourlinux.net/2011/03/09/1476.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>大家有啥好问题，可以去http://faq.ourlinux.net/&#8230;</title>
		<link>http://www.ourlinux.net/2011/03/06/1475.html</link>
		<comments>http://www.ourlinux.net/2011/03/06/1475.html#comments</comments>
		<pubDate>Sun, 06 Mar 2011 02:54:55 +0000</pubDate>
		<dc:creator>bixuan</dc:creator>
				<category><![CDATA[status]]></category>
		<category><![CDATA[faq]]></category>

		<guid isPermaLink="false">http://www.ourlinux.net/2011/03/06/1475.html</guid>
		<description><![CDATA[大家有啥好问题，可以去http://faq.ourlinux.net/]]></description>
			<content:encoded><![CDATA[<p>大家有啥好问题，可以去<a href="http://faq.ourlinux.net/">http://faq.ourlinux.net/</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.ourlinux.net/2011/03/06/1475.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>有时候在Linux上直接删除文件，但是文件句柄没释放，这样就会导致磁盘空间也不释&#8230;</title>
		<link>http://www.ourlinux.net/2011/03/05/1473.html</link>
		<comments>http://www.ourlinux.net/2011/03/05/1473.html#comments</comments>
		<pubDate>Sat, 05 Mar 2011 13:34:07 +0000</pubDate>
		<dc:creator>bixuan</dc:creator>
				<category><![CDATA[status]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[lsof]]></category>

		<guid isPermaLink="false">http://www.ourlinux.net/2011/03/05/1473.html</guid>
		<description><![CDATA[有时候在Linux上直接删除文件，但是文件句柄没释放，这样就会导致磁盘空间也不释放，这个时候用du来查看目录的空间是不准的。今天就遇到了这个问题，一直没发现是哪个进程占着不释放，后来用lsof终于抓到了。呵呵~ lsof&#124;grep REG&#124;awk '{if ($7 > 0) print $7, $9, $10}'&#124;sort -rn&#124;head -n 10 查看文件最大的10个文件。 如果看到：(deleted)，说明文件已经被删，但是句柄没释放。]]></description>
			<content:encoded><![CDATA[<p>有时候在Linux上直接删除文件，但是文件句柄没释放，这样就会导致磁盘空间也不释放，这个时候用du来查看目录的空间是不准的。今天就遇到了这个问题，一直没发现是哪个进程占着不释放，后来用lsof终于抓到了。呵呵~</p>
<pre>
lsof|grep REG|awk '{if ($7 > 0) print $7, $9, $10}'|sort -rn|head -n 10
</pre>
<p>查看文件最大的10个文件。</p>
<p>如果看到：(deleted)，说明文件已经被删，但是句柄没释放。</p>]]></content:encoded>
			<wfw:commentRss>http://www.ourlinux.net/2011/03/05/1473.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>安装php-handlersocket</title>
		<link>http://www.ourlinux.net/2011/03/05/1466.html</link>
		<comments>http://www.ourlinux.net/2011/03/05/1466.html#comments</comments>
		<pubDate>Sat, 05 Mar 2011 05:48:52 +0000</pubDate>
		<dc:creator>bixuan</dc:creator>
				<category><![CDATA[post]]></category>
		<category><![CDATA[数据库]]></category>
		<category><![CDATA[运维小技巧]]></category>
		<category><![CDATA[HandlerSocket]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[php-handlersocket]]></category>

		<guid isPermaLink="false">http://www.ourlinux.net/2011/03/05/1466.html</guid>
		<description><![CDATA[至于HandlerSocket的安装请参考：MySQL+HandlerSocket安装一文。 安装php-handlersocket一开始还遇到了点小问题，说找不到-Ihsclient的库文件，估计是我安装HandlerSocket-Plugin的时候指定了prefix，而在编译php-handlersocet的时候没加环境导致的，后来为了偷懒，就直接安装到/usr/local了。 wegt -c http://php-handlersocket.googlecode.com/files/php-handlersocket-0.0.7.tar.gz tar zxvf php-handlersocket-0.0.7.tar.gz cd php-handlersocket PREFIX=/opt/app $PREFIX/php5-fastcgi/bin/phpize ./configure --with-handlersocket \ --with-handlersocket-includedir=$PREFIX/HandlerSocket-Plugin/include/handlersocket \ --with-php-config=$PREFIX/php5-fastcgi/bin/php-config make &#38;&#38; make install cd .. 然后将extension=&#8221;handlersocket.so&#8221;加到php,ini配置即可。]]></description>
			<content:encoded><![CDATA[<p>至于HandlerSocket的安装请参考：<a target="_blank">MySQL+HandlerSocket安装</a>一文。</p>
<p>安装<a href="http://code.google.com/p/php-handlersocket" target="_blank">php-handlersocket</a>一开始还遇到了点小问题，说找不到-Ihsclient的库文件，估计是我安装HandlerSocket-Plugin的时候指定了prefix，而在编译php-handlersocet的时候没加环境导致的，后来为了偷懒，就直接安装到/usr/local了。</p>
<pre>wegt -c <a href="http://php-handlersocket.googlecode.com/files/php-handlersocket-0.0.7.tar.gz" rel="nofollow">http://php-handlersocket.googlecode.com/files/php-handlersocket-0.0.7.tar.gz</a>
tar zxvf php-handlersocket-0.0.7.tar.gz
cd php-handlersocket
PREFIX=/opt/app
$PREFIX/php5-fastcgi/bin/phpize
./configure --with-handlersocket \
--with-handlersocket-includedir=$PREFIX/HandlerSocket-Plugin/include/handlersocket \
--with-php-config=$PREFIX/php5-fastcgi/bin/php-config
make &amp;&amp; make install
cd ..</pre>
<p>然后将extension=&#8221;handlersocket.so&#8221;加到php,ini配置即可。</p>]]></content:encoded>
			<wfw:commentRss>http://www.ourlinux.net/2011/03/05/1466.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>“我想在这个世界上，每个人的宿命都已经是安排好的，只不过有的人喜欢，有的人不喜欢&#8230;</title>
		<link>http://www.ourlinux.net/2011/02/26/1464.html</link>
		<comments>http://www.ourlinux.net/2011/02/26/1464.html#comments</comments>
		<pubDate>Sat, 26 Feb 2011 07:02:49 +0000</pubDate>
		<dc:creator>bixuan</dc:creator>
				<category><![CDATA[status]]></category>
		<category><![CDATA[生活]]></category>
		<category><![CDATA[电影]]></category>

		<guid isPermaLink="false">http://www.ourlinux.net/2011/02/26/1464.html</guid>
		<description><![CDATA[“我想在这个世界上，每个人的宿命都已经是安排好的，只不过有的人喜欢，有的人不喜欢。”- from电影《地域神探》]]></description>
			<content:encoded><![CDATA[<p>“我想在这个世界上，每个人的宿命都已经是安排好的，只不过有的人喜欢，有的人不喜欢。”- from电影《地域神探》</p>]]></content:encoded>
			<wfw:commentRss>http://www.ourlinux.net/2011/02/26/1464.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>一个mysql的小故障</title>
		<link>http://www.ourlinux.net/2011/02/25/1460.html</link>
		<comments>http://www.ourlinux.net/2011/02/25/1460.html#comments</comments>
		<pubDate>Fri, 25 Feb 2011 06:18:17 +0000</pubDate>
		<dc:creator>bixuan</dc:creator>
				<category><![CDATA[数据库]]></category>
		<category><![CDATA[运维小技巧]]></category>
		<category><![CDATA[InnoDB]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[故障]]></category>

		<guid isPermaLink="false">http://www.ourlinux.net/2011/02/25/1460.html</guid>
		<description><![CDATA[今天机器重启后，发现一个innodb（mysql-5.0.45）的表提示如下错误：Incorrect information in file: &#8216;./MD/t_monitor_client.frm&#8217;， 原因是：表结构出现错误。 解决方法： 1、停止mysql； 2、在其他的机器上重该表， 3、将t_monitor_client.frm复制到故障机器上， 4、启动mysql， 5、检查，没问题就成功了。]]></description>
			<content:encoded><![CDATA[<p>今天机器重启后，发现一个innodb（mysql-5.0.45）的表提示如下错误：Incorrect information in file: &#8216;./MD/t_monitor_client.frm&#8217;，</p>
<p>原因是：表结构出现错误。</p>
<p>解决方法：<br />
1、停止mysql；<br />
2、在其他的机器上重该表，<br />
3、将t_monitor_client.frm复制到故障机器上，<br />
4、启动mysql，<br />
5、检查，没问题就成功了。</p>]]></content:encoded>
			<wfw:commentRss>http://www.ourlinux.net/2011/02/25/1460.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux Introduction (Commands)</title>
		<link>http://www.ourlinux.net/2011/02/19/1458.html</link>
		<comments>http://www.ourlinux.net/2011/02/19/1458.html#comments</comments>
		<pubDate>Fri, 18 Feb 2011 16:31:32 +0000</pubDate>
		<dc:creator>bixuan</dc:creator>
				<category><![CDATA[操作系统]]></category>
		<category><![CDATA[运维小技巧]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.ourlinux.net/?p=1458</guid>
		<description><![CDATA[Linux Introduction (Commands) View more presentations from anandvaidya.]]></description>
			<content:encoded><![CDATA[<div style="width:425px" id="__ss_107974"><strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/anandvaidya/linux-introduction-commands" title="Linux Introduction (Commands)">Linux Introduction (Commands)</a></strong><object id="__sse107974" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=linux-introduction-commands2338&#038;stripped_title=linux-introduction-commands&#038;userName=anandvaidya" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed name="__sse107974" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=linux-introduction-commands2338&#038;stripped_title=linux-introduction-commands&#038;userName=anandvaidya" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="padding:5px 0 12px">View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/anandvaidya">anandvaidya</a>.</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.ourlinux.net/2011/02/19/1458.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux Administration</title>
		<link>http://www.ourlinux.net/2011/02/19/1456.html</link>
		<comments>http://www.ourlinux.net/2011/02/19/1456.html#comments</comments>
		<pubDate>Fri, 18 Feb 2011 16:29:48 +0000</pubDate>
		<dc:creator>bixuan</dc:creator>
				<category><![CDATA[操作系统]]></category>
		<category><![CDATA[运维小技巧]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.ourlinux.net/?p=1456</guid>
		<description><![CDATA[Linux Administration View more presentations from Harish1983.]]></description>
			<content:encoded><![CDATA[<div style="width:425px" id="__ss_869511"><strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/Harish1983/linux-administration-presentation" title="Linux Administration">Linux Administration</a></strong><object id="__sse869511" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=linux-administration-1230110345775948-1&#038;stripped_title=linux-administration-presentation&#038;userName=Harish1983" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed name="__sse869511" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=linux-administration-1230110345775948-1&#038;stripped_title=linux-administration-presentation&#038;userName=Harish1983" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="padding:5px 0 12px">View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/Harish1983">Harish1983</a>.</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.ourlinux.net/2011/02/19/1456.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Performance Tuning &#8211; GNUnify 2010</title>
		<link>http://www.ourlinux.net/2011/02/19/1454.html</link>
		<comments>http://www.ourlinux.net/2011/02/19/1454.html#comments</comments>
		<pubDate>Fri, 18 Feb 2011 16:28:26 +0000</pubDate>
		<dc:creator>bixuan</dc:creator>
				<category><![CDATA[数据库]]></category>
		<category><![CDATA[运维小技巧]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://www.ourlinux.net/?p=1454</guid>
		<description><![CDATA[MySQL Performance Tuning &#8211; GNUnify 2010 View more presentations from OSSCube LLC A Global Open Source Enterprise for Open Source Solutions.]]></description>
			<content:encoded><![CDATA[<div style="width:425px" id="__ss_3363080"><strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/osscube/mysql-performance-tuning-gnunify-2010" title="MySQL Performance Tuning - GNUnify 2010">MySQL Performance Tuning &#8211; GNUnify 2010</a></strong><object id="__sse3363080" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=mysqlperformancetuning-gnunify-100308032244-phpapp01&#038;stripped_title=mysql-performance-tuning-gnunify-2010&#038;userName=osscube" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed name="__sse3363080" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=mysqlperformancetuning-gnunify-100308032244-phpapp01&#038;stripped_title=mysql-performance-tuning-gnunify-2010&#038;userName=osscube" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="padding:5px 0 12px">View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/osscube">OSSCube LLC A Global Open Source Enterprise for Open Source Solutions</a>.</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.ourlinux.net/2011/02/19/1454.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HOWTO Implement GeoDNS using BIND &amp; &#8230;</title>
		<link>http://www.ourlinux.net/2011/02/17/1450.html</link>
		<comments>http://www.ourlinux.net/2011/02/17/1450.html#comments</comments>
		<pubDate>Thu, 17 Feb 2011 13:42:43 +0000</pubDate>
		<dc:creator>bixuan</dc:creator>
				<category><![CDATA[Bind]]></category>
		<category><![CDATA[运维小技巧]]></category>
		<category><![CDATA[geoip]]></category>

		<guid isPermaLink="false">http://www.ourlinux.net/?p=1450</guid>
		<description><![CDATA[HOWTO Implement GeoDNS using BIND &#38; MaxMind This HOWTO documents an elegant Linux BASH script that can be used to help configure BIND to be geo-aware. The script utilises the information contained within the freely downloadable GeoIP CSV file, published monthly, by MaxMind. No patching of the BIND source code is required for this to work (unlike other methods that [...]]]></description>
			<content:encoded><![CDATA[<h2>HOWTO Implement GeoDNS using BIND &amp; MaxMind</h2>
<p><strong>This HOWTO documents an <a href="http://phix.me/geodns/#script">elegant Linux BASH script</a> that can be used to help configure <a href="https://www.isc.org/software/bind" target="_blank">BIND</a> to be geo-aware. The script utilises the information contained within the <a href="http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip">freely downloadable GeoIP CSV file</a>, published monthly, by <a href="http://www.maxmind.com/" target="_blank">MaxMind</a>. No patching of the BIND source code is required for this to work (unlike <a href="http://www.caraytech.com/geodns/" target="_blank">other methods</a> that have been documented online) thus making it easier to manage GeoIP updates to BIND as and when MaxMind publish updated versions of their GeoIP CSV file or the <a href="https://www.isc.org/" target="_blank">ISC</a> release newer versions of BIND. If you are seeking to implement geo-aware DNS with BIND on the<a href="http://en.wikipedia.org/wiki/IPv6" target="_blank">IPv6 network</a>, you will probably find <a href="http://phix.me/geodns/#IPv6">this</a> extremely useful.</strong></p>
<h3>Licensing &amp; Copyright</h3>
<p><em>The copyrighted material on this page is made available to anyone wishing to use, modify, copy, or redistribute it subject to the terms and conditions of the <a href="http://www.gnu.org/licenses/gpl.html" target="_blank"><strong>GNU General Public License</strong></a>. The scripts published on this page are distributed in the hope that they will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the <a href="http://www.gnu.org/licenses/gpl.html" target="_blank"><strong>GNU General Public License</strong></a> for more details. For further information, write to the <a href="http://www.fsf.org/" target="_blank"><strong>Free Software Foundation</strong></a>, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.</em></p>
<h3><span style="color: #ff0000;">BUG FIX ANNOUNCEMENT</span></h3>
<p>If you have accessed this page <strong>before the 1st of January 2010</strong>, and thus are using these scripts as they were published on this page before this date, changes have since been made to them to address a couple of discovered issues.</p>
<ol>
<li>The first is a change to the <a href="http://phix.me/geodns/#script">fastest recursive script</a>. The change is nothing major but effectively reduces execution time slightly by splitting IP ranges when generating the <strong>GeoIP.acl</strong> file rather than splitting IP ranges when creating the CBE (Country,Begin,End) CSV file. The change is purely in relation to where the range splitting takes place, resulting in <strong>grep</strong> pattern matching against fewer lines, thus marginally reducing the execution time of the script.</li>
<li>The second fix has been made to all scripts and was discovered when noticing that the recursive <strong>awk</strong> function could not correctly split extremely large IP ranges, with an order of magnitude exceeding about 2<sup>31</sup>. For example, giving the script the range 0 to 2147483647 would result in it printing 0.0.0.0/<strong>0</strong> rather than 0.0.0.0/<strong>1</strong>. I located this issue to a rounding anomaly with the <strong>printf</strong> function within <strong>awk</strong> and the solution is to simply ensure that all occurrences of the logarithmic division calculation in each script are truncated to a whole number using the <strong>int</strong> function. This bug has probably not caused people too much grief because the ranges supplied within the MaxMind GeoIP CSV file are nowhere near a magnitude of 2<sup>31</sup> (the largest IP range listed as of writing is of magnitude 2<sup>26</sup>, representing the network 28.0.0.0/6 in the United States). Nevertheless, this was a bug and has now been fixed in the scripts published below.</li>
</ol>
<h3>Overview</h3>
<p>I was recently asked by my employer to bring our DNS in-house from <a href="http://www.ultradns.com/" target="_blank">UltraDNS</a> where we originally hosted all our domain names. Due to various requirements within the company, they were utilising UltraDNS&#8217;s geo-targetting feature to enable internet users in different areas of the world to resolve hosts on our domains to varying IP addresses, depending on the geographical (country) location of these users.</p>
<p>Having already been exposed to BIND&#8217;s <a href="http://oreilly.com/lpt/a/2152" target="_blank">views</a> feature some years ago, I googled on how it would be possible to make BIND geo-aware. There is not much documentation about this online but I found one such solution which involved <a href="http://www.caraytech.com/geodns/" target="_blank">patching the BIND source code</a>. All well and good but, in all honesty, this seemed like using a sledge hammer to crack a nut. Besides, our company does not like patching (hacking) source code unless there is a real requirement to do so as it normally entails maintenance by having to refit changes into revisions of the BIND source code as and when the ISC release newer versions of BIND.</p>
<p>I analysed the <a href="http://www.caraytech.com/geodns/" target="_blank">patching BIND</a> method further and the solution still uses two fundamental things to achieve a geo-aware DNS setup; BIND&#8217;s <a href="http://oreilly.com/lpt/a/2152" target="_blank">views</a> feature and the freely downloadable GeoIP data available from MaxMind. It was then I realised that to make BIND geo-aware, all that is required is to reformat the data in the MaxMind GeoIP CSV file into something which BIND likes, and will accept in its configuration file. The easiest and most manageable way to achieve this is by using the BIND <a href="http://www.zytrax.com/books/dns/ch7/acl.html" target="_blank">Access Control List</a> clause, but here lies the problem. The MaxMind GeoIP CSV file operates in <strong>IP ranges</strong> whereas BIND ACLs operate on <strong>IP networks</strong>, in classic net/mask notation. So, basically, I had to formulate a method to transform <strong>MaxMind IP ranges</strong> into <strong>BIND ACLs</strong>. This method is attainable by using the Linux BASH script(s) shown below.</p>
<p>The result is the automatic creation of a single and maintainable <strong>GeoIP.acl</strong> include file that can be instantly added into any already running BIND DNS server, without the requirement for source code patching and recompilation, producing a geo-aware production-ready DNS server in a matter of minutes.</p>
<h3>Linux BASH script(s) to fetch, unzip, reformat and generate the GeoIP.acl include file for BIND</h3>
<p>There are <strong>two different BASH scripts</strong> documented below which will generate the <strong>GeoIP.acl</strong> include file for BIND. The second is an improvement over the first but I&#8217;ve left it documented anyway as it was my original implementation. The first uses an <strong>iterative BASH loop</strong> (slower) whereas the second uses a <strong>recursive AWK function</strong> (much faster). Both achieve exactly the same thing by employing different programming constructs. <strong>For speed and efficiency, I recommend using the<a href="http://phix.me/geodns/#script">second recursive script</a>.</strong></p>
<p><span style="color: #ff0000;"><strong>NOTE:</strong> By default, some distributions of Linux use a non-GNU version of <strong>AWK</strong> which lacks the <strong>bitwise AND function</strong>. In this instance, <strong>GAWK</strong> must be installed (the GNU version of <strong>AWK</strong>) for the scripts below to function correctly (thanks to Ruben for pointing this out).</span></p>
<p>Each script will attempt to download the latest MaxMind GeoIP CSV file (which is actually a ZIP file). Once downloaded, it will use this file and reprocess it each time it is executed. Removing the ZIP file and then rerunning the script will force it to perform another fetch from MaxMind. Once the ZIP file has been fetched, each script will unzip it, reformat the enclosed GeoIP CSV file (taking several passes to do this if the iterative version is used) and then generate the file <strong>GeoIP.acl</strong>which is the include file that can be added into BIND&#8217;s configuration to make it geo-aware.</p>
<h4>Iterative Version (slowest)</h4>
<pre>#!/bin/bash

[ -f GeoIPCountryCSV.zip ] || wget -T 5 -t 1 <a href="http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip" rel="nofollow">http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip</a>
unzip GeoIPCountryCSV.zip || exit 1

echo -n "Creating initial CBE (Country,Begin,End) CSV file..."
awk -F \" '{print $10","$6","$8}' GeoIPCountryWhois.csv &gt; cbe0.csv
rm -f GeoIPCountryWhois.csv
echo -ne "DONE\nSplitting CBE CSV file..."

lc0=0; lc1=$(wc -l cbe0.csv | awk '{print $1}')

while [ $lc0 -lt $lc1 ]
do
  lc0=$lc1; echo -ne "\n$lc0\t"
  awk -F , '{m = 2^32-2^int(log($3-$2+1)/log(2)); n = and(m,$3); if (n == and(m,$2)) print; else printf "%s,%u,%u\n%s,%u,%u\n",$1,$2,n-1,$1,n,$3}' cbe0.csv &gt; cbe1.csv
  mv -f cbe1.csv cbe0.csv; lc1=$(wc -l cbe0.csv | awk '{print $1}')
  echo -ne "+$[$lc1-$lc0]\t"; [ $lc0 -lt $lc1 ] &amp;&amp; echo -n "OK"
done

echo -ne "DONE\nGenerating BIND GeoIP.acl file..."

(for c in $(awk -F , '{print $1}' cbe0.csv | sort -u)
do
  echo "acl \"$c\" {"
  grep "^$c," cbe0.csv | awk -F , '{printf "\t%u.%u.%u.%u/%u;\n",$2/2^24%256,$2/2^16%256,$2/2^8%256,$2%256,32-int(log($3-$2+1)/log(2))}'
  echo -e "};\n"
done) &gt; GeoIP.acl

rm -f cbe0.csv
echo "DONE"

exit 0</pre>
<h5>Here&#8217;s this script in action!</h5>
<pre>$ ./GeoIP.sh
--00:00:00--  <a href="http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip" rel="nofollow">http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip</a>
           =&gt; `GeoIPCountryCSV.zip'
Resolving geolite.maxmind.com... 64.246.48.99
Connecting to geolite.maxmind.com|64.246.48.99|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1,556,500 (1.5M) [application/zip]

100%[================================================================================&gt;] 1,556,500    820.41K/s

00:00:02 (818.35 KB/s) - `GeoIPCountryCSV.zip' saved [1556500/1556500]

Archive:  GeoIPCountryCSV.zip
  inflating: GeoIPCountryWhois.csv
Creating initial CBE (Country,Begin,End) CSV file...DONE
Splitting CBE CSV file...
106184  +31276  OK
137460  +23038  OK
160498  +11755  OK
172253  +6413   OK
178666  +3544   OK
182210  +1905   OK
184115  +949    OK
185064  +463    OK
185527  +202    OK
185729  +94     OK
185823  +38     OK
185861  +19     OK
185880  +5      OK
185885  +2      OK
185887  +0      DONE
Generating BIND GeoIP.acl file...DONE</pre>
<p><a name="script"></a></p>
<p><a name="script"></a></p>
<p><a name="script"></a></p>
<pre>#!/bin/bash

[ -f GeoIPCountryCSV.zip ] || wget -T 5 -t 1 <a href="http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip" rel="nofollow">http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip</a>
unzip GeoIPCountryCSV.zip || exit 1

echo -n "Creating CBE (Country,Begin,End) CSV file..."
awk -F \" '{print $10","$6","$8}' GeoIPCountryWhois.csv &gt; cbe.csv
rm -f GeoIPCountryWhois.csv
echo -ne "DONE\nGenerating BIND GeoIP.acl file..."

(for c in $(awk -F , '{print $1}' cbe.csv | sort -u)
do
  echo "acl \"$c\" {"
  grep "^$c," cbe.csv | awk -F , 'function s(b,e,l,m,n) {l = int(log(e-b+1)/log(2)); m = 2^32-2^l; n = and(m,e); if (n == and(m,b)) printf "\t%u.%u.%u.%u/%u;\n",b/2^24%256,b/2^16%256,b/2^8%256,b%256,32-l; else {s(b,n-1); s(n,e)}} s($2,$3)'
  echo -e "};\n"
done) &gt; GeoIP.acl

rm -f cbe.csv
echo "DONE"

exit 0</pre>
<h5>Here&#8217;s this script in action!</h5>
<pre>$ ./GeoIP.sh
--00:00:00--  <a href="http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip" rel="nofollow">http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip</a>
           =&gt; `GeoIPCountryCSV.zip'
Resolving geolite.maxmind.com... 64.246.48.99
Connecting to geolite.maxmind.com|64.246.48.99|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1,556,500 (1.5M) [application/zip]

100%[================================================================================&gt;] 1,556,500    820.41K/s

00:00:02 (818.35 KB/s) - `GeoIPCountryCSV.zip' saved [1556500/1556500]

Archive:  GeoIPCountryCSV.zip
  inflating: GeoIPCountryWhois.csv
Creating CBE (Country,Begin,End) CSV file...DONE
Generating BIND GeoIP.acl file...DONE</pre>
<p>Both of these scripts will generate the file <strong>GeoIP.acl</strong> in the current working directory which looks something like this:</p>
<pre>acl "A1" {
        64.46.32.0/23;
        64.46.35.0/24;
        64.46.40.64/26;
        64.46.42.0/23;
        64.46.47.0/24;
        66.38.243.0/24;
        67.15.183.0/25;
        69.10.130.128/26;
        69.10.139.0/25;
        69.10.140.192/26;

...

acl "GB" {
        2.6.190.56/29;
        9.20.0.0/17;
        12.129.72.32/29;
        23.0.0.0/9;
        25.0.0.0/8;
        32.58.57.0/29;
        32.58.58.0/28;
        32.58.59.0/29;
        32.60.34.96/27;
        51.0.0.0/8;

...

        217.204.159.96/29;
        217.204.159.104/30;
        217.204.159.112/28;
        217.204.159.128/25;
        217.204.160.0/19;
        217.204.192.0/18;
        217.205.0.0/16;
        217.206.0.0/15;
        217.237.189.240/29;
        217.243.204.144/29;
};

...

        217.194.132.0/24;
        217.194.145.144/29;
        217.194.146.192/26;
        217.194.147.240/28;
        217.194.149.32/28;
        217.194.149.168/29;
        217.194.156.0/26;
        217.194.157.48/28;
        217.194.157.144/29;
        217.194.157.168/29;
};</pre>
<h3>How do these scripts work?</h3>
<p>I wont go into the technicalities of how these scripts work (this is left as an exercise for the reader) but the first iterative script creates a new CSV file containing 3 fields (Country,Begin,End) and then repeatedly searches for and splits these IP ranges on network boundaries so we are left with a CSV file that has exactly the same coverage of IPs as before but has been processed so that the IP ranges reside on values that allow for each range to be expressed concisely in net/mask notation. The final part of the script then uses this CSV file to generate the <strong>GeoIP.acl</strong> include file.</p>
<p>The second recursive script achieves the same result faster by creating a new CSV file as before, containing 3 fields (Country,Begin,End), and then performing recursive range splitting &#8220;on the fly&#8221; within <strong>awk</strong> itself, for each country, to generate the <strong>GeoIP.acl</strong> include file.</p>
<p>Once either of these scripts have finished running, you can slot the newly created <strong>GeoIP.acl</strong> file straight into your existing BIND configuration file, by adding the line:</p>
<pre>include "/path/to/GeoIP.acl";</pre>
<p>to <strong>named.conf</strong>. It will then be possible to create custom geo-views within BIND, like this:</p>
<pre>view "north_america" {
  match-clients { US; CA; MX; };
  recursion no;
  zone "example555.com" {
    type master;
    file "pri/example555-north-america.db";
  };
};

view "south_america" {
  match-clients { AR; CL; BR; PY; PE; EC; CO; VE; BO; UY; };
  recursion no;
  zone "example555.com" {
    type master;
    file "pri/example555-south-america.db";
  };
};

view "other" {
  match-clients { any; };
  recursion no;
  zone "example555.com" {
    type master;
    file "pri/example555-other.db";
  };
};</pre>
<p>If you decide to cron these scripts within your BIND name server(s), do remember to reload named (normally achieved by running the command <strong>service named reload</strong> on RedHat/CentOS) so the new ACL definitions within the <strong>GeoIP.acl</strong> file are loaded into BIND&#8217;s memory.</p>
<h3>Summary</h3>
<p>I hope this article proves useful for others (that&#8217;s why I have documented it). Interestingly, my original implementation of this was by using a PHP script coupled with MySQL, loading the MaxMind CSV file into a database table, and then running SELECT, UPDATE and INSERT queries to split up the IP ranges. Whilst this worked, it depended on having PHP and MySQL installed and configured. The above scripts achieve exactly the same thing but only using BASH commands and utilities, such as <strong>awk</strong>,<strong>grep</strong> and <strong>sort</strong>, which in my view, is far cleaner!</p>
<p>Incidently, it is actually possible to produce the <strong>GeoIP.acl</strong> file without using <strong>grep</strong> or <strong>any intermediate CSV file</strong> (shown below). These scripts may be used instead but with markedly longer execution times and, because of this, an echo statement, outputting the current country code to standard error, has been introduced into the main loop to give an indication of progress while the script is running.</p>
<h4>Recursive Versions (smallest)</h4>
<pre>#!/bin/bash

[ -f GeoIPCountryCSV.zip ] || wget -T 5 -t 1 <a href="http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip" rel="nofollow">http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip</a>
unzip GeoIPCountryCSV.zip || exit 1

(for c in $(awk -F \" '{print $10}' GeoIPCountryWhois.csv | sort -u)
do
  echo "$c" &gt;&amp;2
  echo "acl \"$c\" {"
  awk -F \" 'function s(b,e,l,m,n) {l = int(log(e-b+1)/log(2)); m = 2^32-2^l; n = and(m,e); if (n == and(m,b)) printf "\t%u.%u.%u.%u/%u;\n",b/2^24%256,b/2^16%256,b/2^8%256,b%256,32-l; else {s(b,n-1); s(n,e)}} c == $10 {s($6,$8)}' c=$c GeoIPCountryWhois.csv
  echo -e "};\n"
done) &gt; GeoIP.acl

rm -f GeoIPCountryWhois.csv

exit 0</pre>
<p>We can marginally reduce the execution time of the above script by adjusting its <strong>awk</strong> line to match the current country using a regular expression, as opposed to setting the <strong>awk</strong> variable <em>c</em> and then checking if <em>c == $10</em>, as follows:</p>
<pre>#!/bin/bash

[ -f GeoIPCountryCSV.zip ] || wget -T 5 -t 1 <a href="http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip" rel="nofollow">http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip</a>
unzip GeoIPCountryCSV.zip || exit 1

(for c in $(awk -F \" '{print $10}' GeoIPCountryWhois.csv | sort -u)
do
  echo "$c" &gt;&amp;2
  echo "acl \"$c\" {"
  awk -F \" 'function s(b,e,l,m,n) {l = int(log(e-b+1)/log(2)); m = 2^32-2^l; n = and(m,e); if (n == and(m,b)) printf "\t%u.%u.%u.%u/%u;\n",b/2^24%256,b/2^16%256,b/2^8%256,b%256,32-l; else {s(b,n-1); s(n,e)}} '"/,\"$c\",/"' {s($6,$8)}' GeoIPCountryWhois.csv
  echo -e "};\n"
done) &gt; GeoIP.acl

rm -f GeoIPCountryWhois.csv

exit 0</pre>
<p>Do note, however, that I personally prefer the previous <strong>grep</strong> method as it is much faster than these two scripts because it initially reformats the data within the CSV file into something that allows for fast regex pattern matching on the country field (by moving this field to the beginning of each line) allowing <strong>awk</strong> to take care of the more complicated task of <em>IP range splitting</em> that operates on the <strong>b</strong>egin (2nd) and <strong>e</strong>nd (3rd) integer IP fields.<a name="IPv6"></a></p>
<p><a name="IPv6"></a></p>
<p><a name="IPv6"></a>Over the last decade, IPv6 has become more and more mainstream. As much as I have not seen any requirement for geo-aware DNS serving on the IPv6 network, I would imagine this will gradually become needed. BIND already handles IPv6 addresses within its ACLs so I have published further scripts below that allow the creation of a<strong>GeoIPv6.acl</strong> include file containing IPv6 net/mask entries, using the <a href="http://geolite.maxmind.com/download/geoip/database/" target="_blank"><strong>freely downloadable GeoIPv6 CSV file</strong></a> available from MaxMind.</p>
<p>It was a challenge to come up with a working solution using the same principles as in the above scripts, but across a much larger address space. This is because IPv6 uses a 128 bit address space, compared to IPv4 being only 32 bits. The scripts above get away with using simple BASH utilities such as <strong>awk</strong> for doing the necessary IP range splitting with 32 bits but, as I found out, <strong>awk</strong> is unable to handle numbers which are up in the realms of 64 bits and beyond. So I&#8217;ve had to pull various different Linux utilities into play here to achieve this.</p>
<p>In order to handle large numbers up to and beyond 64 bits in magnitude, one has to look at other programming languages and the libraries they offer. After evaluating today&#8217;s available languages like Python (which handles large numbers out the box) and PHP (which can only handle large numbers with an additional library installed), I decided to go with Perl. Perl has, on most standard installs, a <a href="http://perldoc.perl.org/bignum.html" target="_blank"><strong>bignum</strong></a> library that is available and ready to go. This library is transparent and as soon as it is included into a script, all number processing will automatically use it. It has all the necessary operations like bitwise AND that the above scripts make use of. However, when writing the Perl script below, I ran into an inconsistency with the <strong>log</strong> function whilst using the <strong>bignum</strong> library and, for anything above 64 bits,<strong>bignum</strong> also exhibits <em>major</em> rounding anomalies. To avoid this curveball, I decided to bring the common Linux arbitrary precision calculator <strong>bc</strong> into play to take over both of these roles. Together, Perl and <strong>bc</strong> offer the accuracy and speed required to split decimal IP ranges with magnitudes of 64 bits and beyond.</p>
<p>So, here are the scripts. The first script is, as before, a standard BASH script (called <strong>GeoIPv6.sh</strong>). It is much the same as before but rather than piping the filtered <strong>grep</strong> lines to <strong>awk</strong>, it pipes them to a newly created Perl script instead. It also contains some further adjustments at the top to download the latest GeoIPv6 CSV file from MaxMind&#8217;s servers, as well as an optional pipe of the Perl script output to <strong>sed</strong> to abbreviate IPv6 addresses to their &#8220;double-colon (::) notation&#8221; equivalent.</p>
<pre>#!/bin/bash

d=http://geolite.maxmind.com/download/geoip/database/
f=$(wget -qT 5 -t 1 -O- $d | egrep -o 'GeoIPv6-[0-9]{8}\.csv\.gz' | head -1)
[ -z "$f" ] &amp;&amp; exit 1; [ -f $f ] || wget -T 5 -t 1 $d$f || exit 1

echo -n "Creating CBE (Country,Begin,End) CSV file..."
gunzip -c $f | awk -F \" '{print $10","$6","$8}' &gt; cbe.csv
echo -e "DONE\nGenerating BIND GeoIPv6.acl file..."

(for c in $(awk -F , '{print $1}' cbe.csv | sort -u)
do
  echo "$c" &gt;&amp;2
  echo "acl \"${c}v6\" {"
  grep "^$c," cbe.csv | ./GeoIPv6.pl | sed 's \(:0\)\+/ ::/ '
  echo -e "};\n"
done) &gt; GeoIPv6.acl

rm -f cbe.csv
echo "DONE"

exit 0</pre>
<p>The Perl script I have called <strong>GeoIPv6.pl</strong>, with the following contents:</p>
<pre>#!/usr/bin/perl

use strict;
use bignum;
use IPC::Open2; open2(*BCOUT,*BCIN,'bc -l');

sub rs {
  my ($b,$e) = @_;
  print BCIN "scale=40; l($e-$b+1)/l(2)\n";
  my ($l) = split('\.',&lt;BCOUT&gt;);
  my $m = 2**128-2**$l;
  my $n = $m &amp; $e;
  if ($n == ($m &amp; $b)) {
    my @x; for (my $p = 112; $p &gt; 0; $p -= 16) {
      print BCIN "scale=0; $b/2^$p\n";
      push(@x,&lt;BCOUT&gt;%65536);
    }
    printf "\t%x:%x:%x:%x:%x:%x:%x:%x/%u;\n",$x[0],$x[1],$x[2],$x[3],$x[4],$x[5],$x[6],$b%65536,128-$l;
  } else {
    rs($b,$n-1); rs($n,$e);
  }
}

while (&lt;STDIN&gt;) {chomp($_); my ($c,$b,$e) = split(',',$_); rs($b,$e)}</pre>
<p>This Perl script effectively reads from standard input in precisely the same way as the original <strong>awk</strong> script does (expecting each line to be in the format of a CBE (Country,Begin,End) CSV file) but, unlike <strong>awk</strong>, can perform IP range splitting on 128 bit decimal numbers, printing IPv6 net/mask entries to standard output. Note the use of a dual pipe to the Linux arbitrary precision calculator <strong>bc</strong> to manage the logarithmic division calculation and also to accurately truncate values before they are passed to the <strong>printf</strong> function (done by a small <em>for loop</em> that places these entries into an array). Most importantly, note that we must increase the default <strong>scale</strong>of <strong>20</strong> within <strong>bc</strong> to at least <strong>40</strong> to be able to accurately cope with the logarithmic division calculation. Observe:</p>
<pre>$ echo 'l(2^128-1)/l(2)' | bc -l
128.00000000000000000132
$ echo 'scale=20; l(2^128-1)/l(2)' | bc -l
128.00000000000000000132
$ echo 'scale=39; l(2^128-1)/l(2)' | bc -l
128.000000000000000000000000000000000000088
$ echo 'scale=40; l(2^128-1)/l(2)' | bc -l
127.9999999999999999999999999999999999999956</pre>
<p>The reason we also choose to open a dual pipe to <strong>bc</strong> within Perl is to stop the forking of a separate <strong>bc</strong> process each time we need to perform a division calculation (forking a new process is costly in terms of CPU time). By opening up a dual pipe to a single persistent <strong>bc</strong> process, we can simply throw and retrieve each calculation into and out off it quickly. The <a href="http://perldoc.perl.org/IPC/Open2.html" target="_blank"><strong>IPC::Open2</strong></a> Perl module is required to do dual pipes and this may need to be installed on your system.</p>
<p>Once these two scripts have been created, it will be possible to run <strong>./GeoIPv6.sh</strong> to generate the <strong>GeoIPv6.acl</strong> include file for BIND. Note that the execution time here will be far greater than before, since we are using Perl with <strong>bignum</strong> support, and passing division calculations to a separate persistent <strong>bc</strong> process. As such, the BASH script has been modified to output the current country code being processed to standard error to indicate progress. Once the script has completed execution, the <strong>GeoIPv6.acl</strong> include file will have been created in the current working directory, which looks something like this:</p>
<pre>acl "ADv6" {
        2001:4df8::/32;
};

acl "AEv6" {
        2001:8f8::/32;
        2a00:d30::/32;
        2a00:f28::/32;
};

acl "AMv6" {
        2001:1bb0::/32;
        2001:4d00::/32;
        2a00:f38::/32;
        2a00:1290::/32;
        2a00:1500::/32;
        2a02:d18::/32;

...

acl "GBv6" {
        2001:630::/32;
        2001:678:4::/47;
        2001:67c:18::/48;
        2001:67c:90::/48;
        2001:67c:b4::/48;
        2001:67c:c0::/48;
        2001:67c:d4::/48;
        2001:6f8::/32;
        2001:710::/32;
        2001:768::/32;

...

        2a02:ce8::/32;
        2a02:da0::/32;
        2a02:df8::/32;
        2a02:e38::/32;
        2a02:e68::/32;
        2a02:eb0::/32;
        2a02:ef8::/32;
        2a02:f70::/32;
        2a02:fb0::/32;
        2a02:fb8::/32;
};

...

        2001:43d8::/32;
        2001:43f8:20::/48;
        2001:43f8:30::/48;
        2001:43f8:40::/48;
        2001:43f8:50::/48;
        2001:43f8:70::/45;
        2001:43f8:90::/48;
        2001:43f8:a0::/48;
        2001:43f8:d0::/48;
};

acl "ZWv6" {
        2001:42b0::/32;
};</pre>
<h3>Performance versus Maintainability (pros/cons for/against this ACL method compared to BIND source code patching)</h3>
<p>John &#8216;Warthog9&#8242; Hawley, the chief administrator of <a href="http://www.kernel.org/" target="_blank">http://www.kernel.org</a> (a high-traffic site which implemented BIND GeoDNS on the 19th of September 2008 via patching), recently contacted me about this HOWTO with some interesting points concerning the implications of using this ACL method over BIND source code patching. I will briefly discuss this here, as it will affect which route you take when implementing GeoDNS within BIND.</p>
<p>In a nutshell, patching BIND for GeoDNS support results in a DNS server that can answer queries at an extremely rapid rate compared with this ACL method (I have confirmed this; it is quite easy to test; see below). This is because the MaxMind binary database is a <a href="http://en.wikipedia.org/wiki/Binary_search_tree" target="_blank">binary search tree</a> data structure, and so the worst case maximum number of lookups required to determine the country location of an IPv4 address will be 32 iterations (and most times, far less than this). Similary, for their IPv6 binary database, this number changes to 128 iterations. As you can imagine, patching the MaxMind GeoIP C library directly into BIND to achieve GeoDNS will result in a server which is able to process, lookup and answer DNS queries with very few CPU cycles. As such, if your DNS servers are high-traffic servers, responding to many DNS requests per second, it would be advisable to go with the source code patching route.</p>
<p>Alternatively, if maintainability is of more importance to you, the ACL method described in this HOWTO is still a viable option, but with the consequence of a substantial performance hit. According to John (who has been chatting with Paul Vixie, the primary author and architect of BIND until release 8), the ACL feature was never designed with the intention to store and hold the number of ACL entries that the above scripts generate, for GeoDNS purposes. This I can believe, as the scripts above (for IPv4) produce an ACL definition file containing over 200,000 ACL entries, which BIND has to load and subsequently store in its memory once launched. I am not fully aware of the data structures used within BIND to store ACLs, but they will be far less efficient than the simple binary search tree that MaxMind offer with their binary GeoIP databases. It is for this reason that the ACL method described in this HOWTO will result in a far slower DNS server, depending on how many views you create and the ACLs assigned to them.</p>
<p>To give you an idea of just how much of a performance hit this ACL method induces, I have a small low-power server on my network running a CentaurHauls VIA Nehemiah CPU @ 1 GHz (2000 BogoMips) with a 192.168.0.0/16 IP address (see <a href="http://www.faqs.org/rfcs/rfc1918.html" target="_blank">RFC 1918</a>; all other hosts on my LAN are in this network so none of them would be a match in <em>any</em> of the above ACLs). When loading BIND with the GeoIP.acl include file, and creating a catch-all view that matches any client (not using <em>any</em> of the ACLs in the GeoIP.acl include file), the DNS response time tends to be about 2 ms. If, however, another view is created before this catch-all one in named.conf, and the clause:</p>
<pre>match-clients { A1; A2; AD; AE; AF; AG; AI; AL; AM; AN; ... VI; VN; VU; WF; WS; YE; YT; ZA; ZM; ZW; };</pre>
<p>
is added to this view (forcing it to attempt a match across every single ACL definition inside the GeoIP.acl file), the response time sores to around 85 ms. In other words, the amount of work that we have now asked BIND to do, in order for it to verify if any of the ACLs are a match for a client with IP address in 192.168.0.0/16, has resulted in it slowing down by a factor of 40 (a rough guestimate figure only) which is a substantial performance hit that needs to be considered. For this reason, if using the ACL method described in this HOWTO, try and limit the number of views you create and the number of ACLs assigned to them as this will lower the amount of work BIND has to do when answering DNS queries made to it.</p>
<p>
In short, you should determine if speed (source code patching) or maintainability (ACL include file) is of more importance to you and be fully aware of the pros and cons of each method of GeoDNS implementation within BIND. As a systems administrator, use your head to decide which method to go with. As <a href="http://www.kernel.org/" target="_blank">http://www.kernel.org</a> is a global site, ranked around 10,000 across all sites on the internet (according to <a href="http://www.alexa.com/siteinfo/kernel.org" target="_blank">Alexa</a>), John has done the right thing and gone with the patching method when deploying BIND GeoDNS servers for Kernel.org.</p>
<p>From：<a href="http://phix.me/geodns/">http://phix.me/geodns/</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.ourlinux.net/2011/02/17/1450.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

