<?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>MySQL实践积累 &#187; Linux</title>
	<atom:link href="http://dbahacker.com/archive/linux/feed" rel="self" type="application/rss+xml" />
	<link>http://dbahacker.com</link>
	<description></description>
	<lastBuildDate>Thu, 17 May 2012 03:59:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>redhat5 和redhat6 root用户不同的ulimits</title>
		<link>http://dbahacker.com/linux/redhat5-%e5%92%8credhat6-root%e7%94%a8%e6%88%b7%e4%b8%8d%e5%90%8c%e7%9a%84ulimits</link>
		<comments>http://dbahacker.com/linux/redhat5-%e5%92%8credhat6-root%e7%94%a8%e6%88%b7%e4%b8%8d%e5%90%8c%e7%9a%84ulimits#comments</comments>
		<pubDate>Tue, 31 Jan 2012 09:27:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[redhat6]]></category>

		<guid isPermaLink="false">http://dbahacker.com/?p=214</guid>
		<description><![CDATA[以前一直都是用redhat5，redhat6也处于测试阶段，当然也遇到了很多奇奇怪怪的问题，比如之前写的一篇博客,当时候是用root启动了mysqld_unsafe，在mysql的QPS到1W以上后，会出现ERROR 1135 (HY000): Can’t create a new thread (errno 11); 当时候的解决办法是用mysql用户来启动就解决了问题。但因为在系统重启后，如果用sudo&#160; -u mysql来启动的话，脚本会被卡主。 这个问题今天得到了一个稍微深入一点的结论。 首先我们看看这个错误 ERROR 1135 (HY000): Can’t create a new thread (errno 11); if you are not out of available memory, you can consult the manual for a possible OS-dependent bug google类似Can’t create a new thread的错误后，得到的结论是文件描述符不够用，检查了vim /etc/security/limits.conf&#160;&#160; 的设置，是正常的 vim /etc/security/limits.conf 得到的结果是 root soft [...]]]></description>
			<content:encoded><![CDATA[<p><font face="新宋体">以前一直都是用redhat5，redhat6也处于测试阶段，当然也遇到了很多奇奇怪怪的问题，比如之前写的一篇</font><a href="http://dbahacker.com/linux/error-1135-hy000-cant-create-a-new-thread-errno-11" target="_blank"><font face="新宋体">博客</font></a><font face="新宋体">,当时候是用root启动了mysqld_unsafe，在mysql的QPS到1W以上后，会出现ERROR 1135 (HY000): Can’t create a new thread (errno 11); 当时候的解决办法是用mysql用户来启动就解决了问题。但因为在系统重启后，如果用sudo&#160; -u mysql来启动的话，脚本会被卡主。</font></p>
<p><font face="新宋体">这个问题今天得到了一个稍微深入一点的结论。</font></p>
<p><font face="新宋体">首先我们看看这个错误</font></p>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 600px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">ERROR 1135 (HY000): Can’t create a new thread (errno 11);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #0000ff">if</span> you are not out of available memory,
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">you can consult the manual <span style="color: #0000ff">for</span> a possible OS-dependent bug</pre>
</pre>
<p>google类似Can’t create a new thread的错误后，得到的结论是文件描述符不够用，检查了vim /etc/security/limits.conf&#160;&#160; 的设置，是正常的</p>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 600px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">vim /etc/security/limits.conf
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">得到的结果是
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">root    soft    nofile  65535
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">root    hard    nofile  65535
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">admin   soft    nofile  65535
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">admin   hard    nofile  65535
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"># End of file
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">mysql   soft    nproc   65536
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">mysql   hard    nproc   65536
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">mysql   soft    nofile  65535
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">mysql   hard    nofile  65535</pre>
</pre>
<div class="csharpcode">但观察了sudo -u root bash -c &quot; ulimit -a &quot; 后，得到 max user processes&#160;&#160; (-u) 1024</div>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 600px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">core file size          (blocks, -c) 0
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">data seg size           (kbytes, -d) unlimited
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">scheduling priority             (-e) 0
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">file size               (blocks, -f) unlimited
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">pending signals                 (-i) 385957
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">max locked memory       (kbytes, -l) 64
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">max memory size         (kbytes, -m) unlimited
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #0000ff">open</span> files                      (-n) 65535
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">pipe size            (512 bytes, -p) 8
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">POSIX message queues     (bytes, -q) 819200
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">real-<span style="color: #0000ff">time</span> priority              (-r) 0
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">stack size              (kbytes, -s) 10240
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">cpu <span style="color: #0000ff">time</span>               (seconds, -t) unlimited
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">max user processes              (-u) 1024
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">virtual memory          (kbytes, -v) unlimited
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">file locks                      (-x) unlimited</pre>
</pre>
<div class="csharpcode">max user processes&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; (-u) 1024 和 sudo -u root bash -c &quot; ulimit -u &quot;&#160; 一样，都是得到1024的结果</div>
<pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">sudo -u root bash -c &quot;<span style="color: #8b0000"> ulimit -u </span>&quot;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">1024</pre>
</pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>而在redhat5里面，只要在/etc/security/limits.conf&#160; 设置了root&#160;&#160;&#160; soft&#160;&#160;&#160; nofile&#160; 65535 和root&#160;&#160;&#160; hard&#160;&#160;&#160; nofile&#160; 65535，对应的uilmit&#160; -u 就会是65535. </p>
<p>和@维西v @tb天羽 搞了几个小时，依然没法成功修改root用户的 max user processes到65535 。后来发现了<a href="http://dlutzy.wordpress.com/2011/05/19/know-your-limits-ulimits/" target="_blank">一篇文章</a> Know your limits (ulimits)&#160; ，提及到redhat6新增了/etc/security/limits.d/90-nproc.conf，里面的内容是</p>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 600px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"># Default limit <span style="color: #0000ff">for</span> number of user's processes to prevent
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"># accidental fork bombs.
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"># See rhbz #432903 <span style="color: #0000ff">for</span> reasoning.
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">*          soft    nproc     1024</pre>
</pre>
<p><strong><font size="4">redhat6下面，root用户使用ulimit -u没法修改</font></strong></p>
<p>* soft nproc 1024的意思是任何用户的最大max user processes为1024个，其他用户可以通过ulimit -u来修改 ，但root用户则修改不成功，我们这里看一个例子</p>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 600px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">[yingyuan.ydh@my031226 ~]$ cat /etc/security/limits.d/90-nproc.conf
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"># Default limit <span style="color: #0000ff">for</span> number of user's processes to prevent
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"># accidental fork bombs.
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"># See rhbz #432903 <span style="color: #0000ff">for</span> reasoning.
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">*          soft    nproc     1024
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">[yingyuan.ydh@my031226 ~]$ ulimit -u
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">1024
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">[yingyuan.ydh@my031226 ~]$ ulimit -u 65535
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">[yingyuan.ydh@my031226 ~]$ ulimit -u
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">65535
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">[yingyuan.ydh@my031226 ~]$ sudo -uroot bash -c &quot;<span style="color: #8b0000"> ulimit -u 65535</span>&quot;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">[yingyuan.ydh@my031226 ~]$ sudo -uroot bash -c &quot;<span style="color: #8b0000"> ulimit -u </span>&quot;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">1024
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
</pre>
<p>很明显，在redhat6的/etc/security/limits.d/90-nproc.conf限制下，个人用户可以修改ulimit-u,但root用户没法修改。 <strong>解下来，我们把etc/security/limits.d/90-nproc.conf改掉，会看到root的ulimit -u 可以修改成功</strong>。 </p>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 600px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">[yingyuan.ydh@my031226 ~]$ sudo -uroot bash -c &quot;<span style="color: #8b0000"> ulimit -u 65535</span>&quot;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">[yingyuan.ydh@my031226 ~]$ sudo -uroot bash -c &quot;<span style="color: #8b0000"> ulimit -u </span>&quot;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">65535
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">[yingyuan.ydh@my031226 ~]$ cat /etc/security/limits.d/90-nproc.conf
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"># Default limit <span style="color: #0000ff">for</span> number of user's processes to prevent
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"># accidental fork bombs.
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"># See rhbz #432903 <span style="color: #0000ff">for</span> reasoning.
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">*          soft    nproc     65535</pre>
</pre>
<p><strong><font size="4">结果</font></strong></p>
<p><strong><font size="4"></font></strong>在成功修改了root用户的max user processes后，继续使用root用户启动mysqld_safe脚本，稳定运行了一个下午，一切正常。 </p>
<p><strong><font size="4">思考</font></strong></p>
<p>为什么redhat6要做新增一个文件的限制，而不是继续沿用redhat5的方式来管理？ 在微博上面发了一条简单的描述，引起很多人的讨论。 </p>
<p><a href="http://weibo.com/1642466057/y3jM4cz3q">http://weibo.com/1642466057/y3jM4cz3q</a></p>
</p>
<p><font face="新宋体"></font></p>
]]></content:encoded>
			<wfw:commentRss>http://dbahacker.com/linux/redhat5-%e5%92%8credhat6-root%e7%94%a8%e6%88%b7%e4%b8%8d%e5%90%8c%e7%9a%84ulimits/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>遭遇Linux进程状态D</title>
		<link>http://dbahacker.com/linux/%e9%81%ad%e9%81%87linux%e8%bf%9b%e7%a8%8b%e7%8a%b6%e6%80%81d</link>
		<comments>http://dbahacker.com/linux/%e9%81%ad%e9%81%87linux%e8%bf%9b%e7%a8%8b%e7%8a%b6%e6%80%81d#comments</comments>
		<pubDate>Thu, 19 Jan 2012 14:37:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://dbahacker.com/?p=211</guid>
		<description><![CDATA[在一台flashcache的机器上面跑stap脚本 global some_count probe process(@1).function(&#34;*&#34;) { &#160; some_count[tid()] = backtrace() } function print_top() { &#160; foreach (tid+ in some_count) &#160; { &#160;&#160;&#160; print_stack(some_count[tid]) &#160; } } probe timer.s(5) { &#160; print_top() &#160; printf(&#34;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-\n&#34;) } 跑了这个脚本，跑了一会就ctrl+c abort掉，但后台还是有一个D进程的程序，用了好几次kill -9也杀不掉 1 15466 15252 14863 ?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; -1 D&#160;&#160;&#160;&#160;&#160;&#160;&#160; 0&#160;&#160; 0:00 /usr/libexec/systemtap/stapio -u /tmp/stapzHoiGc/stap_b2dc831605d82ca90db5b550e7dfd16a_24607.ko 在Linux里面，进程状态分为task_running,task_interruptiable,task_uninterruptiable，_task_traced _task_stopped 之前一直对task_uninterruptiable不是很理解，这次亲身经历后，对它的认识更加深入。 进程状态为D的进程，一直滞留在CPU run_queue里面，搞得我的其他进程都不能正常运行，尝试了kill –9 [...]]]></description>
			<content:encoded><![CDATA[<p>在一台flashcache的机器上面跑stap脚本</p>
<blockquote><p>global some_count     <br />probe process(@1).function(&quot;*&quot;)      <br />{      <br />&#160; some_count[tid()] = backtrace()      <br />} </p>
<p>function print_top()     <br />{      <br />&#160; foreach (tid+ in some_count)      <br />&#160; {      <br />&#160;&#160;&#160; print_stack(some_count[tid])      <br />&#160; }      <br />} </p>
<p>probe timer.s(5)     <br />{      <br />&#160; print_top()      <br />&#160; printf(&quot;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-\n&quot;)      <br />}</p>
</blockquote>
<p>跑了这个脚本，跑了一会就ctrl+c abort掉，但后台还是有一个D进程的程序，用了好几次kill -9也杀不掉</p>
<blockquote><p>1 15466 15252 14863 ?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; -1 D&#160;&#160;&#160;&#160;&#160;&#160;&#160; 0&#160;&#160; 0:00 /usr/libexec/systemtap/stapio -u /tmp/stapzHoiGc/stap_b2dc831605d82ca90db5b550e7dfd16a_24607.ko</p>
</blockquote>
<p>在Linux里面，进程状态分为task_running,task_interruptiable,task_uninterruptiable，_task_traced _task_stopped</p>
<p>之前一直对task_uninterruptiable不是很理解，这次亲身经历后，对它的认识更加深入。</p>
<p>进程状态为D的进程，一直滞留在CPU run_queue里面，搞得我的其他进程都不能正常运行，尝试了kill –9 ，没办法杀掉。最后只能reboot解决</p>
<p>之所以命名为D，往往是因为I/O资源得不到满足而引发等待。</p>
<p>我们的备库依赖nas服务器来作为备份盘，今年遇到过好几次因为nas的问题，导致mysql的监控一直告警(监控程序需要连接到MySQL,但由于备份脚本因为在写nas的时候，nas在中途卸载掉了，导致脚本一直在等待nas就绪,必须得重新挂载nas才能解决)</p>
<p>&#160;</p>
<p><a href="http://dbahacker.com/wp-content/uploads/2012/01/image4.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://dbahacker.com/wp-content/uploads/2012/01/image_thumb4.png" width="559" height="421" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://dbahacker.com/linux/%e9%81%ad%e9%81%87linux%e8%bf%9b%e7%a8%8b%e7%8a%b6%e6%80%81d/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CPU软中断实践一</title>
		<link>http://dbahacker.com/linux/cpu%e8%bd%af%e4%b8%ad%e6%96%ad%e5%ae%9e%e8%b7%b5%e4%b8%80</link>
		<comments>http://dbahacker.com/linux/cpu%e8%bd%af%e4%b8%ad%e6%96%ad%e5%ae%9e%e8%b7%b5%e4%b8%80#comments</comments>
		<pubDate>Tue, 17 Jan 2012 18:03:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://dbahacker.com/?p=206</guid>
		<description><![CDATA[最近在对一个MySQL项目进行性能测试 QPS在1.1W到1.5W之间波动，但通过tcprstat观察到，响应时间不是非常稳定，会从0.3ms波动到1.9ms 响应时间监控，avg代表的是平均响应时间，单位为微秒，这里可以看到，平均响应时间为0.3ms 到1.7ms之间波动 @淘宝褚霸 在帮忙分析的时候，给了三点建议 1.CPU 2.IO 3.内存 这里先从CPU使用优化来总结一下 1.首先定位系统的CPU占用是否正常，可以使用 命令 mpstat –P ALL&#160; 1 我们可以看到第四颗CPU的idle百分比明显比其他CPU要低好多。那这颗CPU到底在忙什么事情？&#160;&#160;&#160; perf top 工具可以帮我们查看，这颗CPU上面跑的进程的百分比 2. sudo perf top &#8211;cpu=4 输出的结果和oprofile相似，但perf top可以实时来做cpu采样，这点比oprofile要好使得多。 另外一个工具是 taskset ,例如 taskset -p 03 700&#160; 的意思是把pid为700的进程绑定到第四颗CPU上面]]></description>
			<content:encoded><![CDATA[<p>最近在对一个MySQL项目进行性能测试 QPS在1.1W到1.5W之间波动，但通过tcprstat观察到，响应时间不是非常稳定，会从0.3ms波动到1.9ms</p>
<p><a href="http://dbahacker.com/wp-content/uploads/2012/01/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://dbahacker.com/wp-content/uploads/2012/01/image_thumb.png" width="550" height="262" /></a> </p>
<p><font face="宋体">响应时间监控，avg代表的是平均响应时间，单位为微秒，这里可以看到，平均响应时间为0.3ms 到1.7ms之间波动</font></p>
<p><a href="http://dbahacker.com/wp-content/uploads/2012/01/image1.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://dbahacker.com/wp-content/uploads/2012/01/image_thumb1.png" width="540" height="154" /></a> </p>
<p><font face="宋体"><a href="http://weibo.com/tchuba" target="_blank">@淘宝褚霸</a> 在帮忙分析的时候，给了三点建议 1.CPU 2.IO 3.内存 这里先从CPU使用优化来总结一下</font></p>
<p><font face="宋体">1.首先定位系统的CPU占用是否正常，可以使用 命令 mpstat –P ALL&#160; 1</font><a href="http://dbahacker.com/wp-content/uploads/2012/01/image2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://dbahacker.com/wp-content/uploads/2012/01/image_thumb2.png" width="548" height="211" /></a> </p>
<p><font face="宋体">我们可以看到第四颗CPU的idle百分比明显比其他CPU要低好多。那这颗CPU到底在忙什么事情？&#160;&#160;&#160; perf top 工具可以帮我们查看，这颗CPU上面跑的进程的百分比</font></p>
<p><font face="宋体">2. <strong>sudo perf top &#8211;cpu=4</strong> </font><a href="http://dbahacker.com/wp-content/uploads/2012/01/image3.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://dbahacker.com/wp-content/uploads/2012/01/image_thumb3.png" width="540" height="344" /></a> </p>
<p>输出的结果和oprofile相似，但perf top可以实时来做cpu采样，这点比oprofile要好使得多。 </p>
</p>
<p>另外一个工具是 taskset ,例如 taskset -p 03 700&#160; 的意思是把pid为700的进程绑定到第四颗CPU上面</p>
]]></content:encoded>
			<wfw:commentRss>http://dbahacker.com/linux/cpu%e8%bd%af%e4%b8%ad%e6%96%ad%e5%ae%9e%e8%b7%b5%e4%b8%80/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ERROR 1135 (HY000): Can&#8217;t create a new thread (errno 11)</title>
		<link>http://dbahacker.com/linux/error-1135-hy000-cant-create-a-new-thread-errno-11</link>
		<comments>http://dbahacker.com/linux/error-1135-hy000-cant-create-a-new-thread-errno-11#comments</comments>
		<pubDate>Mon, 09 Jan 2012 13:33:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://dbahacker.com/?p=171</guid>
		<description><![CDATA[在一台MySQL测试服务器上面，今天遇到了 ERROR 1135 (HY000): Can&#8217;t create a new thread (errno 11); if you are not out of available memory, you can consult the manual for a possible OS-dependent bug 首先使用perror工具看一下 错误代码11代表的意思 perror 11 OS error code 11: Resource temporarily unavailable 资源暂时不可用 google搜索了一下，很多文章说和当前用户的文件描述符ulimit -n有关系 ulimit -n 65535 当时候mysql的服务器load 为0，自然不可能是文件描述符不够导致的问题 第二个检查操作 cat /etc/security/limits.conf 得到的结果是 root soft nofile 65535 root hard nofile 65535 admin soft nofile 65535 admin hard nofile 65535 # End of file mysql soft nproc 65536 mysql hard nproc 65536 mysql soft [...]]]></description>
			<content:encoded><![CDATA[<p>在一台MySQL测试服务器上面，今天遇到了</p>
<p><span style="color: #000000; font-family: 宋体;">ERROR 1135 (HY000): Can&#8217;t create a new thread (errno 11); if you are not out of available memory, you can consult the manual for a possible OS-dependent bug</span></p>
<p>首先使用perror工具看一下 错误代码11代表的意思</p>
<p>perror 11<br />
OS error code  11:  Resource temporarily unavailable<br />
资源暂时不可用<br />
google搜索了一下，很多文章说和当前用户的文件描述符ulimit -n有关系<br />
ulimit -n<br />
65535<br />
当时候mysql的服务器load 为0，自然不可能是文件描述符不够导致的问题<br />
<strong>第二个检查操作</strong> cat /etc/security/limits.conf<br />
得到的结果是<br />
root    soft    nofile  65535<br />
root    hard    nofile  65535<br />
admin   soft    nofile  65535<br />
admin   hard    nofile  65535<br />
# End of file<br />
mysql   soft    nproc   65536<br />
mysql   hard    nproc   65536<br />
mysql   soft    nofile  65535<br />
<strong>第三个检查操作 查看mysql的错误日志</strong><br />
有一个很奇怪的现象，我的mysql是一直跑着的，但错误日志只有前两天的</p>
<p>这个时候，在ps aux | grep mysql的输出中发现 -log-error=/var/log/mysqld.log ，错误日志输出到/var目录下面是不正常的<br />
<span style="color: #000000; font-family: 宋体;">mysql     2086 35.1 37.1 51184004 18388068 ?   Sl   20:25   9:01 </span><br />
<span style="color: #000000; font-family: 宋体;">/u01/mysql/bin/mysqld &#8211;basedir=/u01/mysql &#8211;datadir=/u01/mysql/data &#8211;plugin-dir=/u01/mysql/lib/plugin</span><br />
<span style="color: #000000; font-family: 宋体;"> &#8211;user=mysql &#8211;log-error=/var/log/mysqld.log &#8211;open-files-limit=65535 &#8211;pid-file=/u01/mysql/run/mysqld.pid</span><br />
<span style="color: #000000; font-family: 宋体;"> &#8211;socket=/u01/mysql/run/mysql.sock &#8211;port=3306</span></p>
<p>直觉告诉我mysql用了/etc/my.cnf的内容<br />
/etc/my.cnf的内容<br />
[mysqld]<br />
datadir=/var/lib/mysql<br />
socket=/var/lib/mysql/mysql.sock<br />
user=mysql<br />
# Disabling symbolic-links is recommended to prevent assorted security risks<br />
symbolic-links=0</p>
<p>[mysqld_safe]<br />
log-error=/var/log/mysqld.log<br />
pid-file=/var/run/mysqld/mysqld.pid</p>
<p>最终把mysqld_safe干掉后，用mysqld_safe &#8211;defaults-file=xx.cnf 重新指定my.cnf的位置，mysql就正常跑了<br />
最终原因，<a href="http://weibo.com/rezic7">@维西v</a> 启动mysql的时候没有指定my.cnf的位置，所以导致mysqld_safe使用了/etc/my.cnf这个默认文件<br />
但依然有问题不是很理解<br />
1.为什么读了/etc/my.cnf的时候，mysqld还会继续使用my.cnf配置文件里面的/u01/mysql/data<br />
2.为什么还会继续使用plugin-dir=/u01/mysql/lib/plugin</p>
]]></content:encoded>
			<wfw:commentRss>http://dbahacker.com/linux/error-1135-hy000-cant-create-a-new-thread-errno-11/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>编译Percona MySQL 5.5 +Handler Socket</title>
		<link>http://dbahacker.com/linux/mysql5-5-hs</link>
		<comments>http://dbahacker.com/linux/mysql5-5-hs#comments</comments>
		<pubDate>Wed, 02 Nov 2011 14:32:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://dbahacker.com/?p=161</guid>
		<description><![CDATA[安装准备 Cmake wget http://service-spi.web.cern.ch/service-spi/external/tarFiles/cmake-2.6.4.tar.gz Percona-Server-5.5.16-rel22.0  get http://www.percona.com/redir/downloads/Percona-Server-5.5/Percona-Server-5.5.16-22.0/source/Percona-Server-5.5.16-rel22.0.tar.gz $tar zxf cmake-2.6.4.tar.gz $cd cmake-2.6.4 $./bootstrap $make $sudo make install tar zxvf  Percona-Server-5.5.15-rel22.0.tar.gz cd  Percona-Server-5.5.15-rel22.0 执行 CFLAGS=”-O3&#8243; CXX=gcc CXXFLAGS=”-O3 -felide-constructors -fno-exceptions -fno-rtti” &#160; cmake . \ -DCMAKE_BUILD_TYPE:STRING=Release \ -DSYSCONFDIR:PATH=/u01/mysql \ -DCMAKE_INSTALL_PREFIX:PATH=/u01/mysql \ -DENABLED_PROFILING:BOOL=ON \ -DENABLE_DEBUG_SYNC:BOOL=OFF \ -DMYSQL_DATADIR:PATH=/u01/mysql/data \ -DMYSQL_MAINTAINER_MODE:BOOL=OFF \ -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk,gb2312 \ -DWITH_BIG_TABLES:BOOL=ON \ -DWITH_FAST_MUTEXES:BOOL=ON \ -DENABLE-PROFILING:BOOL=ON \ -DWITH_SSL:STRING=bundled \ -DWITH_UNIT_TESTS:BOOL=OFF \ -DWITH_ZLIB:STRING=bundled \ -DWITH_PARTITION_STORAGE_ENGINE:BOOL=ON \ -DWITH_SERVER_SUFFIX=hxsw \ -DWITH_PLUGINS=heap,csv,partition,innodb_plugin,myisam [...]]]></description>
			<content:encoded><![CDATA[<p>安装准备 Cmake wget http://service-spi.web.cern.ch/service-spi/external/tarFiles/cmake-2.6.4.tar.gz</p>
<p>Percona-Server-5.5.16-rel22.0  get http://www.percona.com/redir/downloads/Percona-Server-5.5/Percona-Server-5.5.16-22.0/source/Percona-Server-5.5.16-rel22.0.tar.gz</p>
<div id="Msg_{738F92AD-B4C8-4D37-976E-797F91F847B1}"><span style="color: #000000; font-family: 宋体;">$tar zxf cmake-2.6.4.tar.gz<br />
$cd cmake-2.6.4<br />
$./bootstrap<br />
$make<br />
$sudo make install</span></div>
<p>tar zxvf  Percona-Server-5.5.15-rel22.0.tar.gz</p>
<p>cd  Percona-Server-5.5.15-rel22.0</p>
<p>执行 CFLAGS=”-O3&#8243; CXX=gcc CXXFLAGS=”-O3 -felide-constructors -fno-exceptions -fno-rtti”</p>
<p>&nbsp;</p>
<pre>cmake . \
  -DCMAKE_BUILD_TYPE:STRING=Release             \
  -DSYSCONFDIR:PATH=/u01/mysql            \
  -DCMAKE_INSTALL_PREFIX:PATH=/u01/mysql  \
  -DENABLED_PROFILING:BOOL=ON                   \
  -DENABLE_DEBUG_SYNC:BOOL=OFF                  \
  -DMYSQL_DATADIR:PATH=/u01/mysql/data    \
  -DMYSQL_MAINTAINER_MODE:BOOL=OFF              \
  -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk,gb2312  \
  -DWITH_BIG_TABLES:BOOL=ON \
  -DWITH_FAST_MUTEXES:BOOL=ON \
  -DENABLE-PROFILING:BOOL=ON \
  -DWITH_SSL:STRING=bundled                     \
  -DWITH_UNIT_TESTS:BOOL=OFF                    \
  -DWITH_ZLIB:STRING=bundled                    \
  -DWITH_PARTITION_STORAGE_ENGINE:BOOL=ON       \
  -DWITH_SERVER_SUFFIX=hxsw                        \
  -DWITH_PLUGINS=heap,csv,partition,innodb_plugin,myisam \
  -DDEFAULT_CHARSET=gbk -DDEFAULT_COLLATION=gbk_chinese_ci -DWITH_EXTRA_CHARSETS=ALL \
  -DENABLED_ASSEMBLER:BOOL=ON                   \
  -DENABLED_LOCAL_INFILE:BOOL=ON                \
  -DENABLED_THREAD_SAFE_CLIENT:BOOL=ON          \
  -DENABLED_EMBEDDED_SERVER:BOOL=OFF             \
  -DWITH_CLIENT_LDFLAGS:STRING=all-static                 \
  -DINSTALL_LAYOUT:STRING=STANDALONE            \
  -DCOMMUNITY_BUILD:BOOL=ON;</pre>
<pre> make -j `cat /proc/cpuinfo  | grep processor | wc -l`</pre>
<pre>make install</pre>
<p>执行/u01/mysql/scripts/mysql_install_db &#8211;basedir=/u01/mysql/</p>
<p>(安装mysql,test数据库，初始化权限)</p>
<p>启动MySQL /u01/mysql/bin/mysqld_safe &#8211;defaults-file=my.cnf &amp;</p>
<p>(my.cnf 请参考/u01/pmysql/support-files 下面的 my-innodb-heavy-4G.cnf文件 ）</p>
<p>启动MySQL后，登录后</p>
<pre>Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.16-log MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql&gt; show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)</pre>
<p>恭喜你，已经安装成功了！</p>
<p><strong>编译Handler Socket</strong></p>
<p>cd Percona-Server-5.5.16-rel22.0/storage/HandlerSocket-Plugin-for-MySQL</p>
<p>./configure  &#8211;with-mysql-source=/home/xxx/Percona-Server-5.5.15-rel21.0 \</p>
<p>&#8211;with-mysql-bindir=/u01/mysql/bin/ &#8211;with-mysql-plugindir=/u01/mysql/lib/plugin</p>
<p>&nbsp;</p>
<p>make -j `cat /proc/cpuinfo  | grep processor | wc -l`</p>
<p>make install</p>
<p>登录到MySQL</p>
<p>mysql&gt;  INSTALL PLUGIN handlersocket SONAME &#8216;handlersocket.so&#8217;;</p>
<p><span class="Apple-style-span" style="font-family: Consolas, Monaco, monospace; font-size: 12px; line-height: 18px; white-space: pre;">mysql&gt; show plugins;</span></p>
<pre>+--------------------------------+----------+--------------------+------------------+---------+
| Name                           | Status   | Type               | Library          | License |
+--------------------------------+----------+--------------------+------------------+---------+
| binlog                         | ACTIVE   | STORAGE ENGINE     | NULL             | GPL     |
| mysql_native_password          | ACTIVE   | AUTHENTICATION     | NULL             | GPL     |
| mysql_old_password             | ACTIVE   | AUTHENTICATION     | NULL             | GPL     |
| MRG_MYISAM                     | ACTIVE   | STORAGE ENGINE     | NULL             | GPL     |
| MEMORY                         | ACTIVE   | STORAGE ENGINE     | NULL             | GPL     |
| MyISAM                         | ACTIVE   | STORAGE ENGINE     | NULL             | GPL     |
| CSV                            | ACTIVE   | STORAGE ENGINE     | NULL             | GPL     |
| BLACKHOLE                      | ACTIVE   | STORAGE ENGINE     | NULL             | GPL     |
| InnoDB                         | ACTIVE   | STORAGE ENGINE     | NULL             | GPL     |
| INNODB_RSEG                    | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_TRX                     | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_LOCKS                   | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_LOCK_WAITS              | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_CMP                     | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_CMP_RESET               | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_CMPMEM                  | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_CMPMEM_RESET            | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_TABLES              | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_TABLESTATS          | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_INDEXES             | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_COLUMNS             | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_FIELDS              | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_FOREIGN             | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_FOREIGN_COLS        | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_STATS               | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_TABLE_STATS             | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_INDEX_STATS             | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_BUFFER_POOL_PAGES       | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_BUFFER_POOL_PAGES_INDEX | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_BUFFER_POOL_PAGES_BLOB  | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| XTRADB_ADMIN_COMMAND           | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| FEDERATED                      | DISABLED | STORAGE ENGINE     | NULL             | GPL     |
| ARCHIVE                        | ACTIVE   | STORAGE ENGINE     | NULL             | GPL     |
| PERFORMANCE_SCHEMA             | ACTIVE   | STORAGE ENGINE     | NULL             | GPL     |
| partition                      | ACTIVE   | STORAGE ENGINE     | NULL             | GPL     |
| handlersocket                  | ACTIVE   | DAEMON             | handlersocket.so | BSD     |
+--------------------------------+----------+--------------------+------------------+---------+
36 rows in set (0.00 sec)</pre>
<pre></pre>
<p>参考资料 Cmake使用   <a href="http://forge.mysql.com/wiki/Autotools_to_CMake_Transition_Guide">http://forge.mysql.com/wiki/Autotools_to_CMake_Transition_Guide</a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://dbahacker.com/linux/mysql5-5-hs/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>binlog_format=ROW/STATEMENT/MIX   对记录不存在的对比</title>
		<link>http://dbahacker.com/linux/binlog_formatrowstatementmix-%e5%af%b9%e8%ae%b0%e5%bd%95%e4%b8%8d%e5%ad%98%e5%9c%a8%e7%9a%84%e5%af%b9%e6%af%94</link>
		<comments>http://dbahacker.com/linux/binlog_formatrowstatementmix-%e5%af%b9%e8%ae%b0%e5%bd%95%e4%b8%8d%e5%ad%98%e5%9c%a8%e7%9a%84%e5%af%b9%e6%af%94#comments</comments>
		<pubDate>Tue, 09 Aug 2011 12:51:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://dbahacker.com/?p=157</guid>
		<description><![CDATA[昨天一台(slave)不停的出现包含HA_ERR_KEY_NOT_FOUND的复制错误 Include/my_base.sh (376行)  #define HA_ERR_KEY_NOT_FOUND    120     /* Didn&#8217;t find key on read or update */ 翻译的意思是查询或者更新操作找不到键值，实际进行测试的时候 ，where查询条件为索引和普通列值的时候，当主库binlog_format=row的时候，slave也会报错HA_ERR_KEY_NOT_FOUND 改slave对应的主库binlog_format=ROW 2. 测试重现 v031082.sqa.cm4   搞两个mysql实例   做主备 主库 /u01/mysql 3306    binlog_format=ROW 备库 /u01/mysql2 3309  binlog_format=STATEMENT 主库 create table t1(id int ,name varchar(100); Insert into table t1 (name) value (‘mysql’); Insert into table t1 (name) value (‘hbase’); Insert into table [...]]]></description>
			<content:encoded><![CDATA[<p>昨天一台(slave)不停的出现包含HA_ERR_KEY_NOT_FOUND的复制错误</p>
<ol>
<li> Include/my_base.sh (376行)  #define HA_ERR_KEY_NOT_FOUND    120     /* Didn&#8217;t find key on read or update */</li>
</ol>
<p>翻译的意思是查询或者更新操作找不到键值，实际进行测试的时候 ，where查询条件为索引和普通列值的时候，当主库binlog_format=row的时候，slave也会报错HA_ERR_KEY_NOT_FOUND</p>
<p>改slave对应的主库binlog_format=ROW</p>
<ol>
<li><strong>2. </strong><strong>测试重现</strong><strong> </strong></li>
</ol>
<p>v031082.sqa.cm4   搞两个mysql实例   做主备</p>
<p>主库 /u01/mysql 3306    binlog_format=ROW</p>
<p>备库 /u01/mysql2 3309  binlog_format=STATEMENT</p>
<p>主库 create table t1(id int ,name varchar(100);</p>
<p>Insert into table t1 (name) value (‘mysql’);</p>
<p>Insert into table t1 (name) value (‘hbase’);</p>
<p>Insert into table t1 (name) value (‘oracle’);</p>
<p>主备库确认三条记录都在,备库清空t1表 .</p>
<p>备库 show slave status\G无告警</p>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td colspan="3" width="869" valign="top">
<p align="center"><strong>ROW</strong><strong>和</strong><strong>STATEMENT</strong><strong>的类似操作对比</strong><strong></strong></p>
</td>
</tr>
<tr>
<td width="207" valign="top">MySQL</td>
<td width="303" valign="top">主库   Binlog_format=row</td>
<td width="359" valign="top">主库的binlog_format=MIX/statement;</td>
</tr>
<tr>
<td width="207" valign="top">v031082.sqa.cm4 3306   Master</td>
<td width="303" valign="top">delete from t1 where  ;</p>
<p>delete from t1 where   name=’hbase’;</td>
<td width="359" valign="top">Delete from t1 where   name=’mysql’</td>
</tr>
<tr>
<td width="207" valign="top">v031082.sqa.cm4 3309   Slave</td>
<td width="303" valign="top">备库此时show slave   status ;会出现</p>
<p>Could not execute   Update_rows event on table test.t1;</p>
<p>Can&#8217;t find record in   &#8216;t1&#8242;, Error_code: 1032;</p>
<p>handler error   HA_ERR_KEY_NOT_FOUND;</p>
<p>the event&#8217;s master log   mysql-bin.000001, end_log_pos 3499</td>
<td width="359" valign="top">备库没有错误信息 （目前线上大部分的MySQL 主库binlog_format=statement,如果TC迁移到MySQL，需要考虑好到底是采用MIX还是ROW）</td>
</tr>
</tbody>
</table>
<p><strong>源码剖析</strong></p>
<p><strong>storage/innodb_plugin/handler/ha_innodb.cc </strong><strong>这里包含index_read(),index_first(),</strong>index_last()函数，这些函数都会判断记录是否存在<strong></strong></p>
<p>/**********************************************************************//**</p>
<p>Positions an index cursor to the index specified in the handle. Fetches the</p>
<p>row if any.</p>
<p>@return  0, HA_ERR_KEY_NOT_FOUND, or error number */</p>
<p>UNIV_INTERN</p>
<p>Int ha_innobase::index_read(</p>
<p>case DB_RECORD_NOT_FOUND:</p>
<p>error = HA_ERR_KEY_NOT_FOUND;</p>
<p>table-&gt;status = STATUS_NOT_FOUND;</p>
<p>break;</p>
<p>}</p>
<p>/********************************************************************//**</p>
<p>Positions a cursor on the first record in an index and reads the</p>
<p>corresponding row to buf.</p>
<p>@return 0, HA_ERR_END_OF_FILE, or error code */</p>
<p>UNIV_INTERN Int ha_innobase::index_first(</p>
<p>if (error == HA_ERR_KEY_NOT_FOUND) {</p>
<p>error = HA_ERR_END_OF_FILE;</p>
<p>}</p>
<p>)</p>
<p>/********************************************************************//**</p>
<p>Positions a cursor on the last record in an index and reads the</p>
<p>corresponding row to buf.</p>
<p>@return 0, HA_ERR_END_OF_FILE, or error code */</p>
<p>UNIV_INTERN  int  ha_innobase::index_last(</p>
<p>if (error == HA_ERR_KEY_NOT_FOUND) {</p>
<p>error = HA_ERR_END_OF_FILE;</p>
<p>}</p>
<p>)</p>
]]></content:encoded>
			<wfw:commentRss>http://dbahacker.com/linux/binlog_formatrowstatementmix-%e5%af%b9%e8%ae%b0%e5%bd%95%e4%b8%8d%e5%ad%98%e5%9c%a8%e7%9a%84%e5%af%b9%e6%af%94/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL5.5.4InnoDB Plugin 新特性＆改进</title>
		<link>http://dbahacker.com/linux/mysql5-5-4innodb-plugin-%e6%96%b0%e7%89%b9%e6%80%a7%ef%bc%86%e6%94%b9%e8%bf%9b</link>
		<comments>http://dbahacker.com/linux/mysql5-5-4innodb-plugin-%e6%96%b0%e7%89%b9%e6%80%a7%ef%bc%86%e6%94%b9%e8%bf%9b#comments</comments>
		<pubDate>Tue, 20 Apr 2010 00:55:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://dbahacker.com/?p=92</guid>
		<description><![CDATA[http://dev.mysql.com/doc/innodb-plugin/1.1/en/innodb-performance.html mysql5.5.4的innodb增加了很多特性 希望在oracle里面，mysql可以继续走下去]]></description>
			<content:encoded><![CDATA[<p>http://dev.mysql.com/doc/innodb-plugin/1.1/en/innodb-performance.html</p>
<p>mysql5.5.4的innodb增加了很多特性 希望在oracle里面，mysql可以继续走下去</p>
]]></content:encoded>
			<wfw:commentRss>http://dbahacker.com/linux/mysql5-5-4innodb-plugin-%e6%96%b0%e7%89%b9%e6%80%a7%ef%bc%86%e6%94%b9%e8%bf%9b/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>查询MySQL已有的用户的三种方法</title>
		<link>http://dbahacker.com/linux/query-users-html</link>
		<comments>http://dbahacker.com/linux/query-users-html#comments</comments>
		<pubDate>Wed, 31 Mar 2010 04:46:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://dbahacker.com/?p=72</guid>
		<description><![CDATA[查询MySQL已有的用户的方法 mysql -h ip -uroot -p123 -e ” 放以下的查询” select * from mysql.User \G select distinct(User) from mysql.user; select db,host,user from mysql.User 对于MySQL DBA 来说，查阅mysql的用户信息是最平常不过的操作了，这里提供几种方法查看 mysql -h ip -uroot -p123 -e ” 放以下的查询” select * from mysql.User \G select distinct(User) from mysql.user; select db,host,user from mysql.User]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">查询MySQL已有的用户的方法</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">mysql -h ip -uroot -p123 -e ” 放以下的查询”</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">select * from mysql.User \G</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">select distinct(User) from mysql.user;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">
<p>select db,host,user from mysql.User</p></div>
<p>对于MySQL DBA 来说，查阅mysql的用户信息是最平常不过的操作了，这里提供几种方法查看</p>
<p>mysql -h ip -uroot -p123 -e ” 放以下的查询”</p>
<p>select * from mysql.User \G</p>
<p>select distinct(User) from mysql.user;</p>
<p>select db,host,user from mysql.User</p>
]]></content:encoded>
			<wfw:commentRss>http://dbahacker.com/linux/query-users-html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>python 使用OptionParser的时候使用中文出错的解决过程</title>
		<link>http://dbahacker.com/linux/python-optionparser-chinese</link>
		<comments>http://dbahacker.com/linux/python-optionparser-chinese#comments</comments>
		<pubDate>Fri, 19 Mar 2010 09:47:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://dbahacker.com/?p=68</guid>
		<description><![CDATA[今天在使用OptionParser的时候，在填写帮助信息的时候使用了中文，却发现报了一系列的错误 代码如下 #!/usr/bin/env python #coding:UTF-8 import ConfigParser,sys try: from optparse import OptionParser except ImportError: try: from optik import OptionParser except ImportError: raise ImportError, &#8216;Requires Python 2.3 or the Optik option parsing library.&#8217; parser = OptionParser() parser.add_option(“-f”,”&#8211;file”,dest=”name”, help=”帮助信息”,metavar=”FILE”) parser.add_option(“-q”,”&#8211;quit”, action =”store_false”,dest=”verbose”,default=”True”, help=”帮助信息”) (options,args) = parser.parse_args() 错误信息 File “get-parser-cn.py”, line 23, in &#60;module&#62; (options,args) = parser.parse_args() File [...]]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">今天在使用OptionParser的时候，在填写帮助信息的时候使用了中文，却发现报了一系列的错误</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">代码如下</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">#!/usr/bin/env python</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">#coding:UTF-8</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import ConfigParser,sys</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">try:</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">from optparse import OptionParser</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">except ImportError:</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">try:</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">from optik import OptionParser</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">except ImportError:</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">raise ImportError, &#8216;Requires Python 2.3 or the Optik option parsing library.&#8217;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">parser = OptionParser()</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">parser.add_option(“-f”,”&#8211;file”,dest=”name”,</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> help=”帮助信息”,metavar=”FILE”)</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">parser.add_option(“-q”,”&#8211;quit”,</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> action =”store_false”,dest=”verbose”,default=”True”,</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> help=”帮助信息”)</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">(options,args) = parser.parse_args()</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">错误信息</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">File “get-parser-cn.py”, line 23, in &lt;module&gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">(options,args) = parser.parse_args()</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">File “/usr/lib/python2.5/optparse.py”, line 1387, in parse_args</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">stop = self._process_args(largs, rargs, values)</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">File “/usr/lib/python2.5/optparse.py”, line 1431, in _process_args</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">self._process_short_opts(rargs, values)</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">File “/usr/lib/python2.5/optparse.py”, line 1538, in _process_short_opts</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">option.process(opt, value, values, self)</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">File “/usr/lib/python2.5/optparse.py”, line 774, in process</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">self.action, self.dest, opt, value, values, parser)</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">File “/usr/lib/python2.5/optparse.py”, line 796, in take_action</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">parser.print_help()</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">File “/usr/lib/python2.5/optparse.py”, line 1657, in print_help</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">file.write(self.format_help().encode(encoding, “replace”))</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">UnicodeDecodeError: &#8216;ascii&#8217; codec can&#8217;t decode byte 0xe5 in position 124: ordinal not in range(128)</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">和 @smallfish9 同学 讨论了一番，并搜索了一些资料后，找到了解决方案如下</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import sys</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">reload(sys) # Python2.5 初始化后会删除 sys.setdefaultencoding 这个方法，我们需要重新载入 ,可以注释掉来试试，会提示没有这个setdefaultencoding方法的</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">#!/usr/bin/env python</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">#coding:UTF-8</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import ConfigParser,sys</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">reload(sys)</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">print sys.getdefaultencoding()</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">sys.setdefaultencoding(&#8216;utf-8&#8242;)</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">try:</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">from optparse import OptionParser</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">except ImportError:</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">try:</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">from optik import OptionParser</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">except ImportError:</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">raise ImportError, &#8216;Requires Python 2.3 or the Optik option parsing library.&#8217;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">parser = OptionParser()</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">parser.add_option(“-f”,”&#8211;file”,dest=”name”,</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> help=”帮助信息”,metavar=”FILE”)</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">parser.add_option(“-q”,”&#8211;quit”,</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> action =”store_false”,dest=”verbose”,default=”True”,</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> help=”帮助信息”)</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">(options,args) = parser.parse_args()</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">再进行 python  get-parser-cn.py -h 的时候，可爱的中文就出来了</div>
<p>今天在使用OptionParser的时候，在填写帮助信息的时候使用了中文，却发现报了一系列的错误</p>
<p>代码如下</p>
<blockquote><p>#!/usr/bin/env python</p>
<p>#coding:UTF-8</p>
<p>import sys</p>
<p>from optparse import OptionParser</p>
<p>parser = OptionParser()</p>
<p>parser.add_option(“-f”,”&#8211;file”,dest=”name”,help=”帮助信息”,metavar=”FILE”)</p>
<p>(options,args) = parser.parse_args()</p></blockquote>
<p><strong>错误信息</strong></p>
<blockquote><p>File “get-parser-cn.py”, line 23, in &lt;module&gt;</p>
<p>(options,args) = parser.parse_args()</p>
<p>File “/usr/lib/python2.5/optparse.py”, line 1387, in parse_args</p>
<p>stop = self._process_args(largs, rargs, values)</p>
<p>File “/usr/lib/python2.5/optparse.py”, line 1431, in _process_args</p>
<p>self._process_short_opts(rargs, values)</p>
<p>File “/usr/lib/python2.5/optparse.py”, line 1538, in _process_short_opts</p>
<p>option.process(opt, value, values, self)</p>
<p>File “/usr/lib/python2.5/optparse.py”, line 774, in process</p>
<p>self.action, self.dest, opt, value, values, parser)</p>
<p>File “/usr/lib/python2.5/optparse.py”, line 796, in take_action</p>
<p>parser.print_help()</p>
<p>File “/usr/lib/python2.5/optparse.py”, line 1657, in print_help</p>
<p>file.write(self.format_help().encode(encoding, “replace”))</p>
<p>UnicodeDecodeError: &#8216;ascii&#8217; codec can&#8217;t decode byte 0xe5 in position 124: ordinal not in range(128)</p></blockquote>
<p>和 @smallfish9 同学 讨论了一番，并搜索了一些资料后，找到了解决方案如下</p>
<p><strong>import sys</strong></p>
<p><strong>reload(sys)</strong> # Python2.5 初始化后会删除 sys.setdefaultencoding 这个方法，我们需要重新载入 ,可以注释掉来试试，会提示没有这个setdefaultencoding方法的</p>
<p>完整的代码</p>
<blockquote><p>#!/usr/bin/env python</p>
<p>#coding:UTF-8</p>
<p>import sys</p>
<p>from optparse import OptionParser</p>
<p>reload(sys)</p>
<p>print sys.getdefaultencoding()</p>
<p>sys.setdefaultencoding(&#8216;utf-8&#8242;)</p>
<p>parser = OptionParser()</p>
<p>parser.add_option(“-f”,”&#8211;file”,dest=”name”,</p>
<p>help=”帮助信息”,metavar=”FILE”)</p>
<p>(options,args) = parser.parse_args()</p></blockquote>
<p>再进行 python  get-parser-cn.py -h 的时候，可爱的中文就出来了</p>
]]></content:encoded>
			<wfw:commentRss>http://dbahacker.com/linux/python-optionparser-chinese/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Slave落后于Master的检查步骤</title>
		<link>http://dbahacker.com/linux/slave%e8%90%bd%e5%90%8e%e4%ba%8emaster%e7%9a%84%e6%a3%80%e6%9f%a5%e6%ad%a5%e9%aa%a4</link>
		<comments>http://dbahacker.com/linux/slave%e8%90%bd%e5%90%8e%e4%ba%8emaster%e7%9a%84%e6%a3%80%e6%9f%a5%e6%ad%a5%e9%aa%a4#comments</comments>
		<pubDate>Tue, 09 Mar 2010 15:28:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL Master Slave]]></category>

		<guid isPermaLink="false">http://dbahacker.com/?p=63</guid>
		<description><![CDATA[前两天一直好好的master-slave，突然出现了几个slave复制严重落后于master的情况，在CU的论坛发了个帖子问大伙slave落后于master的原因分析,一哥们给的答复很专业 “落后的原因一般是master的写压力比较大，因为mysql的同步使用两个线程，一个读取bin-log，一个应用这些log，但是master上一般是多个线程写，所以压力大的时候，会造成从服务器一个线程写入不能及时完成，就会造成落后master了 ” 再后来和公司的前辈讨论了下，总结了如下几个检查步骤 1. 在slave 执行show full processlist ，这个是最直接的方法，发现了Master端对一个大表的某个字段执行了update操作 2. 使用iostat来检查slave的io负载情况(也就是上面那哥们所说的写操作的检查了) 前两天一直好好的master-slave，突然出现了几个slave复制严重落后于master的情况，在CU的论坛发了个帖子问大伙slave落后于master的原因分析,一哥们给的答复很专业 “落后的原因一般是master的写压力比较大，因为mysql的同步使用两个线程，一个读取bin-log，一个应用这些log，但是master上一般是多个线程写，所以压力大的时候，会造成从服务器一个线程写入不能及时完成，就会造成落后master了 ” 再后来和公司的前辈讨论了下，总结了如下几个检查步骤 1. 在slave 执行show full processlist ，这个是最直接的方法，发现了Master端对一个大表的某个字段执行了update操作 2. 使用iostat来检查slave的io负载情况(也就是上面那哥们所说的写操作的检查了)]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste" style="position: absolute; left: -10000px; top: 116px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">前两天一直好好的master-slave，突然出现了几个slave复制严重落后于master的情况，在CU的论坛发了个帖子问大伙slave落后于master的原因分析,一哥们给的答复很专业</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 116px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">“落后的原因一般是master的写压力比较大，因为mysql的同步使用两个线程，一个读取bin-log，一个应用这些log，但是master上一般是多个线程写，所以压力大的时候，会造成从服务器一个线程写入不能及时完成，就会造成落后master了</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 116px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">”</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 116px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>再后来和公司的前辈讨论了下，总结了如下几个检查步骤</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 116px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">1.<span style="white-space: pre;"> </span>在slave 执行show full processlist ，这个是最直接的方法，发现了Master端对一个大表的某个字段执行了update操作</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 116px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">2.<span style="white-space: pre;"> </span>使用iostat来检查slave的io负载情况(也就是上面那哥们所说的写操作的检查了)</div>
<p>前两天一直好好的master-slave，突然出现了几个slave复制严重落后于master的情况，在CU的论坛发了个<a href="http://bbs.chinaunix.net/viewthread.php?tid=1672188" target="_blank">帖子</a>问大伙slave落后于master的原因分析,一哥们给的答复很专业</p>
<p>“落后的原因一般是master的写压力比较大，因为mysql的同步使用两个线程，一个读取bin-log，一个应用这些log，但是master上一般是多个线程写，所以压力大的时候，会造成从服务器一个线程写入不能及时完成，就会造成落后master了</p>
<p>”</p>
<p><span style="white-space: pre;"> </span>再后来和公司的前辈讨论了下，总结了如下几个检查步骤</p>
<p>1.<span style="white-space: pre;"> </span>在slave 执行show full processlist ，这个是最直接的方法，发现了Master端对一个大表的某个字段执行了update操作</p>
<p>2.<span style="white-space: pre;"> </span>使用iostat来检查slave的io负载情况(也就是上面那哥们所说的写操作的检查了)</p>
]]></content:encoded>
			<wfw:commentRss>http://dbahacker.com/linux/slave%e8%90%bd%e5%90%8e%e4%ba%8emaster%e7%9a%84%e6%a3%80%e6%9f%a5%e6%ad%a5%e9%aa%a4/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

