﻿<?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>单调专注的明王子 &#187; LINUX</title>
	<atom:link href="http://www.uyun.com/category/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.uyun.com</link>
	<description></description>
	<lastBuildDate>Thu, 29 Apr 2010 17:09:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0-beta1</generator>
		<item>
		<title>Linux 系统查看流量的命令</title>
		<link>http://www.uyun.com/2010/01/linux-system-see-the-order-flow/</link>
		<comments>http://www.uyun.com/2010/01/linux-system-see-the-order-flow/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 07:56:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[LINUX]]></category>

		<guid isPermaLink="false">http://www.uyun.com/?p=520</guid>
		<description><![CDATA[事实上ifconfig 这个命令就提供了在启动网卡以来的总流量，是以B也就是位计算的。 结合watch命令即可看到某个时间间隔内的流量变化，很cool的。完整命令如下： watch -n 1 &#8216;ifconfig &#124;grep byte&#8217; 该命令会自动刷新，流量统计，非常好。可以在 保存到/root/liuliang.sh 。赋权 chmod  x+  /root/liuliang.sh 日后就可以通过 /root/liuliang.sh 来看流量了，爽！ 效果图： RX 就是接收数据，TX就是发送的数据。上面的图就是服务器接收了14.7G的数据包，发送了11.5G]]></description>
			<content:encoded><![CDATA[<p>事实上ifconfig 这个命令就提供了在启动网卡以来的总流量，是以B也就是位计算的。</p>
<p>结合watch命令即可看到某个时间间隔内的流量变化，很cool的。完整命令如下：</p>
<blockquote><p><strong>watch -n 1 &#8216;ifconfig |grep byte&#8217;<br />
</strong></p></blockquote>
<p>该命令会自动刷新，流量统计，非常好。可以在 保存到/root/liuliang.sh 。赋权 chmod  x+  /root/liuliang.sh</p>
<p>日后就可以通过 /root/liuliang.sh 来看流量了，爽！</p>
<p>效果图：</p>
<p><a href="http://www.uyun.com/wp-content/uploads/2010/01/watch-n-1.png"><img class="alignnone size-full wp-image-526" title="watch-n-1" src="http://www.uyun.com/wp-content/uploads/2010/01/watch-n-1.png" alt="" width="643" height="74" /></a></p>
<p>RX 就是接收数据，TX就是发送的数据。上面的图就是服务器接收了14.7G的数据包，发送了11.5G</p>
]]></content:encoded>
			<wfw:commentRss>http://www.uyun.com/2010/01/linux-system-see-the-order-flow/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rewrite大全之DNS 负载均衡</title>
		<link>http://www.uyun.com/2007/01/rewrite-daquan-the-dns-load-balancing/</link>
		<comments>http://www.uyun.com/2007/01/rewrite-daquan-the-dns-load-balancing/#comments</comments>
		<pubDate>Mon, 15 Jan 2007 03:11:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[LINUX]]></category>

		<guid isPermaLink="false">http://www.uyun.com/index.php/315</guid>
		<description><![CDATA[DNS 负载均衡 一种成熟的基于DNS的负载均衡方法是使用http://www.stanford.edu/~schemers/docs/lbnamed/lbnamed.html的lbnamed程序，它是一个Perl 5程序，带有若干辅助工具，实现了真正的基于DNS的负载均衡。 代理吞吐循环(Proxy Throughput Round-Robin) 这是一个使用mod_rewrite及其代理吞吐特性的方法。首先，在DNS记录中，将www0.foo.com固定为www.foo.com，如下： 代码: www IN CNAME www0.foo.com. 其次，将www0.foo.com转换为一个专职代理服务器，即，由这个机器把所有到来的URL通过内部代理分散到另外5个服务器(www1-www5)。为此，必须建立一个规则集，对所有URL调用一个负载均衡脚本lb.pl。 代码: RewriteEngine on RewriteMap lb prg:/path/to/lb.pl RewriteRule ^/(. )$ $ [P,L] 以下是lb.pl: 代码: #!/path/to/perl ## ## lb.pl &#8212; load balancing script ## $&#124; = 1; $name = &#8220;www&#8221;; # the hostname base $first = 1; # the first server (not 0 [...]]]></description>
			<content:encoded><![CDATA[<p>DNS 负载均衡<br />
一种成熟的基于DNS的负载均衡方法是使用<a target="_blank" href="http://www.stanford.edu/~schemers/docs/lbnamed/lbnamed.html">http://www.stanford.edu/~schemers/docs/lbnamed/lbnamed.html</a>的lbnamed程序，它是一个Perl 5程序，带有若干辅助工具，实现了真正的基于DNS的负载均衡。</p>
<p>代理吞吐循环(Proxy Throughput Round-Robin)<br />
这是一个使用mod_rewrite及其代理吞吐特性的方法。首先，在DNS记录中，将www0.foo.com固定为<a target="_blank" href="http://www.foo.com/">www.foo.com</a>，如下：</p>
<p>代码:<br />
www IN CNAME www0.foo.com.</p>
<p>其次，将www0.foo.com转换为一个专职代理服务器，即，由这个机器把所有到来的URL通过内部代理分散到另外5个服务器(www1-www5)。为此，必须建立一个规则集，对所有URL调用一个负载均衡脚本lb.pl。</p>
<p>代码:<br />
RewriteEngine on<br />
RewriteMap lb prg:/path/to/lb.pl<br />
RewriteRule ^/(. )$ $ [P,L]</p>
<p>以下是lb.pl:</p>
<p>代码:<br />
#!/path/to/perl<br />
##<br />
## lb.pl &#8212; load balancing script<br />
##</p>
<p>$| = 1;</p>
<p>$name = &#8220;www&#8221;; # the hostname base<br />
$first = 1; # the first server (not 0 here, because 0 is myself)<br />
$last = 5; # the last server in the round-robin<br />
$domain = &#8220;foo.dom&#8221;; # the domainname</p>
<p>$cnt = 0;<br />
while () {<br />
$cnt = (($cnt 1) % ($last 1-$first));<br />
$server = sprintf(&#8220;%s%d.%s&#8221;, $name, $cnt $first, $domain);<br />
print &#8220;http://$server/$_&#8221;;<br />
}</p>
<p>##EOF##</p>
<p>最后的说明：这样有用吗？www0.foo.com似乎也会超载呀？答案是：没错，它的确会超载，但是它超载的仅仅是简单的代理吞吐请求！所有诸如SSI、CGI、ePerl等等的处理完全是由其他机器完成的，这个才是要点。<br />
硬件/TCP循环<br />
还有一个硬件解决方案。Cisco有一个叫LocalDirector的东西，实现了TCP/IP层的负载均衡，事实上，它是一个位于网站集群前端的电路级网关。如果你有足够资金而且的确需要高性能的解决方案，那么可以用这个。</p>
<p>反向代理<br />
说明:<br />
&#8230;<br />
方案:<br />
代码:<br />
##<br />
## apache-rproxy.conf &#8212; Apache configuration for Reverse Proxy Usage<br />
##</p>
<p># server type<br />
ServerType standalone<br />
Listen 8000<br />
MinSpareServers 16<br />
StartServers 16<br />
MaxSpareServers 16<br />
MaxClients 16<br />
MaxRequestsPerChild 100</p>
<p># server operation parameters<br />
KeepAlive on<br />
MaxKeepAliveRequests 100<br />
KeepAliveTimeout 15<br />
Timeout 400<br />
IdentityCheck off<br />
HostnameLookups off</p>
<p># paths to runtime files<br />
PidFile /path/to/apache-rproxy.pid<br />
LockFile /path/to/apache-rproxy.lock<br />
ErrorLog /path/to/apache-rproxy.elog<br />
CustomLog /path/to/apache-rproxy.dlog &#8220;%t %h -&gt; %e URL: %U&#8221;</p>
<p># unused paths<br />
ServerRoot /tmp<br />
DocumentRoot /tmp<br />
CacheRoot /tmp<br />
RewriteLog /dev/null<br />
TransferLog /dev/null<br />
TypesConfig /dev/null<br />
AccessConfig /dev/null<br />
ResourceConfig /dev/null</p>
<p># speed up and secure processing</p>
<p>Options -FollowSymLinks -SymLinksIfOwnerMatch<br />
AllowOverride None</p>
<p># the status page for monitoring the reverse proxy</p>
<p>SetHandler server-status</p>
<p># enable the URL rewriting engine<br />
RewriteEngine on<br />
RewriteLogLevel 0</p>
<p># define a rewriting map with value-lists where<br />
# mod_rewrite randomly chooses a particular value<br />
RewriteMap server rnd:/path/to/apache-rproxy.conf-servers</p>
<p># make sure the status page is handled locally<br />
# and make sure no one uses our proxy except ourself<br />
RewriteRule ^/apache-rproxy-status.* &#8211; [L]<br />
RewriteRule ^(http|ftp)://.* &#8211; [F]</p>
<p># now choose the possible servers for particular URL types<br />
RewriteRule ^/(.*.(cgi|shtml))$ to://$/ [S=1]<br />
RewriteRule ^/(.*)$ to://$/</p>
<p># and delegate the generated URL by passing it<br />
# through the proxy module<br />
RewriteRule ^to://([^/] )/(.*) <a target="_blank" href="http:///">http:///</a> [E=SERVER:,P,L]</p>
<p># and make really sure all other stuff is forbidden<br />
# when it should survive the above rules&#8230;<br />
RewriteRule .* &#8211; [F]</p>
<p># enable the Proxy module without caching<br />
ProxyRequests on<br />
NoCache *</p>
<p># setup URL reverse mapping for redirect reponses<br />
ProxyPassReverse / <a target="_blank" href="http://www1.foo.dom/">http://www1.foo.dom/</a><br />
ProxyPassReverse / <a target="_blank" href="http://www2.foo.dom/">http://www2.foo.dom/</a><br />
ProxyPassReverse / <a target="_blank" href="http://www3.foo.dom/">http://www3.foo.dom/</a><br />
ProxyPassReverse / <a target="_blank" href="http://www4.foo.dom/">http://www4.foo.dom/</a><br />
ProxyPassReverse / <a target="_blank" href="http://www5.foo.dom/">http://www5.foo.dom/</a><br />
ProxyPassReverse / <a target="_blank" href="http://www6.foo.dom/">http://www6.foo.dom/</a></p>
<p>##<br />
## apache-rproxy.conf-servers &#8212; Apache/mod_rewrite selection table<br />
##</p>
<p># list of backend servers which serve static<br />
# pages (HTML files and Images, etc.)<br />
static www1.foo.dom|www2.foo.dom|www3.foo.dom|www4.foo.dom</p>
<p># list of backend servers which serve dynamically<br />
# generated page (CGI programs or mod_perl scripts)<br />
dynamic www5.foo.dom|www6.foo.dom</p>
]]></content:encoded>
			<wfw:commentRss>http://www.uyun.com/2007/01/rewrite-daquan-the-dns-load-balancing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rewrite大全之虚拟用户主机</title>
		<link>http://www.uyun.com/2007/01/rewrite-of-the-virtual-user-hosts-daquan/</link>
		<comments>http://www.uyun.com/2007/01/rewrite-of-the-virtual-user-hosts-daquan/#comments</comments>
		<pubDate>Mon, 15 Jan 2007 03:10:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[LINUX]]></category>

		<guid isPermaLink="false">http://www.uyun.com/index.php/314</guid>
		<description><![CDATA[虚拟用户主机 说明: 如果需要为用户username支持一个www.username.host.domain.com的主页，但不是用在此机器上建虚拟主机的方法，而是用仅在此机器上增加一个DNS记录的方法实现。 方案: 对HTTP/1.0的请求，这是无法实现的；但是对HTTP/1.1的在HTTP头中包含有主机名的请求，可以用以下规则集来内部地重写http://www.username.host.com/anypath为/home/username/anypath： 代码: RewriteEngine on RewriteCond % ^www.[^.] .host.com$ RewriteRule ^(. ) % [C] RewriteRule ^www.([^.] ).host.com(.*) /home/ 为外来访问者重定向宿主目录 说明: 对不是来自本地域ourdomain.com的外来访问者的请求，重定向其宿主目录URL到另一个网站服务器www.somewhere.com，有时这种做法也会用在虚拟主机的上下文中。 方案: 只须一个重写条件: 代码: RewriteEngine on RewriteCond % !^. .ourdomain.com$ RewriteRule ^(/~. ) http://www.somewhere.com/ [R,L] 重定向失败的URL到其他网站服务器 说明: 如何重写URL以重定向对网站服务器A的失败请求到服务器B，是一个常见的问题。一般，可以用Perl写的CGI脚本通过ErrorDocument来解决，此外，还有mod_rewrite方案。但是须注意，这种方法的执行效率不如用ErrorDocument的CGI脚本! 方案: 第一种方案，有最好的性能而灵活性欠佳，出错概率小所以安全: 代码: RewriteEngine on RewriteCond /your/docroot/% !-f RewriteRule ^(. ) http://webserverB.dom/ 但是其问题在于，它只对位于DocumentRoot中的页面有效。虽然可以增加更多的条件(比如同时还处理宿主目录，等等)，但是还有一个更好的方法： 代码: [...]]]></description>
			<content:encoded><![CDATA[<p>虚拟用户主机<br />
说明:<br />
如果需要为用户username支持一个<a target="_blank" href="http://www.username.host.domain.com/">www.username.host.domain.com</a>的主页，但不是用在此机器上建虚拟主机的方法，而是用仅在此机器上增加一个DNS记录的方法实现。</p>
<p>方案:<br />
对HTTP/1.0的请求，这是无法实现的；但是对HTTP/1.1的在HTTP头中包含有主机名的请求，可以用以下规则集来内部地重写<a target="_blank" href="http://www.username.host.com/anypath">http://www.username.host.com/anypath</a>为/home/username/anypath：</p>
<p>代码:<br />
RewriteEngine on<br />
RewriteCond % ^www.[^.] .host.com$<br />
RewriteRule ^(. ) % [C]<br />
RewriteRule ^<a target="_blank" href="http://www.(/">www.(</a>[^.] ).host.com(.*) /home/</p>
<p>为外来访问者重定向宿主目录<br />
说明:<br />
对不是来自本地域ourdomain.com的外来访问者的请求，重定向其宿主目录URL到另一个网站服务器<a target="_blank" href="http://www.somewhere.com/">www.somewhere.com</a>，有时这种做法也会用在虚拟主机的上下文中。</p>
<p>方案:<br />
只须一个重写条件:</p>
<p>代码:<br />
RewriteEngine on<br />
RewriteCond % !^. .ourdomain.com$<br />
RewriteRule ^(/~. ) <a target="_blank" href="http://www.somewhere.com/">http://www.somewhere.com/</a> [R,L]</p>
<p>重定向失败的URL到其他网站服务器<br />
说明:<br />
如何重写URL以重定向对网站服务器A的失败请求到服务器B，是一个常见的问题。一般，可以用Perl写的CGI脚本通过ErrorDocument来解决，此外，还有mod_rewrite方案。但是须注意，这种方法的执行效率不如用ErrorDocument的CGI脚本!</p>
<p>方案:<br />
第一种方案，有最好的性能而灵活性欠佳，出错概率小所以安全:</p>
<p>代码:<br />
RewriteEngine on<br />
RewriteCond /your/docroot/% !-f<br />
RewriteRule ^(. ) <a target="_blank" href="http://webserverb.dom/">http://webserverB.dom/</a></p>
<p>但是其问题在于，它只对位于DocumentRoot中的页面有效。虽然可以增加更多的条件(比如同时还处理宿主目录，等等)，但是还有一个更好的方法：</p>
<p>代码:<br />
RewriteEngine on<br />
RewriteCond % !-U<br />
RewriteRule ^(. ) <a target="_blank" href="http://webserverb.dom/">http://webserverB.dom/</a></p>
<p>这种方法使用了mod_rewrite提供的“向前参照(look-ahead)”的功能，是一种对所有URL类型都有效而且安全的方法。但是，对网站服务器的性能会有影响，所以如果网站服务器有一个强大的CPU，那就用这个方法。而在慢速机器上，可以用第一种方法，或者用性能更好的 ErrorDocument CGI脚本。</p>
<p>扩展的重定向<br />
说明:<br />
有时候，我们会需要更多的对重定向URL的(有关字符转义机制方面的)控制。通常，Apache内核中的URL转义函数uri_escape()同时还会对anchor转义，即，类似&#8221;url#anchor&#8221;的URL，因此，你不能用mod_rewrite对此类URL直接重定向。那么如何实现呢?</p>
<p>方案:<br />
必须用NPH-CGI脚本使它自己重定向，因为对NPH(non-parseable headers [无须解析的HTTP头])不会发生转义操作。首先，在针对服务器的配置中(应该位于所有重写规则的最后)，引入一种新的URL类型xredirect:：</p>
<p>代码:<br />
RewriteRule ^xredirect. ) /path/to/nph-xredirect.cgi/<br />
[T=application/x-httpd-cgi,L]</p>
<p>以强制所有带xredirect:前缀的URL被传送到如下的nph-xredirect.cgi程序：</p>
<p>代码:<br />
#!/path/to/perl<br />
##<br />
## nph-xredirect.cgi &#8212; NPH/CGI script for extended redirects<br />
## Copyright (c) 1997 Ralf S. Engelschall, All Rights Reserved.<br />
##</p>
<p>$| = 1;<br />
$url = $ENV;</p>
<p>print &#8220;HTTP/1.0 302 Moved Temporarily<br />
&#8220;;<br />
print &#8220;Server: $ENV<br />
&#8220;;<br />
print &#8220;Location: $url<br />
&#8220;;<br />
print &#8220;Content-type: text/html<br />
&#8220;;<br />
print &#8221;<br />
&#8220;;<br />
print &#8221;<br />
&#8220;;<br />
print &#8221;<br />
&#8220;;<br />
print &#8221;<br />
&#8220;;<br />
print &#8221;<br />
&#8220;;<br />
print &#8221;<br />
&#8220;;<br />
print &#8221;<br />
Moved Temporarily (EXTENDED)</p>
<p>&#8220;;<br />
print &#8220;The document has moved here.</p>
<p>&#8220;;<br />
print &#8221;<br />
&#8220;;<br />
print &#8221;<br />
&#8220;;</p>
<p>##EOF##</p>
<p>这是一种可以重定向所有URL类型的方法，包括不被mod_rewrite直接支持的类型。所以，还可以这样重定向news:newsgroup：</p>
<p>代码:<br />
RewriteRule ^anyurl xredirect:news:newsgroup</p>
<p>注意：无须对上述规则加[R]或[R,L]，因为xredirect:会在稍后被其特殊的传送规则扩展。<br />
文档访问的多路复用<br />
说明:<br />
你知道<a target="_blank" href="http://www.perl.com/CPAN">http://www.perl.com/CPAN</a>的CPAN(Comprehensive Perl Archive Network)吗？它实现了一个重定向以提供，全世界的CPAN镜像中离访问者最近的一个FTP站点，也可以称之为FTP访问多路复用服务。CPAN是通过CGI脚本实现的，那么用mod_rewrite如何实现呢？</p>
<p>方案:<br />
首先，我们注意到mod_rewrite从3.0.0版本开始，还可以重写&#8221;ftp:&#8221;类型。其次，对客户端顶级域名的路径最近的求取可以用RewriteMap实现。利用链式规则集，并用顶级域名作为查找多路复用地图的键，可以这样做：</p>
<p>代码:<br />
RewriteEngine on<br />
RewriteMap multiplex txt:/path/to/map.cxan<br />
RewriteRule ^/CxAN/(.*) %:: [C]<br />
RewriteRule ^. .([a-zA-Z] ):.*)$ $ [R,L]</p>
<p>##<br />
## map.cxan &#8212; Multiplexing Map for CxAN<br />
##</p>
<p>de <a target="_blank" href="ftp://ftp.cxan.de/CxAN/">ftp://ftp.cxan.de/CxAN/</a><br />
uk <a target="_blank" href="ftp://ftp.cxan.uk/CxAN/">ftp://ftp.cxan.uk/CxAN/</a><br />
com <a target="_blank" href="ftp://ftp.cxan.com/CxAN/">ftp://ftp.cxan.com/CxAN/</a><br />
:<br />
##EOF##</p>
<p>依赖于时间的重写<br />
说明:<br />
在页面内容依时间不同而变化的场合，比如重定向特定页面，许多网管仍然采用CGI脚本的方法，如何用mod_rewrite来实现呢？</p>
<p>方案:<br />
有许多类似TIME_xxx的变量可以用在重写条件中，利用STRING和=STRING的类型比较，并加以连接，就可以实现依赖于时间的重写：</p>
<p>代码:<br />
RewriteEngine on<br />
RewriteCond %% &gt;0700<br />
RewriteCond %% &lt;1900<br />
RewriteRule ^foo.html$ foo.day.html<br />
RewriteRule ^foo.html$ foo.night.html</p>
<p>此例使URL foo.html在07:00-19:00时指向foo.day.html，而在其余时间，则指向foo.night.html，对主页是一个不错的功能&#8230;</p>
<p>对YYYY过渡为XXXX的向前兼容<br />
说明:<br />
在转变了大批.html文件为.phtml，使文档.YYYY过渡成为文档.XXXX后，如何保持URL的向前兼容(仍然虚拟地存在)？</p>
<p>方案:<br />
只须按基准文件名重写，并测试带有新的扩展名的文件是否存在，如果存在，则用新的，否则，仍然用原来的。</p>
<p>代码:<br />
# backward compatibility ruleset for<br />
# rewriting document.html to document.phtml<br />
# when and only when document.phtml exists<br />
# but no longer document.html<br />
RewriteEngine on<br />
RewriteBase /~quux/<br />
# parse out basename, but remember the fact<br />
RewriteRule ^(.*).html$ [C,E=WasHTML:yes]<br />
# rewrite to document.phtml if exists<br />
RewriteCond %.phtml -f<br />
RewriteRule ^(.*)$ .phtml [S=1]<br />
# else reverse the previous basename cutout<br />
RewriteCond % ^yes$<br />
RewriteRule ^(.*)$ .html</p>
<p>内容的处理<br />
新旧URL(内部的)<br />
说明:<br />
假定已经把文件bar.html改名为foo.html，需要对老的URL向前兼容，即让用户仍然可以使用老的URL，而感觉不到文件被改名了。</p>
<p>方案:<br />
通过以下规则内部地重写老的URL为新的：</p>
<p>代码:<br />
RewriteEngine on<br />
RewriteBase /~quux/<br />
RewriteRule ^foo.html$ bar.html</p>
]]></content:encoded>
			<wfw:commentRss>http://www.uyun.com/2007/01/rewrite-of-the-virtual-user-hosts-daquan/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
