<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2chinesetwfull.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.xiaobin.net/~d/styles/itemcontent.css"?><rss 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/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" version="2.0">

<channel>
	<title>将之典藏</title>
	
	<link>http://xiaobin.net</link>
	<description>一个社交恐惧症患者（俗称：宅男）的互联网从业生活</description>
	<lastBuildDate>Thu, 05 Apr 2012 09:36:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.xiaobin.net/zh_cn" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="zh_cn" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><creativeCommons:license>http://creativecommons.org/licenses/by/2.0/</creativeCommons:license><meta xmlns="http://pipes.yahoo.com" name="pipes" content="noprocess" /><feedburner:emailServiceId xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">zh_cn</feedburner:emailServiceId><feedburner:feedburnerHostname xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://feedburner.google.com</feedburner:feedburnerHostname><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.xiaobin.net%2Fzh_cn" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.plusmo.com/add?url=http%3A%2F%2Ffeeds.xiaobin.net%2Fzh_cn" src="http://plusmo.com/res/graphics/fbplusmo.gif">Subscribe with Plusmo</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.thefreedictionary.com/_/hp/AddRSS.aspx?http%3A%2F%2Ffeeds.xiaobin.net%2Fzh_cn" src="http://img.tfd.com/hp/addToTheFreeDictionary.gif">Subscribe with The Free Dictionary</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.bitty.com/manual/?contenttype=rssfeed&amp;contentvalue=http%3A%2F%2Ffeeds.xiaobin.net%2Fzh_cn" src="http://www.bitty.com/img/bittychicklet_91x17.gif">Subscribe with Bitty Browser</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.newsalloy.com/?rss=http%3A%2F%2Ffeeds.xiaobin.net%2Fzh_cn" src="http://www.newsalloy.com/subrss3.gif">Subscribe with NewsAlloy</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.live.com/?add=http%3A%2F%2Ffeeds.xiaobin.net%2Fzh_cn" src="http://tkfiles.storage.msn.com/x1piYkpqHC_35nIp1gLE68-wvzLZO8iXl_JMledmJQXP-XTBOLfmQv4zhj4MhcWEJh_GtoBIiAl1Mjh-ndp9k47If7hTaFno0mxW9_i3p_5qQw">Subscribe with Live.com</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://mix.excite.eu/add?feedurl=http%3A%2F%2Ffeeds.xiaobin.net%2Fzh_cn" src="http://image.excite.co.uk/mix/addtomix.gif">Subscribe with Excite MIX</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://download.attensa.com/app/get_attensa.html?feedurl=http%3A%2F%2Ffeeds.xiaobin.net%2Fzh_cn" src="http://www.attensa.com/blogs/attensa/WindowsLiveWriter/BadgeredintoBadges_10C02/attensa_feed_button5.gif">Subscribe with Attensa for Outlook</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.webwag.com/wwgthis.php?url=http%3A%2F%2Ffeeds.xiaobin.net%2Fzh_cn" src="http://www.webwag.com/images/wwgthis.gif">Subscribe with Webwag</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.podcastready.com/oneclick_bookmark.php?url=http%3A%2F%2Ffeeds.xiaobin.net%2Fzh_cn" src="http://www.podcastready.com/images/podcastready_button.gif">Subscribe with Podcast Ready</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.flurry.com/pushRssFeed.do?r=fb&amp;url=http%3A%2F%2Ffeeds.xiaobin.net%2Fzh_cn" src="http://www.flurry.com/images/flurry_rss_logo2.gif">Subscribe with Flurry</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.wikio.com/subscribe?url=http%3A%2F%2Ffeeds.xiaobin.net%2Fzh_cn" src="http://www.wikio.com/shared/img/add2wikio.gif">Subscribe with Wikio</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.dailyrotation.com/index.php?feed=http%3A%2F%2Ffeeds.xiaobin.net%2Fzh_cn" src="http://www.dailyrotation.com/rss-dr2.gif">Subscribe with Daily Rotation</feedburner:feedFlare><item>
		<title>SSH登陆响应慢的问题</title>
		<link>http://xiaobin.net/201112/ssh-login-quite-slow/</link>
		<comments>http://xiaobin.net/201112/ssh-login-quite-slow/#comments</comments>
		<pubDate>Tue, 27 Dec 2011 07:21:59 +0000</pubDate>
		<dc:creator>肖斌</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://xiaobin.net/?p=873</guid>
		<description><![CDATA[同样的问题，有可能是两种情况： 第一种情况比较常见，也有很多资料提及到，就是在SSH登陆时服务器端会对客户端的IP进行反解析造成登陆响应慢的问题，通常改sshd_config的“UseDNS no”即可以。 第二种情况，服务器端启用了GSSAPI。登陆的时候客户端需要对服务器端的IP地址进行反解析，如果服务器的IP地址没有配置PTR记录，那么就容易在这里卡住了。 对于这种情况，就有必要禁用GSSAPI认证以加速SSH登陆，具体有下面几种方式： 解法一：使用ssh命令时使用附加的参数：ssh -o GSSAPIAuthentication=no server_address 解法二：修改客户端ssh_config（/etc/ssh/ssh_config或~/.ssh/config）：GSSAPIAuthentication no 解法三：修改服务器端的sshd_config(/etc/ssh/ssd_config)：GSSAPIAuthentication no 参考： GSSAPI 禁用ssh的GSSAPI提升连接速度 SSH登陆响应慢的问题 &#124; 暂无评论，添加评论 本文网址：http://xiaobin.net/201112/ssh-login-quite-slow/ 将之典藏 - 厚积而薄发，© 2005-2011. 如无特别声明，适用署名-非商业性使用-相同方式共享 3.0授权，你可以署名使用全部或者部分内容用于非商业性目的。]]></description>
			<content:encoded><![CDATA[<p>同样的问题，有可能是两种情况：</p>
<p>第一种情况比较常见，也有很多资料提及到，就是在SSH登陆时服务器端会对客户端的IP进行反解析造成登陆响应慢的问题，通常改sshd_config的“UseDNS no”即可以。</p>
<p>第二种情况，服务器端启用了GSSAPI。登陆的时候客户端需要对服务器端的IP地址进行反解析，如果服务器的IP地址没有配置PTR记录，那么就容易在这里卡住了。</p>
<p>对于这种情况，就有必要禁用GSSAPI认证以加速SSH登陆，具体有下面几种方式：</p>
<ol>
<li>解法一：使用ssh命令时使用附加的参数：ssh -o GSSAPIAuthentication=no server_address</li>
<li>解法二：修改客户端ssh_config（/etc/ssh/ssh_config或~/.ssh/config）：GSSAPIAuthentication no</li>
<li>解法三：修改服务器端的sshd_config(/etc/ssh/ssd_config)：GSSAPIAuthentication no</li>
</ol>
<p>参考：</p>
<ul>
<li><a href="http://en.wikipedia.org/wiki/Generic_Security_Services_Application_Program_Interface" target="_blank">GSSAPI</a></li>
<li><a href="http://www.issacy.com/archives/37.html" target="_blank">禁用ssh的GSSAPI提升连接速度</a></li>
</ul>
<hr />
<p><strong><a href="http://xiaobin.net/201112/ssh-login-quite-slow/">SSH登陆响应慢的问题</a></strong> | 暂无评论，<a href="http://xiaobin.net/201112/ssh-login-quite-slow/#comments">添加评论</a>
<br>本文网址：<a href="http://xiaobin.net/201112/ssh-login-quite-slow/">http://xiaobin.net/201112/ssh-login-quite-slow/</a>
<br><a href="http://xiaobin.net">将之典藏</a> - 厚积而薄发，© 2005-2011. 如无特别声明，适用<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">署名-非商业性使用-相同方式共享 3.0</a>授权，你可以署名使用全部或者部分内容用于非商业性目的。</p><img src="http://feeds.feedburner.com/~r/zh_cn/~4/oCOVGVRF2Nw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>怎样让Google在搜索结果呈现你的头像</title>
		<link>http://xiaobin.net/201111/how-to-display-author-profile-picture-in-google-srp/</link>
		<comments>http://xiaobin.net/201111/how-to-display-author-profile-picture-in-google-srp/#comments</comments>
		<pubDate>Fri, 25 Nov 2011 07:16:35 +0000</pubDate>
		<dc:creator>肖斌</dc:creator>
				<category><![CDATA[前端]]></category>
		<category><![CDATA[SEO]]></category>

		<guid isPermaLink="false">http://xiaobin.net/?p=860</guid>
		<description><![CDATA[效果： 第一步：创建Google Profile，修改头像。同时，修改Google Profile的“以下网站的撰稿者”，增加你的博客网址在上面。 第二步：在博客文章中增加你的Google Profile链接，有几种方式： 方式一：将Google Profile链接附加在每篇博文中。同时，重要是的还要设置链接的rel属性为“author”，如： &#60;a href="https://profiles.google.com/102865267049130142543" rel="author"&#62;肖斌&#60;/a&#62; 方式二： 创建一个“关于作者”的页面，在该页面插入Google Profile链接，但是这次rel的属性是&#8221;me&#8221;，如： Google Profile：&#60;a rel="me" href="https://profiles.google.com/102865267049130142543"&#62;Google Profile&#60;/a&#62; 每篇博文增加一个指向“关于作者”页的链接，设置该链接的rel属性为“me”，如： &#60;a rel="author" href="/about"&#62;About&#60;/a&#62; 只需要两个步骤，完成之后，可以通过Google Rich Snippets来测试。 参考： Authorship Display your Profile Picture in Google Search Results http://schema.org/ &#8212; 更新： 11.27 &#8211; 看来Google还在测试这项功能，完成以上的步骤之后还需要提交一个表单。 怎样让Google在搜索结果呈现你的头像 &#124; 暂无评论，添加评论 本文网址：http://xiaobin.net/201111/how-to-display-author-profile-picture-in-google-srp/ 将之典藏 - 厚积而薄发，© 2005-2011. 如无特别声明，适用署名-非商业性使用-相同方式共享 3.0授权，你可以署名使用全部或者部分内容用于非商业性目的。]]></description>
			<content:encoded><![CDATA[<p><strong>效果：</strong></p>
<p><em><a href="http://xiaobin.net/wp-content/uploads/2011/11/google-srp.png"><img class="aligncenter size-full wp-image-888" title="Google搜索结果" src="http://xiaobin.net/wp-content/uploads/2011/11/google-srp.png" alt="" width="530" height="111" /></a></em></p>
<p><strong>第一步</strong>：创建<a href="https://profiles.google.com/">Google Profile</a>，修改头像。同时，修改Google Profile的“<em>以下网站的撰稿者</em>”，增加你的博客网址在上面。</p>
<p><strong>第二步：</strong>在博客文章中增加你的Google Profile链接，有几种方式：</p>
<ol>
<li>方式一：将Google Profile链接附加在每篇博文中。同时，重要是的还要设置链接的rel属性为“author”，如：
<pre>&lt;a href="https://profiles.google.com/102865267049130142543" <span style="color: #ff0000;">rel="author"</span>&gt;肖斌&lt;/a&gt;</pre>
</li>
<li>方式二：</li>
<ol>
<li>创建一个“关于作者”的页面，在该页面插入Google Profile链接，但是这次rel的属性是&#8221;me&#8221;，如：
<pre>Google Profile：&lt;a <span style="color: #ff0000;">rel="me"</span> href="https://profiles.google.com/102865267049130142543"&gt;Google Profile&lt;/a&gt;</pre>
</li>
<li>每篇博文增加一个指向“关于作者”页的链接，设置该链接的rel属性为“me”，如：
<pre>&lt;a <span style="color: #ff0000;">rel="author"</span> href="/about"&gt;About&lt;/a&gt;</pre>
</li>
</ol>
</ol>
<div><span style="font-family: Consolas, Monaco, monospace;"><span class="Apple-style-span" style="font-size: 12px; line-height: 18px; white-space: pre;">只需要两个步骤，完成之后，可以通过<a href="http://www.google.com/webmasters/tools/richsnippets">Google Rich Snippets</a>来测试。</span></span></div>
<p>参考：</p>
<ul>
<li><a href="http://www.google.com/support/webmasters/bin/answer.py?answer=1229920">Authorship</a></li>
<li><a href="http://www.labnol.org/internet/author-profile-in-google/19775/">Display your Profile Picture in Google Search Results</a></li>
<li><a href="http://schema.org/">http://schema.org/</a></li>
</ul>
<div>&#8212;</div>
<div>更新：</div>
<div>11.27 &#8211; 看来Google还在测试这项功能，完成以上的步骤之后还需要提交一个<a href="http://bit.ly/lNjtLM">表单</a>。</div>
<hr />
<p><strong><a href="http://xiaobin.net/201111/how-to-display-author-profile-picture-in-google-srp/">怎样让Google在搜索结果呈现你的头像</a></strong> | 暂无评论，<a href="http://xiaobin.net/201111/how-to-display-author-profile-picture-in-google-srp/#comments">添加评论</a>
<br>本文网址：<a href="http://xiaobin.net/201111/how-to-display-author-profile-picture-in-google-srp/">http://xiaobin.net/201111/how-to-display-author-profile-picture-in-google-srp/</a>
<br><a href="http://xiaobin.net">将之典藏</a> - 厚积而薄发，© 2005-2011. 如无特别声明，适用<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">署名-非商业性使用-相同方式共享 3.0</a>授权，你可以署名使用全部或者部分内容用于非商业性目的。</p><img src="http://feeds.feedburner.com/~r/zh_cn/~4/jJ-RTB_mFfQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>不停止ping的情况下取得统计信息</title>
		<link>http://xiaobin.net/201110/checking-ping-statistics-without-stop/</link>
		<comments>http://xiaobin.net/201110/checking-ping-statistics-without-stop/#comments</comments>
		<pubDate>Tue, 25 Oct 2011 03:03:27 +0000</pubDate>
		<dc:creator>肖斌</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[技术]]></category>

		<guid isPermaLink="false">http://xiaobin.net/?p=848</guid>
		<description><![CDATA[我们常常需要通过长时间ping服务器来判断服务器的稳定性，在这个时候，通常只需要按CTRL+C，或者是向ping进程发送SIGINT信号，该进程就会结束并同时打印出统计信息。 要怎样才可以在不停止ping的情况下取得ping的统计信息呢？ 简单的做法就是使用按键“Ctrl+\”就可以(via)；爱折腾的同学，可以向ping进程发送SIGQUIT信号试试。 在漫长的ping过程中，这个小小技巧会很有用。 在Windows下，也有对应的按键，是：&#8221;Ctrl+Pause Break&#8221; (via)。 不停止ping的情况下取得统计信息 &#124; 暂无评论，添加评论 本文网址：http://xiaobin.net/201110/checking-ping-statistics-without-stop/ 将之典藏 - 厚积而薄发，© 2005-2011. 如无特别声明，适用署名-非商业性使用-相同方式共享 3.0授权，你可以署名使用全部或者部分内容用于非商业性目的。]]></description>
			<content:encoded><![CDATA[<p>我们常常需要通过长时间ping服务器来判断服务器的稳定性，在这个时候，通常只需要按CTRL+C，或者是向ping进程发送SIGINT信号，该进程就会结束并同时打印出统计信息。</p>
<p>要怎样才可以在不停止ping的情况下取得ping的统计信息呢？</p>
<p style="padding-left: 30px;">简单的做法就是使用按键“Ctrl+\”就可以(<a href="http://blog.sqawasmi.com/index.php/2009/09/28/ping-tip-ctl-backslash/">via</a>)；爱折腾的同学，可以向ping进程发送SIGQUIT信号试试。</p>
<p>在漫长的ping过程中，这个小小技巧会很有用。</p>
<p>在Windows下，也有对应的按键，是：&#8221;Ctrl+Pause Break&#8221; (<a href="http://alex.thegilfamily.com/1/post/2010/3/checking-your-ping-statistics-without-stopping-ping.html">via</a>)。</p>
<hr />
<p><strong><a href="http://xiaobin.net/201110/checking-ping-statistics-without-stop/">不停止ping的情况下取得统计信息</a></strong> | 暂无评论，<a href="http://xiaobin.net/201110/checking-ping-statistics-without-stop/#comments">添加评论</a>
<br>本文网址：<a href="http://xiaobin.net/201110/checking-ping-statistics-without-stop/">http://xiaobin.net/201110/checking-ping-statistics-without-stop/</a>
<br><a href="http://xiaobin.net">将之典藏</a> - 厚积而薄发，© 2005-2011. 如无特别声明，适用<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">署名-非商业性使用-相同方式共享 3.0</a>授权，你可以署名使用全部或者部分内容用于非商业性目的。</p><img src="http://feeds.feedburner.com/~r/zh_cn/~4/4z_p_RGkpxM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache绑定子域到目录</title>
		<link>http://xiaobin.net/201109/apache-mapping-subdomain-to-subdir-with-mod_vhost_alias/</link>
		<comments>http://xiaobin.net/201109/apache-mapping-subdomain-to-subdir-with-mod_vhost_alias/#comments</comments>
		<pubDate>Mon, 05 Sep 2011 02:14:53 +0000</pubDate>
		<dc:creator>肖斌</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Apache]]></category>

		<guid isPermaLink="false">http://xiaobin.net/?p=819</guid>
		<description><![CDATA[刚看到一篇《Apache用mod_rewrite配置子域名》，用mod_rewrite来做子域名绑定到目录，我们之前也有尝试过，但是写在conf档里边RewriteEngine，容易与.htaccess中的RewriteEngine发生处突。后来找到一个很完美的解决方案：mod_vhost_alias &#60;VirtualHost *:80&#62; ServerAlias *.xiaobin.net VirtualDocumentRoot /var/htdocs/xiaobin.net/%1 &#60;/VirtualHost&#62; 是的，就这么简单。 Apache绑定子域到目录 &#124; 评论数(2)，添加评论 本文网址：http://xiaobin.net/201109/apache-mapping-subdomain-to-subdir-with-mod_vhost_alias/ 将之典藏 - 厚积而薄发，© 2005-2011. 如无特别声明，适用署名-非商业性使用-相同方式共享 3.0授权，你可以署名使用全部或者部分内容用于非商业性目的。]]></description>
			<content:encoded><![CDATA[<p>刚看到一篇《<a href="http://www.ideawu.net/blog/2011/09/apache%E7%94%A8mod_rewrite%E9%85%8D%E7%BD%AE%E5%AD%90%E5%9F%9F%E5%90%8D.html">Apache用mod_rewrite配置子域名</a>》，用mod_rewrite来做子域名绑定到目录，我们之前也有尝试过，但是写在conf档里边RewriteEngine，容易与.htaccess中的RewriteEngine发生处突。后来找到一个很完美的解决方案：<a href="http://httpd.apache.org/docs/2.0/mod/mod_vhost_alias.html">mod_vhost_alias</a></p>
<pre>&lt;VirtualHost *:80&gt;
    ServerAlias *.xiaobin.net
    VirtualDocumentRoot /var/htdocs/xiaobin.net/%1
&lt;/VirtualHost&gt;</pre>
<p>是的，就这么简单。</p>
<hr />
<p><strong><a href="http://xiaobin.net/201109/apache-mapping-subdomain-to-subdir-with-mod_vhost_alias/">Apache绑定子域到目录</a></strong> | 评论数(2)，<a href="http://xiaobin.net/201109/apache-mapping-subdomain-to-subdir-with-mod_vhost_alias/#comments">添加评论</a>
<br>本文网址：<a href="http://xiaobin.net/201109/apache-mapping-subdomain-to-subdir-with-mod_vhost_alias/">http://xiaobin.net/201109/apache-mapping-subdomain-to-subdir-with-mod_vhost_alias/</a>
<br><a href="http://xiaobin.net">将之典藏</a> - 厚积而薄发，© 2005-2011. 如无特别声明，适用<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">署名-非商业性使用-相同方式共享 3.0</a>授权，你可以署名使用全部或者部分内容用于非商业性目的。</p><img src="http://feeds.feedburner.com/~r/zh_cn/~4/nqHqLpxgI9I" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>一次神奇的MySQL优化</title>
		<link>http://xiaobin.net/201109/strange-sql-performance-problem/</link>
		<comments>http://xiaobin.net/201109/strange-sql-performance-problem/#comments</comments>
		<pubDate>Sat, 03 Sep 2011 09:43:42 +0000</pubDate>
		<dc:creator>肖斌</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://xiaobin.net/?p=785</guid>
		<description><![CDATA[话说有这么一个表： CREATE TABLE `user_group` ( `id` int(11) NOT NULL auto_increment, `uid` int(11) NOT NULL, `group_id` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `uid` (`uid`), KEY `group_id` (`group_id`), ) ENGINE=InnoDB AUTO_INCREMENT=750366 DEFAULT CHARSET=utf8 看AUTO_INCREMENT就知道数据并不多，75万条。然后是一条简单的查询： SELECT SQL_NO_CACHE uid FROM user_group WHERE group_id = 245; 很简单对不对？怪异的地方在于： 如果换成MyISAM做存储引擎的时候，查询耗时只需要0.01s，用InnoDB却会是0.15s左右 如果只是就这么点差距其实不是什么大不了的事，但是真实的业务需求比这个复杂，造成的差距也很大：MyISAM只需要0.12s，InnoDB则需要2.2s.，最终定位到问题症结是在这条SQL。 Explain的结果是： +----+-------------+------------+------+---------------+----------+---------+-------+------+-------+ &#124; id &#124; select_type &#124; table &#124; type [...]]]></description>
			<content:encoded><![CDATA[<p>话说有这么一个表：</p>
<pre>CREATE TABLE `user_group` (
  `id` int(11) NOT NULL auto_increment,
  `uid` int(11) NOT NULL,
  `group_id` int(11) NOT NULL,
  PRIMARY KEY  (`id`),
  KEY `uid` (`uid`),
  KEY `group_id` (`group_id`),
) ENGINE=InnoDB AUTO_INCREMENT=750366 DEFAULT CHARSET=utf8</pre>
<p>看AUTO_INCREMENT就知道数据并不多，75万条。然后是一条简单的查询：</p>
<pre>SELECT SQL_NO_CACHE uid FROM user_group WHERE group_id = 245;</pre>
<p><span id="more-785"></span>很简单对不对？怪异的地方在于：</p>
<ul>
<li>如果换成MyISAM做存储引擎的时候，查询耗时只需要0.01s，用InnoDB却会是0.15s左右</li>
</ul>
<p>如果只是就这么点差距其实不是什么大不了的事，但是真实的业务需求比这个复杂，造成的差距也很大：MyISAM只需要0.12s，InnoDB则需要2.2s.，最终定位到问题症结是在这条SQL。</p>
<p>Explain的结果是：</p>
<pre>+----+-------------+------------+------+---------------+----------+---------+-------+------+-------+
| id | select_type | table      | type | possible_keys | key      | key_len | ref   | rows | Extra |
+----+-------------+------------+------+---------------+----------+---------+-------+------+-------+
|  1 | SIMPLE      | user_group | ref  | group_id      | group_id | 4       | const | 5544 |       |
+----+-------------+------------+------+---------------+----------+---------+-------+------+-------+</pre>
<p>看起来已经用上索引了，而这条SQL语句已经简单到让我无法再优化了。最后请前同事<a href="http://www.gastonwu.com/">Gaston</a>诊断了一下，他认为：数据分布上，group_id相同的比较多，uid散列的比较均匀，加索引的效果一般，但是还是建议我试着加了一个多列索引：</p>
<pre>ALTER TABLE user_group ADD INDEX group_id_uid (group_id, uid);</pre>
<p>然后，不可思议的事情发生了……这句SQL查询的性能发生了巨大的提升，居然已经可以跑到0.00s左右了。经过优化的SQL再结合真实的业务需求，也从之前2.2s下降到0.05s。</p>
<p>再Explain一次：</p>
<pre>+----+-------------+------------+------+-----------------------+--------------+---------+-------+------+-------------+
| id | select_type | table      | type | possible_keys         | key          | key_len | ref   | rows | Extra       |
+----+-------------+------------+------+-----------------------+--------------+---------+-------+------+-------------+
|  1 | SIMPLE      | user_group | ref  | group_id,group_id_uid | group_id_uid | 4       | const | 5378 | <span style="color: #ff0000;">Using index</span> |
+----+-------------+------------+------+-----------------------+--------------+---------+-------+------+-------------+</pre>
<p>原来是这种叫覆盖索引（covering index），MySQL只需要通过索引就可以返回查询所需要的数据，而不必在查到索引之后再去查询数据，所以那是相当的快！！但是同时也要求所查询的字段必须被索引所覆盖到，在Explain的时候，输出的Extra信息中如果有“Using Index”，就表示这条查询使用了覆盖索引。</p>
<p style="text-align: center;"><img class="size-full wp-image-791 aligncenter" title="convering-index" src="http://xiaobin.net/wp-content/uploads/2011/09/convering-index1.png" alt="" width="490" height="321" /></p>
<p>不过，还有一个无法解释的问题就是，不用覆盖索引的情况下，为什么用MyISAM就快那么多，而InnoDB就慢这么多呢？求真相……</p>
<h4>延伸阅读：</h4>
<ul>
<li>High Performance MySQL, 2nd Edition. O&#8217;Reilly.  <a href="http://bit.ly/pXhuCP">P120</a></li>
<li><a href="http://bit.ly/ovIqwy" target="_blank">MySQL之Covering Index</a></li>
<li><a href="http://bit.ly/qwXwoo" target="_blank">Covering indexes</a></li>
<li><a href="http://www.slideshare.net/sky000/mysql-explain">MySQL Explain</a></li>
<li><a href="http://www.mysqlops.com/2011/08/27/innodb-internal.html">InnoDB internal</a> &#8211; 感谢@<a href="http://weibo.com/mysqlops">mysqlops</a>推荐</li>
</ul>
<hr />
<p><strong><a href="http://xiaobin.net/201109/strange-sql-performance-problem/">一次神奇的MySQL优化</a></strong> | 评论数(5)，<a href="http://xiaobin.net/201109/strange-sql-performance-problem/#comments">添加评论</a>
<br>本文网址：<a href="http://xiaobin.net/201109/strange-sql-performance-problem/">http://xiaobin.net/201109/strange-sql-performance-problem/</a>
<br><a href="http://xiaobin.net">将之典藏</a> - 厚积而薄发，© 2005-2011. 如无特别声明，适用<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">署名-非商业性使用-相同方式共享 3.0</a>授权，你可以署名使用全部或者部分内容用于非商业性目的。</p><img src="http://feeds.feedburner.com/~r/zh_cn/~4/79E4NNnl8kM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>strace跟踪apache mod_php5的系统调用</title>
		<link>http://xiaobin.net/201107/strace-apache-mod_php/</link>
		<comments>http://xiaobin.net/201107/strace-apache-mod_php/#comments</comments>
		<pubDate>Fri, 22 Jul 2011 09:38:49 +0000</pubDate>
		<dc:creator>肖斌</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[strace]]></category>

		<guid isPermaLink="false">http://xiaobin.net/?p=760</guid>
		<description><![CDATA[如果跟踪php命令行，或者是fastcgi，应该相对容易多，因为这两种情况下都有独立的PHP进程。 但是跟踪Apache+mod_php5相对就麻烦一些，因为没有独立的PHP进程。如果对httpd守护进程进行strace的话，只会获取到Apache本身的一些系统调用，如查找.htaccess，得不到PHP的系统调用。 有个老外分享了一个视频，跟踪主要分三步： 通过Telnet与Apache建立连接，但是不要立刻就发送HTTP请求（可以写入头HTTP头，但不要连续两次回车），以免连接过快被断开了； 新开一个ssh session，root运行 lsof -p `pidof telnet` &#124; perl -nle 'print "netstat -anp &#124; grep $1" if m/:(\d+)-&#62;/' &#124; sh &#124; perl -nle 'print "strace -p $1" if m/(\d+)\/httpd/' &#124; sh 回到Telnet，发送HTTP请求 具体看视频（自备梯子）： strace跟踪apache mod_php5的系统调用 &#124; 暂无评论，添加评论 本文网址：http://xiaobin.net/201107/strace-apache-mod_php/ 将之典藏 - 厚积而薄发，© 2005-2011. 如无特别声明，适用署名-非商业性使用-相同方式共享 3.0授权，你可以署名使用全部或者部分内容用于非商业性目的。]]></description>
			<content:encoded><![CDATA[<p>如果跟踪php命令行，或者是fastcgi，应该相对容易多，因为这两种情况下都有独立的PHP进程。</p>
<p>但是跟踪Apache+mod_php5相对就麻烦一些，因为没有独立的PHP进程。如果对httpd守护进程进行strace的话，只会获取到Apache本身的一些系统调用，如查找.htaccess，得不到PHP的系统调用。</p>
<p>有个老外分享了一个<a href="http://youtu.be/eF-p--AH37E" target="_blank">视频</a>，跟踪主要分三步：</p>
<ol>
<li>通过Telnet与Apache建立连接，但是不要立刻就发送HTTP请求（可以写入头HTTP头，但不要连续两次回车），以免连接过快被断开了；</li>
<li>新开一个ssh session，root运行
<pre>lsof -p `pidof telnet` | perl -nle 'print "netstat -anp | grep $1" if m/:(\d+)-&gt;/' | sh | perl -nle 'print "strace -p $1" if m/(\d+)\/httpd/' | sh</pre>
</li>
<li>回到Telnet，发送HTTP请求</li>
</ol>
<p><span id="more-760"></span>具体看<a href="http://youtu.be/eF-p--AH37E" target="_blank">视频</a>（自备梯子）：</p>
<p><center><iframe src="http://www.youtube.com/embed/eF-p--AH37E" frameborder="0" width="560" height="349"></iframe></center></p>
<hr />
<p><strong><a href="http://xiaobin.net/201107/strace-apache-mod_php/">strace跟踪apache mod_php5的系统调用</a></strong> | 暂无评论，<a href="http://xiaobin.net/201107/strace-apache-mod_php/#comments">添加评论</a>
<br>本文网址：<a href="http://xiaobin.net/201107/strace-apache-mod_php/">http://xiaobin.net/201107/strace-apache-mod_php/</a>
<br><a href="http://xiaobin.net">将之典藏</a> - 厚积而薄发，© 2005-2011. 如无特别声明，适用<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">署名-非商业性使用-相同方式共享 3.0</a>授权，你可以署名使用全部或者部分内容用于非商业性目的。</p><img src="http://feeds.feedburner.com/~r/zh_cn/~4/G74ljXR0xZQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>高效的大文件拷贝</title>
		<link>http://xiaobin.net/201107/efficiently-copying-files-to-multiple-destinations/</link>
		<comments>http://xiaobin.net/201107/efficiently-copying-files-to-multiple-destinations/#comments</comments>
		<pubDate>Thu, 21 Jul 2011 16:09:51 +0000</pubDate>
		<dc:creator>肖斌</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://xiaobin.net/?p=747</guid>
		<description><![CDATA[译自：Efficiently copying files to multiple destinations 当你要两台机器之间拷贝一些大文件的时候，把nc(netcat)和pigz(parallel gzip)组合起来会是一个简单和高效的选择。不过，如果要把这些文件同时分发到多台机器，有什么好法子吗？在Tumblr，这还算蛮常见的需求，比如我们要快速的同时增加几台MySQL Slave的时候。 你可以从源机器逐个拷贝到逐台目标机器，但是往往时间也是成倍的。或者你也可以同时从源机器同时拷贝到多个目标机器，但是受制于源机器的带宽等因素，速度并不见得真的很快。 还好，借助一些UNIX工具可以做的更好。把tee和FIFO组合起来，可以形成一个文件快速分发链：处于分发链中的每台机器会保存文件，同时还分发给它的下一环。 首先，选定一台目标机器做为分发链的最后一环，在这台机器上只需要用nc监听（假定端口是1234），再通过管道由pigz解压缩，继续通过管道把数据交由tar来分解。 nc -l 1234 &#124; pigz -d &#124; tar xvf - 然后，再从分发链的末端往上走，设置其它目标机器，同样要经过监听、解压、分解，不过在解压之前我们通过tee命令将数据输出到命名管道(FIFO)，另外的一条shell管道会将这些未解压的数据同时分发到分发链的下一环： mkfifo myfifo nc hostname_of_next_box 1234 nc -l 1234 &#124; tee myfifo &#124; pigz -d &#124; tar xvf - 最后，在源机器上启动分发链，让数据传输到分发链的第一环： tar cv some_files &#124; pigz &#124; nc hostname_of_first_box 1234 在我的测试中，分发链中的每台机器大概损失了3%-10%的性能（相对于1对1的拷贝而言），但是相对逐个逐个的拷贝或者单台机器向多台机器同时分发，效率提升是很明显的。 &#8212; 延伸阅读： 网络版瑞士军刀nc作弊条 [...]]]></description>
			<content:encoded><![CDATA[<p>译自：<a href="http://engineering.tumblr.com/post/7658008285/efficiently-copying-files-to-multiple-destinations" target="_blank">Efficiently copying files to multiple destinations</a></p>
<p>当你要两台机器之间拷贝一些大文件的时候，把nc(<a href="http://netcat.sourceforge.net/" target="_blank">netcat</a>)和<a href="http://www.zlib.net/pigz/" target="_blank">pigz</a>(parallel gzip)组合起来会是一个<a href="http://andrew.tumblr.com/post/2316602611">简单</a>和<a href="http://dallas.tumblr.com/post/4418180672/andrew-tumblr-com-combining-tar-pigz-and-netcat">高效</a>的选择。不过，如果要把这些文件同时分发到多台机器，有什么好法子吗？在Tumblr，这还算蛮常见的需求，比如我们要快速的同时增加几台MySQL Slave的时候。</p>
<p>你可以从源机器逐个拷贝到逐台目标机器，但是往往时间也是成倍的。或者你也可以同时从源机器同时拷贝到多个目标机器，但是受制于源机器的带宽等因素，速度并不见得真的很快。<span id="more-747"></span></p>
<p>还好，借助一些UNIX工具可以做的更好。把tee和FIFO组合起来，可以形成一个文件快速分发链：处于分发链中的每台机器会保存文件，同时还分发给它的下一环。</p>
<p>首先，选定一台目标机器做为分发链的最后一环，在这台机器上只需要用nc监听（假定端口是1234），再通过管道由pigz解压缩，继续通过管道把数据交由tar来分解。</p>
<pre>nc -l 1234 | pigz -d | tar xvf -</pre>
<p>然后，再从分发链的末端往上走，设置其它目标机器，同样要经过监听、解压、分解，不过在解压之前我们通过tee命令将数据输出到命名管道(FIFO)，另外的一条shell管道会将这些未解压的数据同时分发到分发链的下一环：</p>
<pre>mkfifo myfifo
nc hostname_of_next_box 1234 nc -l 1234 | tee myfifo | pigz -d | tar xvf -</pre>
<p>最后，在源机器上启动分发链，让数据传输到分发链的第一环：</p>
<pre>tar cv some_files | pigz | nc hostname_of_first_box 1234</pre>
<p>在我的测试中，分发链中的每台机器大概损失了3%-10%的性能（相对于1对1的拷贝而言），但是相对逐个逐个的拷贝或者单台机器向多台机器同时分发，效率提升是很明显的。</p>
<p>&#8212;</p>
<p>延伸阅读：</p>
<ul>
<li><a href="http://blog.sina.com.cn/s/blog_5374d6e30100u5h7.html" target="_blank">网络版瑞士军刀nc作弊条</a></li>
<li><a href="http://searchenterpriselinux.techtarget.com/tip/Linux-cloning-over-the-network-using-netcat" target="_blank">Linux cloning over the network using netcat</a></li>
</ul>
<hr />
<p><strong><a href="http://xiaobin.net/201107/efficiently-copying-files-to-multiple-destinations/">高效的大文件拷贝</a></strong> | 暂无评论，<a href="http://xiaobin.net/201107/efficiently-copying-files-to-multiple-destinations/#comments">添加评论</a>
<br>本文网址：<a href="http://xiaobin.net/201107/efficiently-copying-files-to-multiple-destinations/">http://xiaobin.net/201107/efficiently-copying-files-to-multiple-destinations/</a>
<br><a href="http://xiaobin.net">将之典藏</a> - 厚积而薄发，© 2005-2011. 如无特别声明，适用<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">署名-非商业性使用-相同方式共享 3.0</a>授权，你可以署名使用全部或者部分内容用于非商业性目的。</p><img src="http://feeds.feedburner.com/~r/zh_cn/~4/yyHRyMIRi-U" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>include(“./file.php”)和include(“file.php”)区别</title>
		<link>http://xiaobin.net/201107/difference-between-with-or-whitout-prefix-dot-while-include-file/</link>
		<comments>http://xiaobin.net/201107/difference-between-with-or-whitout-prefix-dot-while-include-file/#comments</comments>
		<pubDate>Thu, 21 Jul 2011 06:46:00 +0000</pubDate>
		<dc:creator>肖斌</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[include_path]]></category>

		<guid isPermaLink="false">http://xiaobin.net/?p=720</guid>
		<description><![CDATA[多数情况下，两种方式的区别可能在性能上有细微的区别(via)。 但是，在多重包含的情况下表现未必一样： &#124;-- index.php `-- lib &#124;-- a.php `-- b.php 假定有三个文件，入口文件index.php，包含lib/a.php。a.php又需要包含它同目录下的b.php： 方式1：include(&#8220;./b.php&#8221;) &#8211; 不工作 方式2：include(&#8220;b.php&#8221;) &#8211; 正常 我们通过strace来跟踪一下方式2的系统调用（我的环境下include_path=.:/tmp）： open("/home/robin/devel/lib/a.php", O_RDONLY) = 3 open("/home/robin/devel/b.php", O_RDONLY) = -1 ENOENT (No such file or directory) open("/tmp/b.php", O_RDONLY) = -1 ENOENT (No such file or directory) open("/home/robin/devel/lib/b.php", O_RDONLY) = 3 官方文档的阐述是这样的： Files are included based on the file path [...]]]></description>
			<content:encoded><![CDATA[<p>多数情况下，两种方式的区别可能在性能上有细微的区别(<a href="http://php.net/manual/en/ini.core.php#ini.include-path" target="_blank">via</a>)。 但是，在多重包含的情况下表现未必一样：</p>
<pre>|-- index.php
`-- lib
    |-- a.php
    `-- b.php</pre>
<p>假定有三个文件，入口文件index.php，包含lib/a.php。a.php又需要包含它同目录下的b.php：</p>
<ul>
<li>方式1：include(&#8220;./b.php&#8221;) &#8211; 不工作</li>
<li>方式2：include(&#8220;b.php&#8221;) &#8211; 正常</li>
</ul>
<div><span id="more-720"></span></div>
<p>我们通过strace来跟踪一下方式2的系统调用（我的环境下include_path=.:/tmp）：</p>
<pre>open("/home/robin/devel/lib/a.php", O_RDONLY) = 3
open("/home/robin/devel/b.php", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/tmp/b.php", O_RDONLY)            = -1 ENOENT (No such file or directory)
open("/home/robin/devel/lib/b.php", O_RDONLY) = 3</pre>
<p>官方文档的阐述是这样的：</p>
<blockquote><p>Files are included based on the file path given or, if none is given, the include_path specified. If the file isn&#8217;t found in the include_path, include() will finally check in the calling script&#8217;s own directory and the current working directory before failing.</p></blockquote>
<p>所以优先级应该是这样：</p>
<ol>
<li>有指定路径的话（如：&#8221;./&#8221;或者是&#8221;../&#8221;或&#8221;/home/&#8230;&#8221;），将直接根据路径来查找文件；</li>
<li>没有指定路径的情况</li>
<ol>
<li>遍历include_path查找，include_path中有“.”开头的话，则指的是CWD(Current working directory，即是例中的index.php所在的目录)</li>
<li>在calling script(也就是例中的a.php)所在的目录查找</li>
<li>在CWD目录查找 &#8211; 不过在测试的时候发现似乎没有做到这一样。很容易测试：把include_path设成”/”避免其中有“.”，也就避免根据include_path方式查找到文件，再把b.php移到index.php同一级目录，结果包含不到。</li>
</ol>
</ol>
<div>当然，比较推荐结合魔术常量__FILE__来include。</div>
<h3>参考及延伸阅读：</h3>
<div>
<ul>
<li><a href="http://bit.ly/p38s19" target="_blank">What does the dot-slash do to PHP include calls?</a>. StackOverflow</li>
<li><a href="http://php.net/manual/en/function.include.php" target="_blank">PHP官方文档</a></li>
</ul>
</div>
<hr />
<p><strong><a href="http://xiaobin.net/201107/difference-between-with-or-whitout-prefix-dot-while-include-file/">include(&#8220;./file.php&#8221;)和include(&#8220;file.php&#8221;)区别</a></strong> | 暂无评论，<a href="http://xiaobin.net/201107/difference-between-with-or-whitout-prefix-dot-while-include-file/#comments">添加评论</a>
<br>本文网址：<a href="http://xiaobin.net/201107/difference-between-with-or-whitout-prefix-dot-while-include-file/">http://xiaobin.net/201107/difference-between-with-or-whitout-prefix-dot-while-include-file/</a>
<br><a href="http://xiaobin.net">将之典藏</a> - 厚积而薄发，© 2005-2011. 如无特别声明，适用<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">署名-非商业性使用-相同方式共享 3.0</a>授权，你可以署名使用全部或者部分内容用于非商业性目的。</p><img src="http://feeds.feedburner.com/~r/zh_cn/~4/q-sL58N1tYY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Symbolic link target toggle</title>
		<link>http://xiaobin.net/201107/symbolic-link-target-toggle/</link>
		<comments>http://xiaobin.net/201107/symbolic-link-target-toggle/#comments</comments>
		<pubDate>Mon, 18 Jul 2011 08:44:13 +0000</pubDate>
		<dc:creator>肖斌</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://xiaobin.net/?p=712</guid>
		<description><![CDATA[背景省略，只贴代码不说话： ln -sf \ $( \ echo $( \ [ \ "$(md5sum oauth.so &#124; awk '{print $1}')" \ = ae8268ac08af61065d2a878ef657835d \ ] \ &#38;&#38; echo "oauth-1.0.so" &#124;&#124; echo "oauth-1.2.so" \ ) \ ) \ oauth.so Symbolic link target toggle &#124; 暂无评论，添加评论 本文网址：http://xiaobin.net/201107/symbolic-link-target-toggle/ 将之典藏 - 厚积而薄发，© 2005-2011. 如无特别声明，适用署名-非商业性使用-相同方式共享 3.0授权，你可以署名使用全部或者部分内容用于非商业性目的。]]></description>
			<content:encoded><![CDATA[<p>背景省略，只贴代码不说话：</p>
<pre>ln -sf                                                      \
    $(                                                      \
        echo $(                                             \
            [                                               \
                "$(md5sum <span style="text-decoration: underline;">oauth.so</span> | awk '{print $1}')"     \
                    = <span style="text-decoration: underline;">ae8268ac08af61065d2a878ef657835d</span>      \
            ]                                               \
            &amp;&amp; echo "<span style="text-decoration: underline;">oauth-1.0.so</span>" || echo "<span style="text-decoration: underline;">oauth-1.2.so</span>"   \
        )                                                   \
    )                                                       \
    <span style="text-decoration: underline;">oauth.so</span></pre>
<hr />
<p><strong><a href="http://xiaobin.net/201107/symbolic-link-target-toggle/">Symbolic link target toggle</a></strong> | 暂无评论，<a href="http://xiaobin.net/201107/symbolic-link-target-toggle/#comments">添加评论</a>
<br>本文网址：<a href="http://xiaobin.net/201107/symbolic-link-target-toggle/">http://xiaobin.net/201107/symbolic-link-target-toggle/</a>
<br><a href="http://xiaobin.net">将之典藏</a> - 厚积而薄发，© 2005-2011. 如无特别声明，适用<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">署名-非商业性使用-相同方式共享 3.0</a>授权，你可以署名使用全部或者部分内容用于非商业性目的。</p><img src="http://feeds.feedburner.com/~r/zh_cn/~4/4DW-ub09Igw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSH Agent与GNU Screen的兼容问题</title>
		<link>http://xiaobin.net/201107/the-problem-between-ssh-agent-and-gnu-screen/</link>
		<comments>http://xiaobin.net/201107/the-problem-between-ssh-agent-and-gnu-screen/#comments</comments>
		<pubDate>Sat, 09 Jul 2011 14:54:59 +0000</pubDate>
		<dc:creator>肖斌</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[ssh agent]]></category>

		<guid isPermaLink="false">http://xiaobin.net/?p=663</guid>
		<description><![CDATA[关于SSH Agent的使用可以见《SSH免密码认证进阶使用》一文，与GNU Screen之间会有这样一个问题： 在客户端运行ssh-agent并启用agent转发； 通过SSH登入服务器，服务器端会在临时文件夹生成auth socks文件A，并将A的路径写入环境变量SSH_AUTH_SOCK； 运行&#8221;screen&#8221;进入到GNU screen， screen会继承环境变量，读入环境变量SSH_AUTH_SOCK； 将screen会话挂起，退出服务器，这时socks文件A将会被销毁； 再一次通过SSH登入服务器，服务器会生成新的auth sock文件B； 恢复screen会话，但是由于恢复screen时不会再刷新环境变量，SSH_AUTH_SOCK的值仍然是A，但是socks文件A却早就被移除掉了，ssh-agent也就失去作用； 我目前的做法是，在.bashrc增加一段代码，每次在进入bash shell时会建立一个软连接指向当时的auth socks文件，然后将SSH_AUTH_SOCK环境变量的值设置为软连接的地址，问题得以解决： agent_file=/tmp/ssh-agent-$USER.sock if [ "$SSH_TTY" -a "$SSH_AUTH_SOCK" -a "$SSH_AUTH_SOCK" != $agent_file ]; then ln -sfn $SSH_AUTH_SOCK $agent_file export SSH_AUTH_SOCK=$agent_file fi # 同时增加了一个函数，方便重建软连接，有些情况下用得着。 update_ssh_agent() { for sock in /tmp/ssh-*/agent* do if [ -S $sock ]; then ln -sfn $sock $agent_file fi [...]]]></description>
			<content:encoded><![CDATA[<p>关于SSH Agent的使用可以见《<a title="SSH免密码认证进阶使用" href="/201106/ssh-key-auth-and-ssh-agent/" target="_blank">SSH免密码认证进阶使用</a>》一文，与GNU Screen之间会有这样一个问题：</p>
<ol>
<li>在客户端运行ssh-agent并启用agent转发；</li>
<li>通过SSH登入服务器，服务器端会在临时文件夹生成auth socks文件A，并将A的路径写入环境变量SSH_AUTH_SOCK；</li>
<li>运行&#8221;screen&#8221;进入到GNU screen， screen会继承环境变量，读入环境变量SSH_AUTH_SOCK；</li>
<li>将screen会话挂起，退出服务器，这时socks文件A将会被销毁；</li>
<li>再一次通过SSH登入服务器，服务器会生成新的auth sock文件B；</li>
<li>恢复screen会话，但是由于恢复screen时不会再刷新环境变量，SSH_AUTH_SOCK的值仍然是A，但是socks文件A却早就被移除掉了，ssh-agent也就失去作用；</li>
</ol>
<p><span id="more-663"></span>我目前的做法是，在.bashrc增加一段代码，每次在进入bash shell时会建立一个软连接指向当时的auth socks文件，然后将SSH_AUTH_SOCK环境变量的值设置为软连接的地址，问题得以解决：</p>
<pre>agent_file=/tmp/ssh-agent-$USER.sock

if [ "$SSH_TTY" -a "$SSH_AUTH_SOCK" -a "$SSH_AUTH_SOCK" != $agent_file ]; then
    ln -sfn $SSH_AUTH_SOCK $agent_file
    export SSH_AUTH_SOCK=$agent_file
fi

# 同时增加了一个函数，方便重建软连接，有些情况下用得着。
update_ssh_agent() {
    for sock in /tmp/ssh-*/agent*
    do
        if [ -S $sock ]; then
            ln -sfn $sock $agent_file
        fi
    done
}</pre>
<hr />
<p><strong><a href="http://xiaobin.net/201107/the-problem-between-ssh-agent-and-gnu-screen/">SSH Agent与GNU Screen的兼容问题</a></strong> | 暂无评论，<a href="http://xiaobin.net/201107/the-problem-between-ssh-agent-and-gnu-screen/#comments">添加评论</a>
<br>本文网址：<a href="http://xiaobin.net/201107/the-problem-between-ssh-agent-and-gnu-screen/">http://xiaobin.net/201107/the-problem-between-ssh-agent-and-gnu-screen/</a>
<br><a href="http://xiaobin.net">将之典藏</a> - 厚积而薄发，© 2005-2011. 如无特别声明，适用<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">署名-非商业性使用-相同方式共享 3.0</a>授权，你可以署名使用全部或者部分内容用于非商业性目的。</p><img src="http://feeds.feedburner.com/~r/zh_cn/~4/NJhb4dLEyvk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

