﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-xiaomage234-随笔分类-linux</title><link>http://www.blogjava.net/xiaomage234/category/28167.html</link><description>生命本就是一次凄美的漂流，记忆中放不下的，永远是孩提时代的那一份浪漫与纯真！</description><language>zh-cn</language><lastBuildDate>Sat, 16 Feb 2019 06:39:02 GMT</lastBuildDate><pubDate>Sat, 16 Feb 2019 06:39:02 GMT</pubDate><ttl>60</ttl><item><title>POSIX 线程详解- 一种支持内存共享的简捷工具【转】</title><link>http://www.blogjava.net/xiaomage234/archive/2019/02/16/433640.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Sat, 16 Feb 2019 03:37:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2019/02/16/433640.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/433640.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2019/02/16/433640.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/433640.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/433640.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: from:https://www.ibm.com/developerworks/cn/linux/thread/posix_thread1/index.htmlhttps://www.ibm.com/developerworks/cn/linux/thread/posix_thread2/index.htmlhttps://www.ibm.com/developerworks/cn/linux/t...&nbsp;&nbsp;<a href='http://www.blogjava.net/xiaomage234/archive/2019/02/16/433640.html'>阅读全文</a><img src ="http://www.blogjava.net/xiaomage234/aggbug/433640.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2019-02-16 11:37 <a href="http://www.blogjava.net/xiaomage234/archive/2019/02/16/433640.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>孤儿进程与僵尸进程[转]</title><link>http://www.blogjava.net/xiaomage234/archive/2018/09/03/433354.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Mon, 03 Sep 2018 11:53:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2018/09/03/433354.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/433354.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2018/09/03/433354.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/433354.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/433354.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: from:https://www.cnblogs.com/Anker/p/3271773.html1、前言　　之前在看《unix环境高级编程》第八章进程时候，提到孤儿进程和僵尸进程，一直对这两个概念比较模糊。今天被人问到什么是孤儿进程和僵尸进程，会带来什么问题，怎么解决，我只停留在概念上面，没有深入，倍感惭愧。晚上回来google了一下，再次参考APUE，认真总结一下，加深理解。2、基本概念　　我...&nbsp;&nbsp;<a href='http://www.blogjava.net/xiaomage234/archive/2018/09/03/433354.html'>阅读全文</a><img src ="http://www.blogjava.net/xiaomage234/aggbug/433354.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2018-09-03 19:53 <a href="http://www.blogjava.net/xiaomage234/archive/2018/09/03/433354.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>grep无法查找shell传过来的变量？先注意一下文本格式吧！</title><link>http://www.blogjava.net/xiaomage234/archive/2017/03/01/432352.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Wed, 01 Mar 2017 08:59:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2017/03/01/432352.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/432352.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2017/03/01/432352.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/432352.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/432352.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: from:https://zhangge.net/4703.html昨天，同事告诉我发现一个诡异的问题，grep无法搜索shell中的变量，着实很惊讶。到他所说的服务器上试了下，还真是不行！大概就是这样一个要求：&#9312;、有个文本为userid.txt，里面每一行一个用户id，类似如下：Shell1234500010003000500070009&#9313;、另外还有一个文本为record...&nbsp;&nbsp;<a href='http://www.blogjava.net/xiaomage234/archive/2017/03/01/432352.html'>阅读全文</a><img src ="http://www.blogjava.net/xiaomage234/aggbug/432352.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2017-03-01 16:59 <a href="http://www.blogjava.net/xiaomage234/archive/2017/03/01/432352.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>构建C1000K的服务器(2) – 实现百万连接的comet服务器</title><link>http://www.blogjava.net/xiaomage234/archive/2016/05/26/430658.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Thu, 26 May 2016 03:17:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2016/05/26/430658.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/430658.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2016/05/26/430658.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/430658.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/430658.html</trackback:ping><description><![CDATA[<p style="margin: 18px 0px; color: #555555; font-family: 微软雅黑, arial; font-size: 15px; line-height: 22.5px; background-color: #ffffff;">这是关于&nbsp;<a href="http://www.ideawu.net/blog/tag/c1000k" style="color: #6666cc; text-decoration: none;">C1000K</a>&nbsp;序列文章的第二篇, 在前一篇文章&nbsp;<a href="http://www.ideawu.net/blog/archives/740.html" style="color: #6666cc; text-decoration: none;">构建C1000K的服务器(1) &#8211; 基础</a>&nbsp;中, 介绍了支持 C1000K 的 Linux 系统的内核参数调整和系统设置. 在本篇文章中, 将对一个真正的应用服务器做 C1000K 测试.</p><p style="margin: 18px 0px; color: #555555; font-family: 微软雅黑, arial; font-size: 15px; line-height: 22.5px; background-color: #ffffff;">Comet 服务器是一类逻辑相对简单, 需要高并发连接的服务器. Comet 在网站系统中的应用非常广泛, 可以见这篇日志的介绍:&nbsp;<a href="http://www.ideawu.net/blog/archives/737.html" style="color: #6666cc; text-decoration: none;">http://www.ideawu.net/blog/archives/737.html</a>.</p><h3>HTTP 协议处理</h3><p style="margin: 18px 0px; color: #555555; font-family: 微软雅黑, arial; font-size: 15px; line-height: 22.5px; background-color: #ffffff;">要开发一个支持百万并发连接的 Comet 服务器, 我选择 C/C++ 语言, 当然还有其它的选择如 Erlang, Java 等. 对于一个只支持 long-polling Comet 服务器, 首先要具备解析 HTTP 协议的能力, 我选择 libevent 来处理 HTTP 协议.</p><p style="margin: 18px 0px; color: #555555; font-family: 微软雅黑, arial; font-size: 15px; line-height: 22.5px; background-color: #ffffff;"></p><h3>通道和订阅者管理</h3><p style="margin: 18px 0px; color: #555555; font-family: 微软雅黑, arial; font-size: 15px; line-height: 22.5px; background-color: #ffffff;">服务器在启动的时候, 就预先分配了 100 万个通道对象的空间, 但订阅者对象是按需分配的, 通过内存池方式. 100 万个通道对象和程序的其它数据占用了 24MB 的内存.</p><h3>Benchmark</h3><p style="margin: 18px 0px; color: #555555; font-family: 微软雅黑, arial; font-size: 15px; line-height: 22.5px; background-color: #ffffff;">启动 icomet 服务器:</p><pre style="overflow: auto; font-size: 12px; line-height: 14.4px; margin-left: 20px; padding: 4px 6px; border-left-width: 5px; border-left-style: solid; border-left-color: #88dd88; color: #555555; background: #f3f3f3;">./icomet </pre><p style="margin: 18px 0px; color: #555555; font-family: 微软雅黑, arial; font-size: 15px; line-height: 22.5px; background-color: #ffffff;">服务器监听了 100 个端口, 是为了测试方便, 原因见前一篇文章的分析:&nbsp;<a href="http://www.ideawu.net/blog/archives/740.html" style="color: #6666cc; text-decoration: none;">构建C1000K的服务器(1) &#8211; 基础</a>.</p><p style="margin: 18px 0px; color: #555555; font-family: 微软雅黑, arial; font-size: 15px; line-height: 22.5px; background-color: #ffffff;">然后启动 benchmark 客户端:</p><pre style="overflow: auto; font-size: 12px; line-height: 14.4px; margin-left: 20px; padding: 4px 6px; border-left-width: 5px; border-left-style: solid; border-left-color: #88dd88; color: #555555; background: #f3f3f3;">./tools/benchmark 127.0.0.1 8100 </pre><p style="margin: 18px 0px; color: #555555; font-family: 微软雅黑, arial; font-size: 15px; line-height: 22.5px; background-color: #ffffff;">benchmark 程序每创建十万个连接, 就会暂停, 按回车后继续. 通过 top/ps 查看 icomet 进程的内存占用. 最终, 得出如下数据.</p><table style="border-collapse: collapse; color: #555555; font-family: 微软雅黑, arial; font-size: 15px; line-height: 22.5px; background-color: #ffffff;"><tbody><tr><th style="padding: 4px; border: 1px solid #aaaaaa; background: #dddddd;">连接数</th><th style="padding: 4px; border: 1px solid #aaaaaa; background: #dddddd;">进程VIRT</th><th style="padding: 4px; border: 1px solid #aaaaaa; background: #dddddd;">进程RES</th></tr><tr><td style="padding: 4px; border-style: solid; border-color: #aaaaaa;">0</td><td style="padding: 4px; border-style: solid; border-color: #aaaaaa;">39m</td><td style="padding: 4px; border-style: solid; border-color: #aaaaaa;">24m</td></tr><tr><td style="padding: 4px; border-style: solid; border-color: #aaaaaa;">100000</td><td style="padding: 4px; border-style: solid; border-color: #aaaaaa;">302m</td><td style="padding: 4px; border-style: solid; border-color: #aaaaaa;">288m</td></tr><tr><td style="padding: 4px; border-style: solid; border-color: #aaaaaa;">200000</td><td style="padding: 4px; border-style: solid; border-color: #aaaaaa;">579m</td><td style="padding: 4px; border-style: solid; border-color: #aaaaaa;">565m</td></tr><tr><td style="padding: 4px; border-style: solid; border-color: #aaaaaa;">500000</td><td style="padding: 4px; border-style: solid; border-color: #aaaaaa;">1441m</td><td style="padding: 4px; border-style: solid; border-color: #aaaaaa;">1427m</td></tr><tr><td style="padding: 4px; border-style: solid; border-color: #aaaaaa;">1000000</td><td style="padding: 4px; border-style: solid; border-color: #aaaaaa;">2734m</td><td style="padding: 4px; border-style: solid; border-color: #aaaaaa;">2720m</td></tr></tbody></table><p style="margin: 18px 0px; color: #555555; font-family: 微软雅黑, arial; font-size: 15px; line-height: 22.5px; background-color: #ffffff;">可以看到, 每一个 Comet 连接大约占用了 2.7KB 的内存. 此时, 服务器空闲, 进程占用 CPU 为 0%.</p><p style="margin: 18px 0px; color: #555555; font-family: 微软雅黑, arial; font-size: 15px; line-height: 22.5px; background-color: #ffffff;">项目的代码在:&nbsp;<a href="https://github.com/ideawu/icomet" style="color: #6666cc; text-decoration: none;">https://github.com/ideawu/icomet</a>, 欢迎大家试用, 并反馈你的测试数据.</p><h3>Related posts:</h3><ol style="margin: 8px 0px; color: #555555; font-family: 微软雅黑, arial; font-size: 15px; line-height: 22.5px; background-color: #ffffff;"><li style="margin: 2px 0px;"><a href="http://www.ideawu.net/blog/archives/821.html" rel="bookmark" title="Permanent Link: HTTP 长连接技术 Comet" style="color: #6666cc; text-decoration: none;">HTTP 长连接技术 Comet</a></li><li style="margin: 2px 0px;"><a href="http://www.ideawu.net/blog/archives/740.html" rel="bookmark" title="Permanent Link: 构建C1000K的服务器(1) &#8211; 基础" style="color: #6666cc; text-decoration: none;">构建C1000K的服务器(1) &#8211; 基础</a></li><li style="margin: 2px 0px;"><a href="http://www.ideawu.net/blog/archives/797.html" rel="bookmark" title="Permanent Link: iComet 的一个应用场景" style="color: #6666cc; text-decoration: none;">iComet 的一个应用场景</a></li><li style="margin: 2px 0px;"><a href="http://www.ideawu.net/blog/archives/781.html" rel="bookmark" title="Permanent Link: 长连接技术的应用" style="color: #6666cc; text-decoration: none;">长连接技术的应用</a></li></ol><img src ="http://www.blogjava.net/xiaomage234/aggbug/430658.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2016-05-26 11:17 <a href="http://www.blogjava.net/xiaomage234/archive/2016/05/26/430658.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>构建C1000K的服务器(1) – 基础</title><link>http://www.blogjava.net/xiaomage234/archive/2016/05/26/430657.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Thu, 26 May 2016 03:16:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2016/05/26/430657.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/430657.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2016/05/26/430657.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/430657.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/430657.html</trackback:ping><description><![CDATA[from:http://www.ideawu.net/blog/archives/740.html?cp=2#comments<br /><br /><div style="float: left; width: 640px; margin-top: 0px; color: #555555; font-family: 微软雅黑, arial; font-size: 15px; line-height: 22.5px; background-color: #ffffff;"><p style="margin: 18px 0px;">著名的&nbsp;<a href="http://www.kegel.com/c10k.html" style="color: #6666cc; text-decoration: none;">C10K 问题</a>提出的时候, 正是 2001 年, 到如今 12 年后的 2013 年, C10K 已经不是问题了, 任何一个普通的程序员, 都能利用手边的语言和库, 轻松地写出 C10K 的服务器. 这既得益于软件的进步, 也得益于硬件性能的提高.</p><p style="margin: 18px 0px;">现在, 该是考虑&nbsp;<a href="http://www.ideawu.net/blog/tag/c100k" style="color: #6666cc; text-decoration: none;">C1000K</a>, 也就是百万连接的问题的时候了. 像 Twitter, weibo, Facebook 这些网站, 它们的同时在线用户有上千万, 同时又希望消息能接近实时地推送给用户, 这就需要服务器能维持和上千万用户的 TCP 网络连接, 虽然可以使用成百上千台服务器来支撑这么多用户, 但如果每台服务器能支持一百万连接(C1000K), 那么只需要十台服务器.</p><p style="margin: 18px 0px;">有很多技术声称能解决&nbsp;<a href="http://www.ideawu.net/blog/tag/c100k" style="color: #6666cc; text-decoration: none;">C1000K</a>&nbsp;问题, 例如 Erlang, Java NIO 等等, 不过, 我们应该首先弄明白, 什么因素限制了 C1000K 问题的解决. 主要是这几点:</p><ol style="margin: 8px 0px;"><li style="margin: 2px 0px;"><a href="http://www.ideawu.net/blog/archives/740.html#q1" style="color: #6666cc; text-decoration: none;">操作系统能否支持百万连接?</a></li><li style="margin: 2px 0px;"><a href="http://www.ideawu.net/blog/archives/740.html#q2" style="color: #6666cc; text-decoration: none;">操作系统维持百万连接需要多少内存?</a></li><li style="margin: 2px 0px;"><a href="http://www.ideawu.net/blog/archives/740.html#q3" style="color: #6666cc; text-decoration: none;">应用程序维持百万连接需要多少内存?</a></li><li style="margin: 2px 0px;"><a href="http://www.ideawu.net/blog/archives/740.html#q4" style="color: #6666cc; text-decoration: none;">百万连接的吞吐量是否超过了网络限制?</a></li></ol><p style="margin: 18px 0px;">下面来分别对这几个问题进行分析.</p><h3><a href="http://www.ideawu.net/blog/archives/740.html?cp=2#q1" name="q1" style="color: #6666cc; text-decoration: none;">1. 操作系统能否支持百万连接?</a></h3><p style="margin: 18px 0px;">对于绝大部分&nbsp;<a href="http://www.ideawu.net/blog/category/linux" style="color: #6666cc; text-decoration: none;">Linux</a>&nbsp;操作系统, 默认情况下确实不支持 C1000K! 因为操作系统包含最大打开文件数(Max Open Files)限制, 分为系统全局的, 和进程级的限制.</p><h4>全局限制</h4><p style="margin: 18px 0px;">在 Linux 下执行:</p><pre style="overflow: auto; font-size: 12px; line-height: 14.4px; margin-left: 20px; padding: 4px 6px; border-left-width: 5px; border-left-style: solid; border-left-color: #88dd88; background: #f3f3f3;">cat /proc/sys/fs/file-nr </pre><p style="margin: 18px 0px;">会打印出类似下面的一行输出:</p><pre style="overflow: auto; font-size: 12px; line-height: 14.4px; margin-left: 20px; padding: 4px 6px; border-left-width: 5px; border-left-style: solid; border-left-color: #88dd88; background: #f3f3f3;">5100	0	101747 </pre><p style="margin: 18px 0px;">第三个数字&nbsp;<code>101747</code>&nbsp;就是当前系统的全局最大打开文件数(Max Open Files), 可以看到, 只有 10 万, 所以, 在这台服务器上无法支持 C1000K. 很多系统的这个数值更小, 为了修改这个数值, 用 root 权限修改 /etc/sysctl.conf 文件:</p><pre style="overflow: auto; font-size: 12px; line-height: 14.4px; margin-left: 20px; padding: 4px 6px; border-left-width: 5px; border-left-style: solid; border-left-color: #88dd88; background: #f3f3f3;">fs.file-max = 1020000 net.ipv4.ip_conntrack_max = 1020000 net.ipv4.netfilter.ip_conntrack_max = 1020000 </pre><p style="margin: 18px 0px;">需要重启系统服务生效:</p><pre style="overflow: auto; font-size: 12px; line-height: 14.4px; margin-left: 20px; padding: 4px 6px; border-left-width: 5px; border-left-style: solid; border-left-color: #88dd88; background: #f3f3f3;"># Linux $ sudo sysctl -p /etc/sysctl.conf  # BSD $ sudo /etc/rc.d/sysctl reload </pre><h3>进程限制</h3><p style="margin: 18px 0px;">执行:</p><pre style="overflow: auto; font-size: 12px; line-height: 14.4px; margin-left: 20px; padding: 4px 6px; border-left-width: 5px; border-left-style: solid; border-left-color: #88dd88; background: #f3f3f3;">ulimit -n </pre><p style="margin: 18px 0px;">输出:</p><pre style="overflow: auto; font-size: 12px; line-height: 14.4px; margin-left: 20px; padding: 4px 6px; border-left-width: 5px; border-left-style: solid; border-left-color: #88dd88; background: #f3f3f3;">1024 </pre><p style="margin: 18px 0px;">说明当前 Linux 系统的每一个进程只能最多打开 1024 个文件. 为了支持 C1000K, 你同样需要修改这个限制.</p><p style="margin: 18px 0px;"><strong>临时修改</strong></p><pre style="overflow: auto; font-size: 12px; line-height: 14.4px; margin-left: 20px; padding: 4px 6px; border-left-width: 5px; border-left-style: solid; border-left-color: #88dd88; background: #f3f3f3;">ulimit -n 1020000 </pre><p style="margin: 18px 0px;">不过, 如果你不是 root, 可能不能修改超过 1024, 会报错:</p><pre style="overflow: auto; font-size: 12px; line-height: 14.4px; margin-left: 20px; padding: 4px 6px; border-left-width: 5px; border-left-style: solid; border-left-color: #88dd88; background: #f3f3f3;">-bash: ulimit: open files: cannot modify limit: Operation not permitted </pre><p style="margin: 18px 0px;"><strong>永久修改</strong></p><p style="margin: 18px 0px;">编辑 /etc/security/limits.conf 文件, 加入如下行:</p><pre style="overflow: auto; font-size: 12px; line-height: 14.4px; margin-left: 20px; padding: 4px 6px; border-left-width: 5px; border-left-style: solid; border-left-color: #88dd88; background: #f3f3f3;"># /etc/security/limits.conf work         hard    nofile      1020000 work         soft    nofile      1020000 </pre><p style="margin: 18px 0px;">第一列的&nbsp;<code>work</code>&nbsp;表示 work 用户, 你可以填&nbsp;<code>*</code>, 或者&nbsp;<code>root</code>. 然后保存退出, 重新登录服务器.</p><p style="margin: 18px 0px;">注意: Linux 内核源码中有一个常量(NR_OPEN in /usr/include/linux/fs.h), 限制了最大打开文件数, 如 RHEL 5 是 1048576(2^20), 所以, 要想支持&nbsp;<a href="http://www.ideawu.net/blog/tag/c1000k" style="color: #6666cc; text-decoration: none;">C1000K</a>, 你可能还需要重新编译内核.</p><h3><a href="http://www.ideawu.net/blog/archives/740.html?cp=2#q2" name="q2" style="color: #6666cc; text-decoration: none;">2. 操作系统维持百万连接需要多少内存?</a></h3><p style="margin: 18px 0px;">解决了操作系统的参数限制, 接下来就要看看内存的占用情况. 首先, 是操作系统本身维护这些连接的内存占用. 对于 Linux 操作系统, socket(fd) 是一个整数, 所以, 猜想操作系统管理一百万个连接所占用的内存应该是 4M/8M, 再包括一些管理信息, 应该会是 100M 左右. 不过, 还有 socket 发送和接收缓冲区所占用的内存没有分析. 为此, 我写了最原始的 C 网络程序来验证:</p><h4>服务器</h4><pre style="overflow: auto; font-size: 12px; line-height: 14.4px; margin-left: 20px; padding: 4px 6px; border-left-width: 5px; border-left-style: solid; border-left-color: #88dd88; background: #f3f3f3;">#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; #include &lt;unistd.h&gt; #include &lt;errno.h&gt; #include &lt;arpa/inet.h&gt; #include &lt;netinet/tcp.h&gt; #include &lt;sys/select.h&gt;  #define MAX_PORTS 10  int main(int argc, char **argv){     struct sockaddr_in addr;     const char *ip = "0.0.0.0";     int opt = 1;     int bufsize;     socklen_t optlen;     int connections = 0;     int base_port = 7000;     if(argc &gt; 2){         base_port = atoi(argv[1]);     }      int server_socks[MAX_PORTS];      for(int i=0; i&lt;MAX_PORTS; i++){         int port = base_port + i;         bzero(&amp;addr, sizeof(addr));         addr.sin_family = AF_INET;         addr.sin_port = htons((short)port);         inet_pton(AF_INET, ip, &amp;addr.sin_addr);          int serv_sock;         if((serv_sock = socket(AF_INET, SOCK_STREAM, 0)) == -1){             goto sock_err;         }         if(setsockopt(serv_sock, SOL_SOCKET, SO_REUSEADDR, &amp;opt, sizeof(opt)) == -1){             goto sock_err;         }         if(bind(serv_sock, (struct sockaddr *)&amp;addr, sizeof(addr)) == -1){             goto sock_err;         }         if(listen(serv_sock, 1024) == -1){             goto sock_err;         }          server_socks[i] = serv_sock;         printf("server listen on port: %d\n", port);     }      //optlen = sizeof(bufsize);     //getsockopt(serv_sock, SOL_SOCKET, SO_RCVBUF, &amp;bufsize, &amp;optlen);     //printf("default send/recv buf size: %d\n", bufsize);      while(1){         fd_set readset;         FD_ZERO(&amp;readset);         int maxfd = 0;         for(int i=0; i&lt;MAX_PORTS; i++){             FD_SET(server_socks[i], &amp;readset);             if(server_socks[i] &gt; maxfd){                 maxfd = server_socks[i];             }         }         int ret = select(maxfd + 1, &amp;readset, NULL, NULL, NULL);         if(ret &lt; 0){             if(errno == EINTR){                 continue;             }else{                 printf("select error! %s\n", strerror(errno));                 exit(0);             }         }          if(ret &gt; 0){             for(int i=0; i&lt;MAX_PORTS; i++){                 if(!FD_ISSET(server_socks[i], &amp;readset)){                     continue;                 }                 socklen_t addrlen = sizeof(addr);                 int sock = accept(server_socks[i], (struct sockaddr *)&amp;addr, &amp;addrlen);                 if(sock == -1){                     goto sock_err;                 }                 connections ++;                 printf("connections: %d, fd: %d\n", connections, sock);             }         }     }      return 0; sock_err:     printf("error: %s\n", strerror(errno));     return 0; } </pre><p style="margin: 18px 0px;">注意, 服务器监听了 10 个端口, 这是为了测试方便. 因为只有一台客户端测试机, 最多只能跟同一个 IP 端口创建 30000 多个连接, 所以服务器监听了 10 个端口, 这样一台测试机就可以和服务器之间创建 30 万个连接了.</p><h4>客户端</h4><pre style="overflow: auto; font-size: 12px; line-height: 14.4px; margin-left: 20px; padding: 4px 6px; border-left-width: 5px; border-left-style: solid; border-left-color: #88dd88; background: #f3f3f3;">#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; #include &lt;unistd.h&gt; #include &lt;errno.h&gt; #include &lt;arpa/inet.h&gt; #include &lt;netinet/tcp.h&gt;  int main(int argc, char **argv){     if(argc &lt;=  2){         printf("Usage: %s ip port\n", argv[0]);         exit(0);     }      struct sockaddr_in addr;     const char *ip = argv[1];     int base_port = atoi(argv[2]);     int opt = 1;     int bufsize;     socklen_t optlen;     int connections = 0;      bzero(&amp;addr, sizeof(addr));     addr.sin_family = AF_INET;     inet_pton(AF_INET, ip, &amp;addr.sin_addr);      char tmp_data[10];     int index = 0;     while(1){         if(++index &gt;= 10){             index = 0;         }         int port = base_port + index;         printf("connect to %s:%d\n", ip, port);          addr.sin_port = htons((short)port);          int sock;         if((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1){             goto sock_err;         }         if(connect(sock, (struct sockaddr *)&amp;addr, sizeof(addr)) == -1){             goto sock_err;         }          connections ++;         printf("connections: %d, fd: %d\n", connections, sock);          if(connections % 10000 == 9999){             printf("press Enter to continue: ");             getchar();         }         usleep(1 * 1000);         /*            bufsize = 5000;            setsockopt(serv_sock, SOL_SOCKET, SO_SNDBUF, &amp;bufsize, sizeof(bufsize));            setsockopt(serv_sock, SOL_SOCKET, SO_RCVBUF, &amp;bufsize, sizeof(bufsize));          */     }      return 0; sock_err:     printf("error: %s\n", strerror(errno));     return 0; } </pre><p style="margin: 18px 0px;">我测试 10 万个连接, 这些连接是空闲的, 什么数据也不发送也不接收. 这时, 进程只占用了不到 1MB 的内存. 但是, 通过程序退出前后的 free 命令对比, 发现操作系统用了 200M(大致)内存来维护这 10 万个连接! 如果是百万连接的话, 操作系统本身就要占用 2GB 的内存! 也即 2KB 每连接.</p><p style="margin: 18px 0px;">可以修改</p><pre style="overflow: auto; font-size: 12px; line-height: 14.4px; margin-left: 20px; padding: 4px 6px; border-left-width: 5px; border-left-style: solid; border-left-color: #88dd88; background: #f3f3f3;">/proc/sys/net/ipv4/tcp_wmem /proc/sys/net/ipv4/tcp_rmem </pre><p style="margin: 18px 0px;">来控制 TCP 连接的发送和接收缓冲的大小(多谢 @<a href="http://www.cnblogs.com/egmkang" style="color: #6666cc; text-decoration: none;">egmkang</a>).</p><h3><a href="http://www.ideawu.net/blog/archives/740.html?cp=2#q3" name="q3" style="color: #6666cc; text-decoration: none;">3. 应用程序维持百万连接需要多少内存?</a></h3><p style="margin: 18px 0px;">通过上面的测试代码, 可以发现, 应用程序维持百万个空闲的连接, 只会占用操作系统的内存, 通过 ps 命令查看可知, 应用程序本身几乎不占用内存.</p><h3><a href="http://www.ideawu.net/blog/archives/740.html?cp=2#q4" name="q4" style="color: #6666cc; text-decoration: none;">4. 百万连接的吞吐量是否超过了网络限制?</a></h3><p style="margin: 18px 0px;">假设百万连接中有 20% 是活跃的, 每个连接每秒传输 1KB 的数据, 那么需要的网络带宽是 0.2M x 1KB/s x 8 = 1.6Gbps, 要求服务器至少是万兆网卡(10Gbps).</p><h3>总结</h3><p style="margin: 18px 0px;">Linux 系统需要修改内核参数和系统配置, 才能支持 C1000K. C1000K 的应用要求服务器至少需要 2GB 内存, 如果应用本身还需要内存, 这个要求应该是至少 10GB 内存. 同时, 网卡应该至少是万兆网卡.</p><p style="margin: 18px 0px;">当然, 这仅仅是理论分析, 实际的应用需要更多的内存和 CPU 资源来处理业务数据.</p><p style="margin: 18px 0px;">参考:</p><p style="margin: 18px 0px;">*&nbsp;<a href="http://www.cyberciti.biz/faq/linux-increase-the-maximum-number-of-open-files/" style="color: #6666cc; text-decoration: none;">http://www.cyberciti.biz/faq/linux-increase-the-maximum-number-of-open-files/</a><br />*&nbsp;<a href="http://www.lognormal.com/blog/2012/09/27/linux-tcpip-tuning/" style="color: #6666cc; text-decoration: none;">http://www.lognormal.com/blog/2012/09/27/linux-tcpip-tuning/</a></p><p style="margin: 18px 0px;">下一篇:&nbsp;<a href="http://www.ideawu.net/blog/archives/742.html" style="color: #6666cc; text-decoration: none;">构建C1000K的服务器(2) &#8211; 实现</a></p><h3>Related posts:</h3><ol style="margin: 8px 0px;"><li style="margin: 2px 0px;"><a href="http://www.ideawu.net/blog/archives/706.html" rel="bookmark" title="Permanent Link: 要记得清除 sockaddr_in" style="color: #6666cc; text-decoration: none;">要记得清除 sockaddr_in</a></li><li style="margin: 2px 0px;"><a href="http://www.ideawu.net/blog/archives/742.html" rel="bookmark" title="Permanent Link: 构建C1000K的服务器(2) &#8211; 实现百万连接的comet服务器" style="color: #6666cc; text-decoration: none;">构建C1000K的服务器(2) &#8211; 实现百万连接的comet服务器</a></li><li style="margin: 2px 0px;"><a href="http://www.ideawu.net/blog/archives/244.html" rel="bookmark" title="Permanent Link: 数据传输中的停止等待机制的实现" style="color: #6666cc; text-decoration: none;">数据传输中的停止等待机制的实现</a></li><li style="margin: 2px 0px;"><a href="http://www.ideawu.net/blog/archives/739.html" rel="bookmark" title="Permanent Link: Libevent 2 HTTP 客户端示例" style="color: #6666cc; text-decoration: none;">Libevent 2 HTTP 客户端示例</a></li><li style="margin: 2px 0px;"><a href="http://www.ideawu.net/blog/archives/789.html" rel="bookmark" title="Permanent Link: 有趣的 main 函数参数" style="color: #6666cc; text-decoration: none;">有趣的 main 函数参数</a></li></ol></div><div style="float: left; width: 640px; margin-top: 4px; color: #555555; font-family: 微软雅黑, arial; font-size: 15px; line-height: 22.5px; background-color: #ffffff;">Posted by&nbsp;<strong>ideawu</strong>&nbsp;at 2013-09-16 22:01:16	Tags:&nbsp;<a href="http://www.ideawu.net/blog/tag/c1000k" rel="tag" style="color: #6666cc; text-decoration: none;">C1000K</a>,&nbsp;<a href="http://www.ideawu.net/blog/tag/%e9%ab%98%e5%b9%b6%e5%8f%91" rel="tag" style="color: #6666cc; text-decoration: none;">高并发</a></div><img src ="http://www.blogjava.net/xiaomage234/aggbug/430657.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2016-05-26 11:16 <a href="http://www.blogjava.net/xiaomage234/archive/2016/05/26/430657.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>经典的”服务器最多65536个连接”误解</title><link>http://www.blogjava.net/xiaomage234/archive/2016/05/26/430656.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Thu, 26 May 2016 03:15:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2016/05/26/430656.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/430656.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2016/05/26/430656.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/430656.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/430656.html</trackback:ping><description><![CDATA[from:http://www.ideawu.net/blog/archives/533.html<br /><br /><div style="float: left; width: 640px; margin-top: 0px; color: #555555; font-family: 微软雅黑, arial; font-size: 15px; line-height: 22.5px; background-color: #ffffff;"><p style="margin: 18px 0px;">"因为TCP端口号是16位无符号整数, 最大65535, 所以一台服务器最多支持65536个TCP socket连接." - 一个非常经典的误解! 即使是有多年网络编程经验的人, 也会持有这个错误结论.</p><p style="margin: 18px 0px;">要戳破这个错误结论, 可以从理论和实践两方面来.</p><h3>理论</h3><p style="margin: 18px 0px;">系统通过一个四元组来唯一标识一条TCP连接. 这个四元组的结构是{local_ip, local_port, remote_ip, remote_port}, 对于IPv4, 系统理论上最多可以管理2^(32+16+32+16), 2的96次方个连接.</p><p style="margin: 18px 0px;"><strong>因为对于同一台服务器来说, 一般只有一个 local_ip, 那么, 同一台服务器可以管理 2^(16+32+16) 个连接. 而一个服务(进程, 如 Nginx 进程)一般只监听一个 local_port, 那么, 同一台服务就可以管理 2^(32+16) 个连接. 而如果从一台远端机器(所谓的 client)来连接这台服务器上的一个服务, 那么 local_ip, local_port, remote_ip 这3个变量是固定的, 那么, 就只能建立 2^16=65536 个连接了. 这就是经典的误解的来源!</strong></p><p style="margin: 18px 0px;">如果不仅仅考虑TCP, 则是一个五元组, 加上协议号(TCP, UDP或者其它).</p><p style="margin: 18px 0px;"></p><h3>实践</h3><p style="margin: 18px 0px;">服务器绑定一个ip:port, 然后accept连接, 所有accept的连接使用的本地地址也是同样的ip:port.</p><h3>扩展内容</h3><p style="margin: 18px 0px;">如果某个客户端向同一个TCP端点(ip:port)发起主动连接, 那么每一条连接都必须使用不同的本地TCP端点, 如果客户端只有一个IP则是使用不同的本地端口, 该端口的范围在*nix系统上的一个例子是32768到61000, 可以通过如下命令查看:</p><pre style="overflow: auto; font-size: 12px; line-height: 14.4px; margin-left: 20px; padding: 4px 6px; border-left-width: 5px; border-left-style: solid; border-left-color: #88dd88; background: #f3f3f3;">[root@<a href="http://www.benegg.com/" style="color: #6666cc; text-decoration: none;">benegg.com</a> ~]# cat /proc/sys/net/ipv4/ip_local_port_range  32768   61000 </pre><p style="margin: 18px 0px;">也就是说, 一个客户端连接同一个服务器的同一个ip:port(比如进行压力测试), 最多可以发起30000个左右的连接.</p><p style="margin: 18px 0px;">TCP客户端(TCP的主动发起者)可以在同一ip:port上向不同的服务器发起主动连接, 只需在bind之前对socket设置SO_REUSEADDR选项.</p><p style="margin: 18px 0px;">系统支持的最大打开文件描述符数(包括socket连接):</p><pre style="overflow: auto; font-size: 12px; line-height: 14.4px; margin-left: 20px; padding: 4px 6px; border-left-width: 5px; border-left-style: solid; border-left-color: #88dd88; background: #f3f3f3;">[root@<a href="http://www.benegg.com/" style="color: #6666cc; text-decoration: none;">benegg.com</a> ~]# cat /proc/sys/fs/file-max 580382 </pre><p style="margin: 18px 0px;">单个进程所能打开的最大文件描述符数:</p><pre style="overflow: auto; font-size: 12px; line-height: 14.4px; margin-left: 20px; padding: 4px 6px; border-left-width: 5px; border-left-style: solid; border-left-color: #88dd88; background: #f3f3f3;">[root@<a href="http://www.benegg.com/" style="color: #6666cc; text-decoration: none;">benegg.com</a> ~]# ulimit -n 1024 </pre><h3>结论</h3><p style="margin: 18px 0px;">无论是对于服务器还是客户端, 认为"一台机器最多建立65536个TCP连接"是没有根据的, 理论上远远超过这个值.</p><p style="margin: 18px 0px;">另外, 对于client端, 操作系统会自动根据不同的远端 ip:port, 决定是否重用本地端口.</p><h3>Related posts:</h3><ol style="margin: 8px 0px;"><li style="margin: 2px 0px;"><a href="http://www.ideawu.net/blog/archives/516.html" rel="bookmark" title="Permanent Link: 连连看游戏开发实践(1) &#8211; 算法" style="color: #6666cc; text-decoration: none;">连连看游戏开发实践(1) &#8211; 算法</a></li><li style="margin: 2px 0px;"><a href="http://www.ideawu.net/blog/archives/246.html" rel="bookmark" title="Permanent Link: 对P2P应用不友好的NAT" style="color: #6666cc; text-decoration: none;">对P2P应用不友好的NAT</a></li><li style="margin: 2px 0px;"><a href="http://www.ideawu.net/blog/archives/169.html" rel="bookmark" title="Permanent Link: Tomcat网站server.xml设置" style="color: #6666cc; text-decoration: none;">Tomcat网站server.xml设置</a></li><li style="margin: 2px 0px;"><a href="http://www.ideawu.net/blog/archives/229.html" rel="bookmark" title="Permanent Link: P2P穿透NAT的思路" style="color: #6666cc; text-decoration: none;">P2P穿透NAT的思路</a></li><li style="margin: 2px 0px;"><a href="http://www.ideawu.net/blog/archives/770.html" rel="bookmark" title="Permanent Link: SSDB 的双主和多主配置" style="color: #6666cc; text-decoration: none;">SSDB 的双主和多主配置</a></li></ol></div><div style="float: left; width: 640px; margin-top: 4px; color: #555555; font-family: 微软雅黑, arial; font-size: 15px; line-height: 22.5px; background-color: #ffffff;">Posted by&nbsp;<strong>ideawu</strong>&nbsp;at 2010-07-16 16:44:50</div><img src ="http://www.blogjava.net/xiaomage234/aggbug/430656.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2016-05-26 11:15 <a href="http://www.blogjava.net/xiaomage234/archive/2016/05/26/430656.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>解决libc.so.6: version `GLIBC_2.14' not found问题</title><link>http://www.blogjava.net/xiaomage234/archive/2016/03/10/429593.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Thu, 10 Mar 2016 02:14:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2016/03/10/429593.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/429593.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2016/03/10/429593.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/429593.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/429593.html</trackback:ping><description><![CDATA[<p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">0.以下在系统CentOS 6.3 x86_64上操作</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">1.试图运行程序，提示"libc.so.6: version `GLIBC_2.14' not found",原因是系统的glibc版本太低，软件编译时使用了较高版本的glibc引起的：</p><div bg_cpp"="" style="word-break: break-word; line-height: 24px; background-color: #ffffff;"><ol style="padding-left: 40px;"><li style="list-style-type: decimal; line-height: 1.6;">[ghui@StuOS&nbsp;bin]$&nbsp;pwd&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">/var/VMdisks/cross/mingw32/bin&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">[ghui@StuOS&nbsp;bin]$&nbsp;ls&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">lrelease&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QtCore4.dll&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QtNetwork4.dll&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QtSql4.dll&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QtXml4.dll&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">moc&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QtDeclarative4.dll&nbsp;&nbsp;QtOpenGL4.dll&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QtSvg4.dll&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rcc&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">phonon4.dll&nbsp;&nbsp;QtGui4.dll&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QtScript4.dll&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QtTest4.dll&nbsp;&nbsp;&nbsp;&nbsp;uic&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">qmake&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QtMultimedia4.dll&nbsp;&nbsp;&nbsp;QtScriptTools4.dll&nbsp;&nbsp;QtWebKit4.dll&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">[ghui@StuOS&nbsp;bin]$&nbsp;./qmake&nbsp;&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">./qmake:&nbsp;/lib64/libc.so.6:&nbsp;version&nbsp;`GLIBC_2.14'&nbsp;not&nbsp;found&nbsp;(required&nbsp;by&nbsp;./qmake)&nbsp;&nbsp;</li></ol></div><pre name="code" style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-size: 12px; line-height: 24px; background-color: #ffffff;">[ghui@StuOS bin]$ pwd /var/VMdisks/cross/mingw32/bin [ghui@StuOS bin]$ ls lrelease     QtCore4.dll         QtNetwork4.dll      QtSql4.dll     QtXml4.dll moc          QtDeclarative4.dll  QtOpenGL4.dll       QtSvg4.dll     rcc phonon4.dll  QtGui4.dll          QtScript4.dll       QtTest4.dll    uic qmake        QtMultimedia4.dll   QtScriptTools4.dll  QtWebKit4.dll [ghui@StuOS bin]$ ./qmake  ./qmake: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by ./qmake)  </pre><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">&nbsp;</p><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">2.查看系统glibc支持的版本：</span><br style="margin: 0px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;" /><div bg_cpp"="" style="word-break: break-word; line-height: 24px; background-color: #ffffff;"><ol style="padding-left: 40px;"><li style="list-style-type: decimal; line-height: 1.6;">[ghui@StuOS&nbsp;bin]$&nbsp;strings&nbsp;/lib64/libc.so.6&nbsp;|grep&nbsp;GLIBC_&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">GLIBC_2.2.5&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">GLIBC_2.2.6&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">GLIBC_2.3&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">GLIBC_2.3.2&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">GLIBC_2.3.3&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">GLIBC_2.3.4&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">GLIBC_2.4&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">GLIBC_2.5&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">GLIBC_2.6&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">GLIBC_2.7&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">GLIBC_2.8&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">GLIBC_2.9&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">GLIBC_2.10&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">GLIBC_2.11&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">GLIBC_2.12&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">GLIBC_PRIVATE&nbsp;&nbsp;</li></ol></div><pre name="code" style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-size: 12px; line-height: 24px; background-color: #ffffff;">[ghui@StuOS bin]$ strings /lib64/libc.so.6 |grep GLIBC_ GLIBC_2.2.5 GLIBC_2.2.6 GLIBC_2.3 GLIBC_2.3.2 GLIBC_2.3.3 GLIBC_2.3.4 GLIBC_2.4 GLIBC_2.5 GLIBC_2.6 GLIBC_2.7 GLIBC_2.8 GLIBC_2.9 GLIBC_2.10 GLIBC_2.11 GLIBC_2.12 GLIBC_PRIVATE</pre><div bg_cpp"="" style="word-break: break-word; line-height: 24px; background-color: #ffffff;"><ol style="padding-left: 40px;"><li style="list-style-type: decimal; line-height: 1.6;">[ghui@StuOS&nbsp;bin]$&nbsp;rpm&nbsp;-qa&nbsp;|grep&nbsp;glibc&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">glibc-static-2.12-1.80.el6_3.6.x86_64&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">glibc-headers-2.12-1.80.el6_3.6.x86_64&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">glibc-common-2.12-1.80.el6_3.6.x86_64&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">glibc-devel-2.12-1.80.el6_3.6.x86_64&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">glibc-static-2.12-1.80.el6_3.6.i686&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">glibc-devel-2.12-1.80.el6_3.6.i686&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">glibc-2.12-1.80.el6_3.6.i686&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">glibc-2.12-1.80.el6_3.6.x86_64&nbsp;&nbsp;</li></ol></div><pre name="code" style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-size: 12px; line-height: 24px; background-color: #ffffff;">[ghui@StuOS bin]$ rpm -qa |grep glibc glibc-static-2.12-1.80.el6_3.6.x86_64 glibc-headers-2.12-1.80.el6_3.6.x86_64 glibc-common-2.12-1.80.el6_3.6.x86_64 glibc-devel-2.12-1.80.el6_3.6.x86_64 glibc-static-2.12-1.80.el6_3.6.i686 glibc-devel-2.12-1.80.el6_3.6.i686 glibc-2.12-1.80.el6_3.6.i686 glibc-2.12-1.80.el6_3.6.x86_64 </pre><br style="margin: 0px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;" /><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">3.可以看到最高只支持2.12版本，所以考虑编译解决这个问题：</p><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp;a. 到</span><a href="http://www.gnu.org/software/libc/" target="_blank" style="margin: 0px; padding: 0px; color: #ff6600; text-decoration: none; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">http://www.gnu.org/software/libc/</a><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">下载最新版本，我这里下载了</span><a href="http://mirror.bjtu.edu.cn/gnu/libc/glibc-2.14.tar.xz" target="_blank" style="margin: 0px; padding: 0px; color: #003466; text-decoration: none; line-height: 24px; font-family: Verdana, 'Bitstream Vera Sans', 'DejaVu Sans', sans-serif; font-size: 16px; background-color: #ffffff;">glibc-2.14.tar.xz</a><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">&nbsp;这个版本，解压到任意目录准备编译</span><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp;b.这里解压到/var/VMdisks/glibc-2.14/</p><div bg_cpp"="" style="word-break: break-word; line-height: 24px; background-color: #ffffff;"><ol style="padding-left: 40px;"><li style="list-style-type: decimal; line-height: 1.6;">[ghui@StuOS&nbsp;bin]$&nbsp;cd&nbsp;/var/VMdisks/glibc-2.14/&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">[ghui@StuOS&nbsp;glibc-2.14]$&nbsp;pwd&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">/var/VMdisks/glibc-2.14&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">[ghui@StuOS&nbsp;glibc-2.14]$&nbsp;ls&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">abilist&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;config.h.in&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;intl&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;README.libm&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">abi-tags&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;config.log&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;io&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;resolv&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">aclocal.m4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;config.make.in&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;libc-abis&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;resource&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">aout&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;configure&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;libidn&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rt&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">argp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;configure.in&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;libio&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Rules&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">assert&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conform&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LICENSES&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scripts&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">autom4te.cache&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CONFORMANCE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;locale&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setjmp&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">bits&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;COPYING&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;localedata&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;shadow&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">BUGS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;COPYING.LIB&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;login&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;shlib-versions&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">build&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cppflags-iterator.mk&nbsp;&nbsp;mach&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signal&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">CANCEL-FCT-WAIVE&nbsp;&nbsp;&nbsp;crypt&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Makeconfig&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;socket&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">CANCEL-FILE-WAIVE&nbsp;&nbsp;csu&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Makefile&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;soft-fp&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">catgets&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ctype&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Makefile.in&nbsp;&nbsp;&nbsp;&nbsp;stdio-common&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">ChangeLog&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;debug&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Makerules&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stdlib&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">ChangeLog.1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dirent&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;malloc&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;streams&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">ChangeLog.10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dlfcn&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;manual&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">ChangeLog.11&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;math&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sunrpc&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">ChangeLog.12&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;extra-lib.mk&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;misc&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sysdeps&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">ChangeLog.13&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;extra-modules.mk&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NAMESPACE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sysvipc&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">ChangeLog.14&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FAQ&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NEWS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;termios&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">ChangeLog.15&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FAQ.in&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nis&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;test-skeleton.c&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">ChangeLog.16&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gmon&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NOTES&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;time&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">ChangeLog.17&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gnulib&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nptl&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;timezone&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">ChangeLog.2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;grp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nptl_db&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tls.make.c&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">ChangeLog.3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gshadow&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nscd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;version.h&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">ChangeLog.4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hesiod&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nss&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Versions.def&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">ChangeLog.5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hurd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;o-iterator.mk&nbsp;&nbsp;wcsmbs&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">ChangeLog.6&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;iconv&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;po&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wctype&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">ChangeLog.7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;iconvdata&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;posix&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WUR-REPORT&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">ChangeLog.8&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;include&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PROJECTS&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">ChangeLog.9&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inet&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pwd&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">conf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;INSTALL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;README&nbsp;&nbsp;</li></ol></div><pre name="code" style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-size: 12px; line-height: 24px; background-color: #ffffff;">[ghui@StuOS bin]$ cd /var/VMdisks/glibc-2.14/ [ghui@StuOS glibc-2.14]$ pwd /var/VMdisks/glibc-2.14 [ghui@StuOS glibc-2.14]$ ls abilist            config.h.in           intl           README.libm abi-tags           config.log            io             resolv aclocal.m4         config.make.in        libc-abis      resource aout               configure             libidn         rt argp               configure.in          libio          Rules assert             conform               LICENSES       scripts autom4te.cache     CONFORMANCE           locale         setjmp bits               COPYING               localedata     shadow BUGS               COPYING.LIB           login          shlib-versions build              cppflags-iterator.mk  mach           signal CANCEL-FCT-WAIVE   crypt                 Makeconfig     socket CANCEL-FILE-WAIVE  csu                   Makefile       soft-fp catgets            ctype                 Makefile.in    stdio-common ChangeLog          debug                 Makerules      stdlib ChangeLog.1        dirent                malloc         streams ChangeLog.10       dlfcn                 manual         string ChangeLog.11       elf                   math           sunrpc ChangeLog.12       extra-lib.mk          misc           sysdeps ChangeLog.13       extra-modules.mk      NAMESPACE      sysvipc ChangeLog.14       FAQ                   NEWS           termios ChangeLog.15       FAQ.in                nis            test-skeleton.c ChangeLog.16       gmon                  NOTES          time ChangeLog.17       gnulib                nptl           timezone ChangeLog.2        grp                   nptl_db        tls.make.c ChangeLog.3        gshadow               nscd           version.h ChangeLog.4        hesiod                nss            Versions.def ChangeLog.5        hurd                  o-iterator.mk  wcsmbs ChangeLog.6        iconv                 po             wctype ChangeLog.7        iconvdata             posix          WUR-REPORT ChangeLog.8        include               PROJECTS ChangeLog.9        inet                  pwd conf               INSTALL               README  </pre><br style="margin: 0px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;" /><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; c.在glibc源码目录建立构建目录，并cd进入构建目录</span><div bg_cpp"="" style="word-break: break-word; line-height: 24px; background-color: #ffffff;"><ol style="padding-left: 40px;"><li style="list-style-type: decimal; line-height: 1.6;">[ghui@StuOS&nbsp;glibc-2.14]$&nbsp;mkdir&nbsp;build&nbsp;&nbsp;</li></ol></div><pre name="code" style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-size: 12px; line-height: 24px; background-color: #ffffff;">[ghui@StuOS glibc-2.14]$ mkdir build</pre><div bg_cpp"="" style="word-break: break-word; line-height: 24px; background-color: #ffffff;"><ol style="padding-left: 40px;"><li style="list-style-type: decimal; line-height: 1.6;">[ghui@StuOS&nbsp;glibc-2.14]$&nbsp;cd&nbsp;build&nbsp;&nbsp;</li></ol></div><pre name="code" style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-size: 12px; line-height: 24px; background-color: #ffffff;">[ghui@StuOS glibc-2.14]$ cd build </pre><br style="margin: 0px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;" /><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">&nbsp; &nbsp; d.运行configure配置，make &amp;&amp; sudo &nbsp;make install</span><div bg_cpp"="" style="word-break: break-word; line-height: 24px; background-color: #ffffff;"><ol style="padding-left: 40px;"><li style="list-style-type: decimal; line-height: 1.6;">[ghui@StuOS&nbsp;build]$&nbsp;../configure&nbsp;--prefix=/opt/glibc-2.14&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">[ghui@StuOS&nbsp;build]$&nbsp;make&nbsp;-j4&nbsp;&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">[ghui@StuOS&nbsp;build]$&nbsp;sudo&nbsp;make&nbsp;install&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">[sudo]&nbsp;password&nbsp;for&nbsp;ghui:&nbsp;&nbsp;&nbsp;</li></ol></div><pre name="code" style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-size: 12px; line-height: 24px; background-color: #ffffff;">[ghui@StuOS build]$ ../configure --prefix=/opt/glibc-2.14 [ghui@StuOS build]$ make -j4  [ghui@StuOS build]$ sudo make install [sudo] password for ghui:   </pre><br style="margin: 0px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;" /><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;">4.临时修改环境变量</span><div bg_cpp"="" style="word-break: break-word; line-height: 24px; background-color: #ffffff;"><ol style="padding-left: 40px;"><li style="list-style-type: decimal; line-height: 1.6;">[ghui@StuOS&nbsp;bin]$&nbsp;export&nbsp;LD_LIBRARY_PATH=/opt/glibc-2.14/lib:$LD_LIBRARY_PATH&nbsp;&nbsp;</li></ol></div><pre name="code" style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-size: 12px; line-height: 24px; background-color: #ffffff;">[ghui@StuOS bin]$ export LD_LIBRARY_PATH=/opt/glibc-2.14/lib:$LD_LIBRARY_PATH </pre><div bg_cpp"="" style="word-break: break-word; line-height: 24px; background-color: #ffffff;"><ol style="padding-left: 40px;"><li style="list-style-type: decimal; line-height: 1.6;">[ghui@StuOS&nbsp;glibc-2.14]$&nbsp;cd&nbsp;/var/VMdisks/cross/mingw32/bin/&nbsp;&nbsp;</li></ol></div><pre name="code" style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-size: 12px; line-height: 24px; background-color: #ffffff;">[ghui@StuOS glibc-2.14]$ cd /var/VMdisks/cross/mingw32/bin/ </pre><br style="margin: 0px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; background-color: #ffffff;" /><div bg_cpp"="" style="word-break: break-word; line-height: 24px; background-color: #ffffff;"><ol style="padding-left: 40px;"><li style="list-style-type: decimal; line-height: 1.6;">[ghui@StuOS&nbsp;bin]$&nbsp;./qmake&nbsp;&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">Usage:&nbsp;./qmake&nbsp;[mode]&nbsp;[options]&nbsp;[files]&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">QMake&nbsp;has&nbsp;two&nbsp;modes,&nbsp;one&nbsp;mode&nbsp;for&nbsp;generating&nbsp;project&nbsp;files&nbsp;based&nbsp;on&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">some&nbsp;heuristics,&nbsp;and&nbsp;the&nbsp;other&nbsp;for&nbsp;generating&nbsp;makefiles.&nbsp;Normally&nbsp;you&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">shouldn't&nbsp;need&nbsp;to&nbsp;specify&nbsp;a&nbsp;mode,&nbsp;as&nbsp;makefile&nbsp;generation&nbsp;is&nbsp;the&nbsp;default&nbsp;&nbsp;</li><li style="list-style-type: decimal; line-height: 1.6;">mode&nbsp;for&nbsp;qmake,&nbsp;but&nbsp;you&nbsp;may&nbsp;use&nbsp;this&nbsp;to&nbsp;test&nbsp;qmake&nbsp;on&nbsp;an&nbsp;existing&nbsp;project&nbsp;&nbsp;</li></ol><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px;"><strong style="margin: 0px; padding: 0px;"><span style="margin: 0px; padding: 0px;">From:</span></strong></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px;"><span style="margin: 0px; padding: 0px;">http://blog.csdn.net/cpplang/article/details/8462768</span></p></div><img src ="http://www.blogjava.net/xiaomage234/aggbug/429593.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2016-03-10 10:14 <a href="http://www.blogjava.net/xiaomage234/archive/2016/03/10/429593.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用十条命令在一分钟内检查Linux服务器性能</title><link>http://www.blogjava.net/xiaomage234/archive/2015/12/25/428827.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Fri, 25 Dec 2015 08:30:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2015/12/25/428827.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/428827.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2015/12/25/428827.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/428827.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/428827.html</trackback:ping><description><![CDATA[<p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;">如果你的Linux服务器突然负载暴增，告警短信快发爆你的手机，如何在最短时间内找出Linux性能问题所在？来看Netflix性能工程团队的这篇<a href="http://techblog.netflix.com/2015/11/linux-performance-analysis-in-60s.html" style="text-decoration: none; color: #286ab2; outline: none !important; margin: 0px; border: 0px; padding: 0px;">博文</a>，看它们通过十条命令在一分钟内对机器性能问题进行诊断。</p><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;"><span style="font-weight: 600; margin: 0px; border: 0px; padding: 0px;">概述</span></p><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;">通过执行以下命令，可以在1分钟内对系统资源使用情况有个大致的了解。</p><ul style="margin: 0px 0px 15px 10px; padding: 0px; border: 0px; clear: left; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;"><li style="margin: 0px 0px 0px 15px; padding: 0px; border: 0px; float: none; clear: none;">uptime</li><li style="margin: 0px 0px 0px 15px; padding: 0px; border: 0px; float: none; clear: none;">dmesg | tail</li><li style="margin: 0px 0px 0px 15px; padding: 0px; border: 0px; float: none; clear: none;">vmstat 1</li><li style="margin: 0px 0px 0px 15px; padding: 0px; border: 0px; float: none; clear: none;">mpstat -P ALL 1</li><li style="margin: 0px 0px 0px 15px; padding: 0px; border: 0px; float: none; clear: none;">pidstat 1</li><li style="margin: 0px 0px 0px 15px; padding: 0px; border: 0px; float: none; clear: none;">iostat -xz 1</li><li style="margin: 0px 0px 0px 15px; padding: 0px; border: 0px; float: none; clear: none;">free -m</li><li style="margin: 0px 0px 0px 15px; padding: 0px; border: 0px; float: none; clear: none;">sar -n DEV 1</li><li style="margin: 0px 0px 0px 15px; padding: 0px; border: 0px; float: none; clear: none;">sar -n TCP,ETCP 1</li><li style="margin: 0px 0px 0px 15px; padding: 0px; border: 0px; float: none; clear: none;">top</li></ul><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;">其中一些命令需要安装sysstat包，有一些由procps包提供。这些命令的输出，有助于快速定位性能瓶颈，检查出所有资源（CPU、内存、磁盘IO等）的利用率（utilization）、饱和度（saturation）和错误（error）度量，也就是所谓的<a href="http://www.brendangregg.com/usemethod.html" style="text-decoration: none; color: #286ab2; outline: none !important; margin: 0px; border: 0px; padding: 0px;">USE方法</a>。</p><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;">下面我们来逐一介绍下这些命令，有关这些命令更多的参数和说明，请参照命令的手册。</p><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;"><span style="font-weight: 600; margin: 0px; border: 0px; padding: 0px;">uptime</span></p><pre style="margin-top: 10px; margin-bottom: 10px; padding: 10px 10px 10px 5px; border: 1px solid #e8e8e8; font-family: Consolas, Monaco, 'Andale Mono', monospace; color: #314e64; width: 597.796875px; overflow: auto; clear: none; float: none !important; background-color: #f5f2f0; background-position: -29px 0px;">$ uptime 23:51:26 up 21:31,  1 user,  load average: 30.02, 26.43, 19.02 </pre><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;">这个命令可以快速查看机器的负载情况。在Linux系统中，这些数据表示等待CPU资源的进程和阻塞在不可中断IO进程（进程状态为D）的数量。这些数据可以让我们对系统资源使用有一个宏观的了解。</p><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;">命令的输出分别表示1分钟、5分钟、15分钟的平均负载情况。通过这三个数据，可以了解服务器负载是在趋于紧张还是区域缓解。如果1分钟平均负载很高，而15分钟平均负载很低，说明服务器正在命令高负载情况，需要进一步排查CPU资源都消耗在了哪里。反之，如果15分钟平均负载很高，1分钟平均负载较低，则有可能是CPU资源紧张时刻已经过去。</p><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;">上面例子中的输出，可以看见最近1分钟的平均负载非常高，且远高于最近15分钟负载，因此我们需要继续排查当前系统中有什么进程消耗了大量的资源。可以通过下文将会介绍的vmstat、mpstat等命令进一步排查。</p><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;"><span style="font-weight: 600; margin: 0px; border: 0px; padding: 0px;">dmesg | tail</span></p><pre style="margin-top: 10px; margin-bottom: 10px; padding: 10px 10px 10px 5px; border: 1px solid #e8e8e8; font-family: Consolas, Monaco, 'Andale Mono', monospace; color: #314e64; width: 597.796875px; overflow: auto; clear: none; float: none !important; background-color: #f5f2f0; background-position: -29px 0px;">$ dmesg | tail [1880957.563150] perl invoked oom-killer: gfp_mask=0x280da, order=0, oom_score_adj=0 [...] [1880957.563400] Out of memory: Kill process 18694 (perl) score 246 or sacrifice child [1880957.563408] Killed process 18694 (perl) total-vm:1972392kB, anon-rss:1953348kB, file-rss:0kB [2320864.954447] TCP: Possible SYN flooding on port 7001. Dropping request.  Check SNMP counters. </pre><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;">该命令会输出系统日志的最后10行。示例中的输出，可以看见一次内核的oom kill和一次TCP丢包。这些日志可以帮助排查性能问题。千万不要忘了这一步。</p><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;"><span style="font-weight: 600; margin: 0px; border: 0px; padding: 0px;">vmstat 1</span></p><pre style="margin-top: 10px; margin-bottom: 10px; padding: 10px 10px 10px 5px; border: 1px solid #e8e8e8; font-family: Consolas, Monaco, 'Andale Mono', monospace; color: #314e64; width: 597.796875px; overflow: auto; clear: none; float: none !important; background-color: #f5f2f0; background-position: -29px 0px;">$ vmstat 1 procs ---------memory---------- ---swap-- -----io---- -system-- ------cpu-----  r  b swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st 34  0    0 200889792  73708 591828    0    0     0     5    6   10 96  1  3  0  0 32  0    0 200889920  73708 591860    0    0     0   592 13284 4282 98  1  1  0  0 32  0    0 200890112  73708 591860    0    0     0     0 9501 2154 99  1  0  0  0 32  0    0 200889568  73712 591856    0    0     0    48 11900 2459 99  0  0  0  0 32  0    0 200890208  73712 591860    0    0     0     0 15898 4840 98  1  1  0  0 ^C </pre><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;">vmstat(8) 命令，每行会输出一些系统核心指标，这些指标可以让我们更详细的了解系统状态。后面跟的参数1，表示每秒输出一次统计信息，表头提示了每一列的含义，这几介绍一些和性能调优相关的列：</p><ul style="margin: 0px 0px 15px 10px; padding: 0px; border: 0px; clear: left; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;"><li style="margin: 0px 0px 0px 15px; padding: 0px; border: 0px; float: none; clear: none;">r：等待在CPU资源的进程数。这个数据比平均负载更加能够体现CPU负载情况，数据中不包含等待IO的进程。如果这个数值大于机器CPU核数，那么机器的CPU资源已经饱和。</li><li style="margin: 0px 0px 0px 15px; padding: 0px; border: 0px; float: none; clear: none;">free：系统可用内存数（以千字节为单位），如果剩余内存不足，也会导致系统性能问题。下文介绍到的free命令，可以更详细的了解系统内存的使用情况。</li><li style="margin: 0px 0px 0px 15px; padding: 0px; border: 0px; float: none; clear: none;">si, so：交换区写入和读取的数量。如果这个数据不为0，说明系统已经在使用交换区（swap），机器物理内存已经不足。</li><li style="margin: 0px 0px 0px 15px; padding: 0px; border: 0px; float: none; clear: none;">us, sy, id, wa, st：这些都代表了CPU时间的消耗，它们分别表示用户时间（user）、系统（内核）时间（sys）、空闲时间（idle）、IO等待时间（wait）和被偷走的时间（stolen，一般被其他虚拟机消耗）。</li></ul><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;">上述这些CPU时间，可以让我们很快了解CPU是否出于繁忙状态。一般情况下，如果用户时间和系统时间相加非常大，CPU出于忙于执行指令。如果IO等待时间很长，那么系统的瓶颈可能在磁盘IO。</p><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;">示例命令的输出可以看见，大量CPU时间消耗在用户态，也就是用户应用程序消耗了CPU时间。这不一定是性能问题，需要结合r队列，一起分析。</p><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;"><span style="font-weight: 600; margin: 0px; border: 0px; padding: 0px;">mpstat -P ALL 1</span></p><pre style="margin-top: 10px; margin-bottom: 10px; padding: 10px 10px 10px 5px; border: 1px solid #e8e8e8; font-family: Consolas, Monaco, 'Andale Mono', monospace; color: #314e64; width: 597.796875px; overflow: auto; clear: none; float: none !important; background-color: #f5f2f0; background-position: -29px 0px;">$ mpstat -P ALL 1 Linux 3.13.0-49-generic (titanclusters-xxxxx)  07/14/2015  _x86_64_ (32 CPU) 07:38:49 PM  CPU   %usr  %nice   %sys %iowait   %irq  %soft  %steal  %guest  %gnice  %idle 07:38:50 PM  all  98.47   0.00   0.75    0.00   0.00   0.00    0.00    0.00    0.00   0.78 07:38:50 PM    0  96.04   0.00   2.97    0.00   0.00   0.00    0.00    0.00    0.00   0.99 07:38:50 PM    1  97.00   0.00   1.00    0.00   0.00   0.00    0.00    0.00    0.00   2.00 07:38:50 PM    2  98.00   0.00   1.00    0.00   0.00   0.00    0.00    0.00    0.00   1.00 07:38:50 PM    3  96.97   0.00   0.00    0.00   0.00   0.00    0.00    0.00    0.00   3.03 [...] </pre><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;">该命令可以显示每个CPU的占用情况，如果有一个CPU占用率特别高，那么有可能是一个单线程应用程序引起的。</p><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;"><span style="font-weight: 600; margin: 0px; border: 0px; padding: 0px;">pidstat 1</span></p><pre style="margin-top: 10px; margin-bottom: 10px; padding: 10px 10px 10px 5px; border: 1px solid #e8e8e8; font-family: Consolas, Monaco, 'Andale Mono', monospace; color: #314e64; width: 597.796875px; overflow: auto; clear: none; float: none !important; background-color: #f5f2f0; background-position: -29px 0px;">$ pidstat 1 Linux 3.13.0-49-generic (titanclusters-xxxxx)  07/14/2015    _x86_64_    (32 CPU) 07:41:02 PM   UID       PID    %usr %system  %guest    %CPU   CPU  Command 07:41:03 PM     0         9    0.00    0.94    0.00    0.94     1  rcuos/0 07:41:03 PM     0      4214    5.66    5.66    0.00   11.32    15  mesos-slave 07:41:03 PM     0      4354    0.94    0.94    0.00    1.89     8  java 07:41:03 PM     0      6521 1596.23    1.89    0.00 1598.11    27  java 07:41:03 PM     0      6564 1571.70    7.55    0.00 1579.25    28  java 07:41:03 PM 60004     60154    0.94    4.72    0.00    5.66     9  pidstat 07:41:03 PM   UID       PID    %usr %system  %guest    %CPU   CPU  Command 07:41:04 PM     0      4214    6.00    2.00    0.00    8.00    15  mesos-slave 07:41:04 PM     0      6521 1590.00    1.00    0.00 1591.00    27  java 07:41:04 PM     0      6564 1573.00   10.00    0.00 1583.00    28  java 07:41:04 PM   108      6718    1.00    0.00    0.00    1.00     0  snmp-pass 07:41:04 PM 60004     60154    1.00    4.00    0.00    5.00     9  pidstat ^C </pre><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;">pidstat命令输出进程的CPU占用率，该命令会持续输出，并且不会覆盖之前的数据，可以方便观察系统动态。如上的输出，可以看见两个JAVA进程占用了将近1600%的CPU时间，既消耗了大约16个CPU核心的运算资源。</p><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;"><span style="font-weight: 600; margin: 0px; border: 0px; padding: 0px;">iostat -xz 1</span></p><pre style="margin-top: 10px; margin-bottom: 10px; padding: 10px 10px 10px 5px; border: 1px solid #e8e8e8; font-family: Consolas, Monaco, 'Andale Mono', monospace; color: #314e64; width: 597.796875px; overflow: auto; clear: none; float: none !important; background-color: #f5f2f0; background-position: -29px 0px;">$ iostat -xz 1 Linux 3.13.0-49-generic (titanclusters-xxxxx)  07/14/2015  _x86_64_ (32 CPU) avg-cpu:  %user   %nice %system %iowait  %steal   %idle           73.96    0.00    3.73    0.03    0.06   22.21 Device:   rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util xvda        0.00     0.23    0.21    0.18     4.52     2.08    34.37     0.00    9.98   13.80    5.42   2.44   0.09 xvdb        0.01     0.00    1.02    8.94   127.97   598.53   145.79     0.00    0.43    1.78    0.28   0.25   0.25 xvdc        0.01     0.00    1.02    8.86   127.79   595.94   146.50     0.00    0.45    1.82    0.30   0.27   0.26 dm-0        0.00     0.00    0.69    2.32    10.47    31.69    28.01     0.01    3.23    0.71    3.98   0.13   0.04 dm-1        0.00     0.00    0.00    0.94     0.01     3.78     8.00     0.33  345.84    0.04  346.81   0.01   0.00 dm-2        0.00     0.00    0.09    0.07     1.35     0.36    22.50     0.00    2.55    0.23    5.62   1.78   0.03 [...] ^C </pre><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;">iostat命令主要用于查看机器磁盘IO情况。该命令输出的列，主要含义是：</p><ul style="margin: 0px 0px 15px 10px; padding: 0px; border: 0px; clear: left; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;"><li style="margin: 0px 0px 0px 15px; padding: 0px; border: 0px; float: none; clear: none;">r/s, w/s, rkB/s, wkB/s：分别表示每秒读写次数和每秒读写数据量（千字节）。读写量过大，可能会引起性能问题。</li><li style="margin: 0px 0px 0px 15px; padding: 0px; border: 0px; float: none; clear: none;">await：IO操作的平均等待时间，单位是毫秒。这是应用程序在和磁盘交互时，需要消耗的时间，包括IO等待和实际操作的耗时。如果这个数值过大，可能是硬件设备遇到了瓶颈或者出现故障。</li><li style="margin: 0px 0px 0px 15px; padding: 0px; border: 0px; float: none; clear: none;">avgqu-sz：向设备发出的请求平均数量。如果这个数值大于1，可能是硬件设备已经饱和（部分前端硬件设备支持并行写入）。</li><li style="margin: 0px 0px 0px 15px; padding: 0px; border: 0px; float: none; clear: none;">%util：设备利用率。这个数值表示设备的繁忙程度，经验值是如果超过60，可能会影响IO性能（可以参照IO操作平均等待时间）。如果到达100%，说明硬件设备已经饱和。</li></ul><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;">如果显示的是逻辑设备的数据，那么设备利用率不代表后端实际的硬件设备已经饱和。值得注意的是，即使IO性能不理想，也不一定意味这应用程序性能会不好，可以利用诸如预读取、写缓存等策略提升应用性能。</p><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;"><span style="font-weight: 600; margin: 0px; border: 0px; padding: 0px;">free &#8211;m</span></p><pre style="margin-top: 10px; margin-bottom: 10px; padding: 10px 10px 10px 5px; border: 1px solid #e8e8e8; font-family: Consolas, Monaco, 'Andale Mono', monospace; color: #314e64; width: 597.796875px; overflow: auto; clear: none; float: none !important; background-color: #f5f2f0; background-position: -29px 0px;">$ free -m              total       used       free     shared    buffers     cached Mem:        245998      24545     221453         83         59        541 -/+ buffers/cache:      23944     222053 Swap:            0          0          0 </pre><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;">free命令可以查看系统内存的使用情况，-m参数表示按照兆字节展示。最后两列分别表示用于IO缓存的内存数，和用于文件系统页缓存的内存数。需要注意的是，第二行-/+ buffers/cache，看上去缓存占用了大量内存空间。这是Linux系统的内存使用策略，尽可能的利用内存，如果应用程序需要内存，这部分内存会立即被回收并分配给应用程序。因此，这部分内存一般也被当成是可用内存。</p><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;">如果可用内存非常少，系统可能会动用交换区（如果配置了的话），这样会增加IO开销（可以在iostat命令中提现），降低系统性能。</p><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;"><span style="font-weight: 600; margin: 0px; border: 0px; padding: 0px;">sar -n DEV 1</span></p><pre style="margin-top: 10px; margin-bottom: 10px; padding: 10px 10px 10px 5px; border: 1px solid #e8e8e8; font-family: Consolas, Monaco, 'Andale Mono', monospace; color: #314e64; width: 597.796875px; overflow: auto; clear: none; float: none !important; background-color: #f5f2f0; background-position: -29px 0px;">$ sar -n DEV 1 Linux 3.13.0-49-generic (titanclusters-xxxxx)  07/14/2015     _x86_64_    (32 CPU) 12:16:48 AM     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s   %ifutil 12:16:49 AM      eth0  18763.00   5032.00  20686.42    478.30      0.00      0.00      0.00      0.00 12:16:49 AM        lo     14.00     14.00      1.36      1.36      0.00      0.00      0.00      0.00 12:16:49 AM   docker0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00 12:16:49 AM     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s   %ifutil 12:16:50 AM      eth0  19763.00   5101.00  21999.10    482.56      0.00      0.00      0.00      0.00 12:16:50 AM        lo     20.00     20.00      3.25      3.25      0.00      0.00      0.00      0.00 12:16:50 AM   docker0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00 ^C </pre><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;">sar命令在这里可以查看网络设备的吞吐率。在排查性能问题时，可以通过网络设备的吞吐量，判断网络设备是否已经饱和。如示例输出中，eth0网卡设备，吞吐率大概在22 Mbytes/s，既176 Mbits/sec，没有达到1Gbit/sec的硬件上限。</p><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;"><span style="font-weight: 600; margin: 0px; border: 0px; padding: 0px;">sar -n TCP,ETCP 1</span></p><pre style="margin-top: 10px; margin-bottom: 10px; padding: 10px 10px 10px 5px; border: 1px solid #e8e8e8; font-family: Consolas, Monaco, 'Andale Mono', monospace; color: #314e64; width: 597.796875px; overflow: auto; clear: none; float: none !important; background-color: #f5f2f0; background-position: -29px 0px;">$ sar -n TCP,ETCP 1 Linux 3.13.0-49-generic (titanclusters-xxxxx)  07/14/2015    _x86_64_    (32 CPU) 12:17:19 AM  active/s passive/s    iseg/s    oseg/s 12:17:20 AM      1.00      0.00  10233.00  18846.00 12:17:19 AM  atmptf/s  estres/s retrans/s isegerr/s   orsts/s 12:17:20 AM      0.00      0.00      0.00      0.00      0.00 12:17:20 AM  active/s passive/s    iseg/s    oseg/s 12:17:21 AM      1.00      0.00   8359.00   6039.00 12:17:20 AM  atmptf/s  estres/s retrans/s isegerr/s   orsts/s 12:17:21 AM      0.00      0.00      0.00      0.00      0.00 ^C </pre><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;">sar命令在这里用于查看TCP连接状态，其中包括：</p><ul style="margin: 0px 0px 15px 10px; padding: 0px; border: 0px; clear: left; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;"><li style="margin: 0px 0px 0px 15px; padding: 0px; border: 0px; float: none; clear: none;">active/s：每秒本地发起的TCP连接数，既通过connect调用创建的TCP连接；</li><li style="margin: 0px 0px 0px 15px; padding: 0px; border: 0px; float: none; clear: none;">passive/s：每秒远程发起的TCP连接数，即通过accept调用创建的TCP连接；</li><li style="margin: 0px 0px 0px 15px; padding: 0px; border: 0px; float: none; clear: none;">retrans/s：每秒TCP重传数量；</li></ul><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;">TCP连接数可以用来判断性能问题是否由于建立了过多的连接，进一步可以判断是主动发起的连接，还是被动接受的连接。TCP重传可能是因为网络环境恶劣，或者服务器压力过大导致丢包。</p><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;"><span style="font-weight: 600; margin: 0px; border: 0px; padding: 0px;">top</span></p><pre style="margin-top: 10px; margin-bottom: 10px; padding: 10px 10px 10px 5px; border: 1px solid #e8e8e8; font-family: Consolas, Monaco, 'Andale Mono', monospace; color: #314e64; width: 597.796875px; overflow: auto; clear: none; float: none !important; background-color: #f5f2f0; background-position: -29px 0px;">$ top top - 00:15:40 up 21:56,  1 user,  load average: 31.09, 29.87, 29.92 Tasks: 871 total,   1 running, 868 sleeping,   0 stopped,   2 zombie %Cpu(s): 96.8 us,  0.4 sy,  0.0 ni,  2.7 id,  0.1 wa,  0.0 hi,  0.0 si,  0.0 st KiB Mem:  25190241+total, 24921688 used, 22698073+free,    60448 buffers KiB Swap:        0 total,        0 used,        0 free.   554208 cached Mem    PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND  20248 root      20   0  0.227t 0.012t  18748 S  3090  5.2  29812:58 java   4213 root      20   0 2722544  64640  44232 S  23.5  0.0 233:35.37 mesos-slave  66128 titancl+  20   0   24344   2332   1172 R   1.0  0.0   0:00.07 top   5235 root      20   0 38.227g 547004  49996 S   0.7  0.2   2:02.74 java   4299 root      20   0 20.015g 2.682g  16836 S   0.3  1.1  33:14.42 java      1 root      20   0   33620   2920   1496 S   0.0  0.0   0:03.82 init      2 root      20   0       0      0      0 S   0.0  0.0   0:00.02 kthreadd      3 root      20   0       0      0      0 S   0.0  0.0   0:05.35 ksoftirqd/0      5 root       0 -20       0      0      0 S   0.0  0.0   0:00.00 kworker/0:0H      6 root      20   0       0      0      0 S   0.0  0.0   0:06.94 kworker/u256:0      8 root      20   0       0      0      0 S   0.0  0.0   2:38.05 rcu_sched </pre><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;">top命令包含了前面好几个命令的检查的内容。比如系统负载情况（uptime）、系统内存使用情况（free）、系统CPU使用情况（vmstat）等。因此通过这个命令，可以相对全面的查看系统负载的来源。同时，top命令支持排序，可以按照不同的列排序，方便查找出诸如内存占用最多的进程、CPU占用率最高的进程等。</p><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;">但是，top命令相对于前面一些命令，输出是一个瞬间值，如果不持续盯着，可能会错过一些线索。这时可能需要暂停top命令刷新，来记录和比对数据。</p><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;"><span style="font-weight: 600; margin: 0px; border: 0px; padding: 0px;">总结</span></p><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;">排查Linux服务器性能问题还有很多工具，上面介绍的一些命令，可以帮助我们快速的定位问题。例如前面的示例输出，多个证据证明有JAVA进程占用了大量CPU资源，之后的性能调优就可以针对应用程序进行。</p><hr style="margin: 0px; border: 0px; padding: 0px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;" /><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;">感谢<a href="http://www.infoq.com/cn/author/%E5%BE%90%E5%B7%9D" style="text-decoration: none; color: #286ab2; outline: none !important; margin: 0px; border: 0px; padding: 0px;">徐川</a>对本文的审校。</p><p style="margin: 0px 0px 15px; padding: 0px; border: 0px; float: none; line-height: 1.8; clear: both; width: 610px; font-family: 'Lantinghei SC', 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, STHeiti, 'WenQuanYi Micro Hei', SimSun, Helvetica, sans-serif; background-color: #ffffff;">给InfoQ中文站投稿或者参与内容翻译工作，请邮件至<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#101;&#100;&#105;&#116;&#111;&#114;&#115;&#64;&#99;&#110;&#46;&#105;&#110;&#102;&#111;&#113;&#46;&#99;&#111;&#109;" style="text-decoration: none; color: #286ab2; outline: none !important; margin: 0px; border: 0px; padding: 0px;">editors@cn.infoq.com</a>。也欢迎大家通过新浪微博（<a href="http://www.weibo.com/infoqchina" style="text-decoration: none; color: #286ab2; outline: none !important; margin: 0px; border: 0px; padding: 0px;">@InfoQ</a>，<a href="http://weibo.com/u/1451714913" style="text-decoration: none; color: #286ab2; outline: none !important; margin: 0px; border: 0px; padding: 0px;">@丁晓昀</a>），微信（微信号：<a href="http://weixin.sogou.com/gzh?openid=oIWsFt0HnZ93MfLi3pW2ggVJFRxY" style="text-decoration: none; color: #286ab2; outline: none !important; margin: 0px; border: 0px; padding: 0px;">InfoQChina</a>）关注我们，并与我们的编辑和其他读者朋友交流（欢迎加入InfoQ读者交流群<a href="http://shang.qq.com/wpa/qunwpa?idkey=cc82a73d7522f0090aa3cbb6a8f4bdafa8b82177f481014c976a8740d927997a" target="_blank" style="text-decoration: none; color: #286ab2; outline: none !important; margin: 0px; border: 0px; padding: 0px;"><img _href="img://group.png" _p="true" align="middle" alt="InfoQ好读者" border="0" src="http://pub.idqqimg.com/wpa/images/group.png" title="InfoQ好读者" style="border: 0px; margin: 0px 10px 10px 0px; padding: 0px; max-width: 100%;" /></a>（已满），InfoQ读者交流群（#2）</p><img src ="http://www.blogjava.net/xiaomage234/aggbug/428827.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2015-12-25 16:30 <a href="http://www.blogjava.net/xiaomage234/archive/2015/12/25/428827.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux nc(netcat)命令详解</title><link>http://www.blogjava.net/xiaomage234/archive/2015/09/16/427347.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Wed, 16 Sep 2015 01:01:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2015/09/16/427347.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/427347.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2015/09/16/427347.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/427347.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/427347.html</trackback:ping><description><![CDATA[<div id="art_desc" style="clear: both; border: 1px dashed #bfdfff; color: #444444; padding: 3px; word-wrap: break-word; word-break: break-all; line-height: 25.2000007629395px; text-indent: 20px; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background: #ffffff;"><div>NetCat，在网络工具中有ldquo;瑞士军刀rdquo;美誉，其有Windows和Linux的版本。因为它短小精悍（1.84版本也不过25k，旧版本或缩</div></div><div id="con_all" style="clear: both; padding-top: 20px; padding-bottom: 20px; margin: 0px; overflow: hidden; width: 640px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; line-height: 25.2000007629395px; background-color: #f7fcff;"><div id="con_ad1" style="float: left; width: 300px; margin: 0px; overflow: hidden;"></div><div id="con_ad8" style="float: right; margin: 0px; overflow: hidden;"></div></div><p style="margin: 13px 0px; padding: 0px; line-height: 25px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background-color: #f7fcff;"></p><p style="margin: 13px 0px; padding: 0px; line-height: 25px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background-color: #f7fcff;">NetCat，在网络工具中有&#8220;瑞士军刀&#8221;美誉，其有Windows和Linux的版本。因为它短小精悍（1.84版本也不过25k，旧版本或缩减版甚至更小）、功能实用，被设计为一个简单、可靠的网络工具，可通过TCP或UDP协议传输读写数据。同时，它还是一个网络应用Debug分析器，因为它可以根据需要创建各种不同类型的网络连接。</p><p style="margin: 13px 0px; padding: 0px; line-height: 25px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background-color: #f7fcff;">一、版本<br />通常的Linux发行版中都带有NetCat（简称nc），甚至在拯救模式光盘中也由busybox提供了简版的nc工具。但不同的版本，其参数的使用略有差异。<br />NetCat 官方地址：</p><p style="margin: 13px 0px; padding: 0px; line-height: 25px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background-color: #f7fcff;"><br />引用[root@hatest1 ~]# cat /etc/asianux-release<br />Asianux release 2.0 (Trinity SP2)<br />[root@hatest1 ~]# cat /etc/redflag-release<br />Red Flag DC Server release 5.0 (Trinity SP2)<br />[root@hatest1 ~]# type -a nc<br />nc is /usr/bin/nc<br />[root@hatest1 ~]# rpm -q nc<br />nc-1.10-22</p><p style="margin: 13px 0px; padding: 0px; line-height: 25px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background-color: #f7fcff;">建议在使用前，先用man nc看看帮助。这里以红旗DC Server 5.0上的1.10版本进行简单说明。<br />假设两<a href="http://www.68idc.cn/" style="text-decoration: none; color: blue;">服务器</a>信息：</p><p style="margin: 13px 0px; padding: 0px; line-height: 25px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background-color: #f7fcff;">server1: 192.168.10.10<br />server2: 192.168.10.11</p><p style="margin: 13px 0px; padding: 0px; line-height: 25px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background-color: #f7fcff;">二、常见使用<br />1、远程拷贝文件<br />从server1拷贝文件到server2上。需要先在server2上，，用nc激活监听，</p><p style="margin: 13px 0px; padding: 0px; line-height: 25px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background-color: #f7fcff;">server2上运行： nc -l 1234 &gt; text.txt</p><p style="margin: 13px 0px; padding: 0px; line-height: 25px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background-color: #f7fcff;">server1上运行： nc 192.168.10.11 1234 &lt; text.txt</p><p style="margin: 13px 0px; padding: 0px; line-height: 25px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background-color: #f7fcff;">注：server2上的监听要先打开</p><p style="margin: 13px 0px; padding: 0px; line-height: 25px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background-color: #f7fcff;"><br />2、克隆硬盘或分区<br />操作与上面的拷贝是雷同的，只需要由dd获得硬盘或分区的数据，然后传输即可。<br />克隆硬盘或分区的操作，不应在已经mount的的系统上进行。所以，需要使用安装光盘引导后，进入拯救模式（或使用Knoppix工具光盘）启动系统后，在server2上进行类似的监听动作：</p><p style="margin: 13px 0px; padding: 0px; line-height: 25px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background-color: #f7fcff;">&nbsp;nc -l -p 1234 | dd of=/dev/sda</p><p style="margin: 13px 0px; padding: 0px; line-height: 25px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background-color: #f7fcff;">server1上执行传输，即可完成从server1克隆sda硬盘到server2的任务：</p><p style="margin: 13px 0px; padding: 0px; line-height: 25px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background-color: #f7fcff;">&nbsp;dd if=/dev/sda | nc192.168.10.11 1234</p><p style="margin: 13px 0px; padding: 0px; line-height: 25px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background-color: #f7fcff;">&#8251; 完成上述工作的前提，是需要落实光盘的拯救模式支持<a href="http://www.68idc.cn/" style="text-decoration: none; color: blue;">服务器</a>上的网卡，并正确配置IP。</p><p style="margin: 13px 0px; padding: 0px; line-height: 25px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background-color: #f7fcff;">3、端口扫描<br />可以执行：</p><p style="margin: 13px 0px; padding: 0px; line-height: 25px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background-color: #f7fcff;"># nc -v -w 2 192.168.10.11 -z 21-24<br />nc: connect to 192.168.10.11 port 21 (tcp) failed: Connection refused<br />Connection to 192.168.10.11 22 port [tcp/ssh] succeeded!<br />nc: connect to 192.168.10.11 port 23 (tcp) failed: Connection refused<br />nc: connect to 192.168.10.11 port 24 (tcp) failed: Connection refused&nbsp;<br />-z后面跟的是要扫描的端口</p><p style="margin: 13px 0px; padding: 0px; line-height: 25px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background-color: #f7fcff;"><br />4、保存Web页面</p><p style="margin: 13px 0px; padding: 0px; line-height: 25px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background-color: #f7fcff;"># while true; do nc -l -p 80 -q 1 &lt; somepage.html; done</p><p style="margin: 13px 0px; padding: 0px; line-height: 25px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background-color: #f7fcff;"><br />5、模拟HTTP Headers</p><p style="margin: 13px 0px; padding: 0px; line-height: 25px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background-color: #f7fcff;">引用[root@hatest1 ~]# nc 80<br />GET / HTTP/1.1<br />Host: ispconfig.org<br />Referrer: mypage.com<br />User-Agent: my-browser</p><p style="margin: 13px 0px; padding: 0px; line-height: 25px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background-color: #f7fcff;">HTTP/1.1 200 OK<br />Date: Tue, 16 Dec 2008 07:23:24 GMT<br />Server: Apache/2.2.6 (Unix) DAV/2 mod_mono/1.2.1 mod_python/3.2.8 Python/2.4.3 mod_perl/2.0.2 Perl/v5.8.8<br />Set-Cookie: PHPSESSID=bbadorbvie1gn037iih6lrdg50; path=/<br />Expires: 0<br />Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0<br />Pragma: no-cache<br />Cache-Control: private, post-check=0, pre-check=0, max-age=0<br />Set-Cookie: oWn_sid=xRutAY; expires=Tue, 23-Dec-2008 07:23:24 GMT; path=/<br />Vary: Accept-Encoding<br />Transfer-Encoding: chunked<br />Content-Type: text/html<br />[......]</p><p style="margin: 13px 0px; padding: 0px; line-height: 25px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background-color: #f7fcff;">在nc命令后，输入红色部分的内容，然后按两次回车，即可从对方获得HTTP Headers内容。</p><p style="margin: 13px 0px; padding: 0px; line-height: 25px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background-color: #f7fcff;">6、聊天<br />nc还可以作为简单的字符下聊天工具使用，同样的，server2上需要启动监听：</p><p style="margin: 13px 0px; padding: 0px; line-height: 25px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background-color: #f7fcff;">server2上启动：# nc -lp 1234&nbsp;<br />server1上传输：# nc 192.168.10.11 1234</p><p style="margin: 13px 0px; padding: 0px; line-height: 25px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background-color: #f7fcff;"><br />这样，双方就可以相互交流了。使用Ctrl+D正常退出。</p><p style="margin: 13px 0px; padding: 0px; line-height: 25px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background-color: #f7fcff;">7、传输目录<br />从server1拷贝nginx-0.6.34目录内容到server2上。需要先在server2上，用nc激活监听，</p><p style="margin: 13px 0px; padding: 0px; line-height: 25px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background-color: #f7fcff;">server2上运行：# nc -l 1234 |tar xzvf -</p><p style="margin: 13px 0px; padding: 0px; line-height: 25px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background-color: #f7fcff;">server1上运行：# tar czvf - nginx-0.6.34|nc 192.168.10.11 1234</p><p style="margin: 13px 0px; padding: 0px; line-height: 25px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background-color: #f7fcff;">&nbsp;</p><p style="margin: 13px 0px; padding: 0px; line-height: 25px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background-color: #f7fcff;"><br />8、用nc命名操作memcached</p><p style="margin: 13px 0px; padding: 0px; line-height: 25px; color: #444444; font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; background-color: #f7fcff;">1）存储数据：printf &#8220;set key 0 10 6rnresultrn&#8221; |nc 192.168.10.11 11211<br />2）获取数据：printf &#8220;get keyrn&#8221; |nc 192.168.10.11 11211<br />3）删除数据：printf &#8220;delete keyrn&#8221; |nc 192.168.10.11 11211<br />4）查看状态：printf &#8220;statsrn&#8221; |nc 192.168.10.11 11211<br />5）模拟top命令查看状态：watch &#8220;echo stats&#8221; |nc 192.168.10.11 11211<br />6）清空缓存：printf &#8220;flush_allrn&#8221; |nc 192.168.10.11 11211 (小心操作，清空了缓存就没了）</p><img src ="http://www.blogjava.net/xiaomage234/aggbug/427347.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2015-09-16 09:01 <a href="http://www.blogjava.net/xiaomage234/archive/2015/09/16/427347.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Lvs之NAT、DR、TUN三种模式的应用配置案例[转]</title><link>http://www.blogjava.net/xiaomage234/archive/2015/09/02/427100.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Wed, 02 Sep 2015 08:07:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2015/09/02/427100.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/427100.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2015/09/02/427100.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/427100.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/427100.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: from:http://www.sxt.cn/u/324/blog/3188LVS一、LVS简介&nbsp;&nbsp;&nbsp;&nbsp;LVS是Linux Virtual Server的简写，意即Linux虚拟服务器，是一个虚拟服务器集群系统。本项目在1998年5月由章文嵩博士成立，是中国国内最早出现的自由软件之一。二、LVS的分类LVS-NAT：地址转换LVS-DR： 直接路由LVS-T...&nbsp;&nbsp;<a href='http://www.blogjava.net/xiaomage234/archive/2015/09/02/427100.html'>阅读全文</a><img src ="http://www.blogjava.net/xiaomage234/aggbug/427100.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2015-09-02 16:07 <a href="http://www.blogjava.net/xiaomage234/archive/2015/09/02/427100.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Nginx1.1.4+ 对后端机器的长连接特性</title><link>http://www.blogjava.net/xiaomage234/archive/2014/02/14/409863.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Fri, 14 Feb 2014 07:35:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2014/02/14/409863.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/409863.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2014/02/14/409863.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/409863.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/409863.html</trackback:ping><description><![CDATA[<p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">nginx&nbsp;upstream&nbsp;keepalive&nbsp;connections</span></span></p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">Nginx从&nbsp;1.1.4&nbsp;开始，实现了对后端机器的长连接支持，这是一个激动人心的改进，这意味着&nbsp;Nginx&nbsp;与后端机器的通信效率更高，后端机器的负担更低。</span></span></p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">例如，对一个没有长连接支持的后端机器，会出现大量TIME_WAIT&nbsp;状态的连接，使用以下命令验证之：</span></span></p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">netstat&nbsp;-n&nbsp;|&nbsp;grep&nbsp;TIME_WAIT</span></span></p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">经过查阅官方文档，其目前已经实现了http,&nbsp;fastcgi,&nbsp;memcache&nbsp;协议的长连接支持。而之前的版本中仅支持memcache&nbsp;协议。</span></span></p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">1.&nbsp;启用到&nbsp;memcache&nbsp;服务器的长连接&nbsp;</span><span style="font-size: 10.5pt; font-family: 'Lucida Console';"><br /></span><span style="font-size: 10.5pt; font-family: 'Lucida Console';">在upstream&nbsp;配置段中增加&nbsp;keepalive&nbsp;N&nbsp;指令即可：&nbsp;</span><span style="font-size: 10.5pt; font-family: 'Lucida Console';"><br /></span><span style="font-size: 10.5pt; font-family: 'Lucida Console';">upstream&nbsp;memcached_backend&nbsp;{</span></span></p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">&nbsp;&nbsp;&nbsp;&nbsp;server&nbsp;127.0.0.1:11211;</span></span></p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">&nbsp;&nbsp;&nbsp;&nbsp;server&nbsp;10.0.0.2:11211;</span></span></p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">&nbsp;&nbsp;&nbsp;</span>&nbsp;<span style="font-weight: bold; font-size: 10.5pt; font-family: 'Lucida Console';">&nbsp;keepalive&nbsp;32;</span></span></p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">}</span></span></p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">server&nbsp;{</span></span></p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">&nbsp;&nbsp;&nbsp;&nbsp;...</span></span></p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">&nbsp;&nbsp;&nbsp;&nbsp;location&nbsp;/memcached/&nbsp;{</span></span></p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set&nbsp;$memcached_key&nbsp;$uri;</span></span></p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memcached_pass&nbsp;memcached_backend;</span></span></p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span></p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">}</span></span></p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 宋体;">2.&nbsp;</span>&nbsp;<span style="font-size: 10.5pt; font-family: 宋体;">启用<span style="font-family: 'Lucida Console';">fastcgi</span>&nbsp;长连接支持&nbsp;</span><span style="font-size: 10.5pt; font-family: 宋体;"><br /></span><span style="font-size: 10.5pt; font-family: 宋体;">除了需要在<span style="font-family: 'Lucida Console';">upstream</span>&nbsp;中配置&nbsp;<span style="font-family: 'Lucida Console';">keepalive&nbsp;N</span>&nbsp;外，还需要在&nbsp;<span style="font-family: 'Lucida Console';">location</span>&nbsp;中增加&nbsp;<span style="font-family: 'Lucida Console';">fastcgi_keep_conn&nbsp;on;</span></span></span></p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">upstream&nbsp;fastcgi_backend&nbsp;{</span></span></p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">&nbsp;&nbsp;&nbsp;&nbsp;server&nbsp;127.0.0.1:9000;</span></span></p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;<span style="font-weight: bold; font-size: 10.5pt; font-family: 'Lucida Console';">keepalive&nbsp;8;</span></span></p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">}</span></span></p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;">&nbsp;</p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">server&nbsp;{</span></span></p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">&nbsp;&nbsp;&nbsp;&nbsp;...</span></span></p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">&nbsp;&nbsp;&nbsp;&nbsp;location&nbsp;/fastcgi/&nbsp;{</span></span></p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fastcgi_pass&nbsp;fastcgi_backend;</span></span></p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;<span style="font-weight: bold; font-size: 10.5pt; font-family: 'Lucida Console';">fastcgi_keep_conn&nbsp;on;</span></span></p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...</span></span></p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span></p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">}</span></span></p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;">&nbsp;</p><p style="margin: 0pt 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 宋体;">3.&nbsp;</span>&nbsp;<span style="font-size: 10.5pt; font-family: 宋体;">启用对后端机器<span style="font-family: 'Lucida Console';">HTTP</span>&nbsp;长连接支持</span></span></p><p style="margin: 0pt 0px 0pt 21pt; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">upstream&nbsp;http_backend&nbsp;{</span></span></p><p style="margin: 0pt 0px 0pt 21pt; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">&nbsp;&nbsp;&nbsp;&nbsp;server&nbsp;127.0.0.1:8080;</span></span></p><p style="margin: 0pt 0px 0pt 21pt; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">&nbsp;&nbsp;&nbsp;&nbsp;keepalive&nbsp;16;</span></span></p><p style="margin: 0pt 0px 0pt 21pt; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">}</span></span></p><p style="margin: 0pt 0px 0pt 21pt; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;">&nbsp;</p><p style="margin: 0pt 0px 0pt 21pt; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">server&nbsp;{</span></span></p><p style="margin: 0pt 0px 0pt 21pt; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">&nbsp;&nbsp;&nbsp;&nbsp;...</span></span></p><p style="margin: 0pt 0px 0pt 21pt; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">&nbsp;&nbsp;&nbsp;&nbsp;location&nbsp;/http/&nbsp;{</span></span></p><p style="margin: 0pt 0px 0pt 21pt; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proxy_pass&nbsp;http://http_backend;</span></span></p><p style="margin: 0pt 0px 0pt 21pt; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proxy_http_version&nbsp;1.1;</span></span></p><p style="margin: 0pt 0px 0pt 21pt; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proxy_set_header&nbsp;Connection&nbsp;"";</span></span></p><p style="margin: 0pt 0px 0pt 21pt; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...</span></span></p><p style="margin: 0pt 0px 0pt 21pt; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span></p><p style="margin: 0pt 0px 0pt 21pt; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 'Lucida Console';">}</span></span></p><p style="margin: 0pt 0px 0pt 21pt; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;">&nbsp;</p><p style="margin: 0pt 0px 0pt 21pt; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 宋体;">注意：需要设置<span style="font-family: 'Lucida Console';">nginx</span>&nbsp;代理请求的&nbsp;<span style="font-family: 'Lucida Console';">http</span>&nbsp;协议版本号为&nbsp;<span style="font-family: 'Lucida Console';">1.1,&nbsp;</span>&nbsp;以及清除掉&nbsp;<span style="font-family: 'Lucida Console';">Connection</span>&nbsp;请求<span style="font-family: 'Lucida Console';">header,&nbsp;</span>&nbsp;官方文档描述：</span></span></p><p style="margin: 0pt 0px 0pt 21pt; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 宋体;">For&nbsp;HTTP,&nbsp;the&nbsp;proxy_http_version&nbsp;directive&nbsp;should&nbsp;be&nbsp;set&nbsp;to&nbsp;&#8220;&nbsp;<span style="font-family: 'Lucida Console';">1.1</span>&nbsp;&#8221;&nbsp;&nbsp;<span style="font-family: 'Lucida Console';">and&nbsp;the&nbsp;</span>&nbsp;&#8220;<span style="font-family: 'Lucida Console';">Connection</span>&nbsp;&#8221;&nbsp;&nbsp;<span style="font-family: 'Lucida Console';">header&nbsp;field&nbsp;should&nbsp;be&nbsp;cleared</span>&nbsp;</span><span style="font-size: 10.5pt; font-family: 宋体;">.</span></span></p><p style="margin: 0pt 0px 0pt 21pt; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;">&nbsp;</p><p style="margin: 0pt 0px 0pt 21pt; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 宋体;">The&nbsp;connections&nbsp;parameter&nbsp;should&nbsp;be&nbsp;set&nbsp;low&nbsp;enough&nbsp;to&nbsp;allow&nbsp;upstream&nbsp;servers&nbsp;to&nbsp;process&nbsp;additional&nbsp;new&nbsp;incoming&nbsp;connections&nbsp;as&nbsp;well.&nbsp;</span></span></p><p style="margin: 0pt 0px 0pt 21pt; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;">&nbsp;</p><p style="margin: 0pt 0px 0pt 21pt; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 宋体;">即是说：<span style="font-family: 'Lucida Console';">keepalive&nbsp;N</span>&nbsp;指令中&nbsp;<span style="font-family: 'Lucida Console';">,&nbsp;N</span>&nbsp;的值应该尽可能设置小一些，以便后端机器可以同时接受新的连接。</span></span></p><p style="margin: 0pt 0px 0pt 21pt; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;">&nbsp;</p><p style="margin: 0pt 0px 0pt 21pt; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 宋体;">在我负责的生产环境中，前端是<span style="font-family: 'Lucida Console';">nginx,&nbsp;</span>&nbsp;静态文件缓存使用&nbsp;<span style="font-family: 'Lucida Console';">varnish,&nbsp;</span>&nbsp;使用长连接之后，&nbsp;<span style="font-family: 'Lucida Console';">varnish</span>机器的连接数从&nbsp;<span style="font-family: 'Lucida Console';">8000</span>&nbsp;多下降至&nbsp;<span style="font-family: 'Lucida Console';">200</span>&nbsp;多，负载值也有明显降低。</span></span></p><p style="margin: 0pt 0px 0pt 21pt; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;">&nbsp;</p><p style="margin: 0pt 0px 0pt 21pt; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 宋体;">但是针对<span style="font-family: 'Lucida Console';">fastcgi,&nbsp;</span>&nbsp;即后端机器是&nbsp;<span style="font-family: 'Lucida Console';">php-fpm</span>&nbsp;服务时，在&nbsp;<span style="font-family: 'Lucida Console';">nginx</span>&nbsp;日志中出现以下错误：</span></span></p><p style="margin: 0pt 0px 0pt 21pt; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 宋体;">&nbsp;upstream&nbsp;sent&nbsp;unsupported&nbsp;FastCGI&nbsp;protocol&nbsp;version:&nbsp;0&nbsp;while&nbsp;reading&nbsp;upstream</span>&nbsp;<span style="font-size: 10.5pt; font-family: 宋体;">。</span></span></p><p style="margin: 0pt 0px 0pt 21pt; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;">&nbsp;</p><p style="margin: 0pt 0px 0pt 21pt; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff; text-indent: 21pt;"><span style="font-size: large;"><span style="font-size: 10.5pt; font-family: 宋体;">广泛搜集，目前还未解决之。如果您遇到同样的问题并解决之，请一定联系笔者信箱<span style="font-family: 'Lucida Console';">zhangxugg@163.com,</span>&nbsp;</span><span style="font-size: 10.5pt; font-family: 宋体;">&nbsp;甚是感谢。</span></span></p><img src ="http://www.blogjava.net/xiaomage234/aggbug/409863.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2014-02-14 15:35 <a href="http://www.blogjava.net/xiaomage234/archive/2014/02/14/409863.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Rolling cURL: PHP并发最佳实践【转】</title><link>http://www.blogjava.net/xiaomage234/archive/2013/12/13/407541.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Fri, 13 Dec 2013 06:15:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2013/12/13/407541.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/407541.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2013/12/13/407541.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/407541.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/407541.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: from:http://www.searchtb.com/2012/06/rolling-curl-best-practices.html在实际项目或者自己编写小工具(比如新闻聚合,商品价格监控,比价)的过程中, 通常需要从第3方网站或者API接口获取数据, 在需要处理1个URL队列时, 为了提高性能, 可以采用cURL提供的curl_multi_*族函数实现简单的并发.本文将探讨两种具体的实现方...&nbsp;&nbsp;<a href='http://www.blogjava.net/xiaomage234/archive/2013/12/13/407541.html'>阅读全文</a><img src ="http://www.blogjava.net/xiaomage234/aggbug/407541.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2013-12-13 14:15 <a href="http://www.blogjava.net/xiaomage234/archive/2013/12/13/407541.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>安装Memcached和Memcached PHP扩展【转】</title><link>http://www.blogjava.net/xiaomage234/archive/2013/09/27/404546.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Fri, 27 Sep 2013 06:25:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2013/09/27/404546.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/404546.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2013/09/27/404546.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/404546.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/404546.html</trackback:ping><description><![CDATA[<p style="border: 0px; margin: 1em 0px; padding: 0px; line-height: 25px; font-family: arial, helvetica, clean, sans-serif; font-size: small; background-color: #f9f9f9;">Memcached资源很容易混淆,所以我打包好了.<br style="border: 0px; margin: 0px; padding: 0px;" />下载地址:&nbsp;<a title="Memcached源码包" href="http://www.euphie.net/downloads/memcached.tar.gz" target="_blank" style="border: 0px; margin: 0px; padding: 0px; color: #666666; text-decoration: none;">http://www.euphie.net/downloads/memcached.tar.gz</a><br style="border: 0px; margin: 0px; padding: 0px;" />下载后解压,里面有几个包:<br style="border: 0px; margin: 0px; padding: 0px;" />1.memcached-1.4.15 //Memcached服务端.<br style="border: 0px; margin: 0px; padding: 0px;" />2.memcached-2.1.0 //PHP的Memcached扩展,其实Memcached扩展有两种,还有一种叫Memcache,不过Memcached比Memcache功能更强大.<br style="border: 0px; margin: 0px; padding: 0px;" />3.libevent-2.0.21-stable //Memcached服务端的依赖包.<br style="border: 0px; margin: 0px; padding: 0px;" />4.libmemcached-1.0.16 //Memcached扩展的依赖包.<br style="border: 0px; margin: 0px; padding: 0px;" /></p><h1>一,安装Libevent</h1><pre style="border: 1px solid silver; margin-top: 10px; margin-bottom: 10px; padding: 15px 20px; font-size: 12px; line-height: 12px; background-color: #f5f5f5; overflow: auto; width: 590.65625px;">#cd libevent-2.0.21-stable #./configure -prefix=/usr/local/libevent #make #make install</pre><h1>二,安装Memcached服务端</h1><pre style="border: 1px solid silver; margin-top: 10px; margin-bottom: 10px; padding: 15px 20px; font-size: 12px; line-height: 12px; background-color: #f5f5f5; overflow: auto; width: 590.65625px;">#cd memcached-1.4.15 #./configure -prefix=/usr/local/memcached  -with-libevent=/usr/local/libevent #make #make install</pre><h1>三,启动Memcached服务</h1><pre style="border: 1px solid silver; margin-top: 10px; margin-bottom: 10px; padding: 15px 20px; font-size: 12px; line-height: 12px; background-color: #f5f5f5; overflow: auto; width: 590.65625px;">#/usr/local/memcached/bin/memcached -d -m 50  -u root -p 12000 -c 256 -P /tmp/memcached.pid</pre><p style="border: 0px; margin: 1em 0px; padding: 0px; line-height: 25px; font-family: arial, helvetica, clean, sans-serif; font-size: small; background-color: #f9f9f9;"><span style="border: 0px; margin: 0px; padding: 0px; color: #ff0000;">注:</span><br style="border: 0px; margin: 0px; padding: 0px;" /><span style="border: 0px; margin: 0px; padding: 0px; color: #ff0000;">-d选项是启动一个守护进程，</span><br style="border: 0px; margin: 0px; padding: 0px;" /><span style="border: 0px; margin: 0px; padding: 0px; color: #ff0000;">-m是分配给Memcache使用的内存数量，单位是MB.</span><br style="border: 0px; margin: 0px; padding: 0px;" /><span style="border: 0px; margin: 0px; padding: 0px; color: #ff0000;">-u是运行Memcache的用户.</span><br style="border: 0px; margin: 0px; padding: 0px;" /><span style="border: 0px; margin: 0px; padding: 0px; color: #ff0000;">-l是监听的服务器IP地址,我这里没有填.</span><br style="border: 0px; margin: 0px; padding: 0px;" /><span style="border: 0px; margin: 0px; padding: 0px; color: #ff0000;">-p是设置Memcache监听的端口.</span><br style="border: 0px; margin: 0px; padding: 0px;" /><span style="border: 0px; margin: 0px; padding: 0px; color: #ff0000;">-c选项是最大运行的并发连接数,默认是1024,按照你服务器的负载量来设定.</span><br style="border: 0px; margin: 0px; padding: 0px;" /><span style="border: 0px; margin: 0px; padding: 0px; color: #ff0000;">-P是设置保存Memcache的pid文件.</span></p><h1>四,安装Libmemcached</h1><pre style="border: 1px solid silver; margin-top: 10px; margin-bottom: 10px; padding: 15px 20px; font-size: 12px; line-height: 12px; background-color: #f5f5f5; overflow: auto; width: 590.65625px;">#cd libmemcached-1.0.16 #./configure -prefix=/usr/local/libmemcached  -with-memcached=/usr/local/memcached/bin/memcached #make #make install</pre><p style="border: 0px; margin: 1em 0px; padding: 0px; line-height: 25px; font-family: arial, helvetica, clean, sans-serif; font-size: small; background-color: #f9f9f9;"><span style="border: 0px; margin: 0px; padding: 0px; color: #ff0000;">注:</span><br style="border: 0px; margin: 0px; padding: 0px;" /><span style="border: 0px; margin: 0px; padding: 0px; color: #ff0000;">如果报&#8221;./libmemcached-1.0/memcached.h:46:27: error: tr1/cinttypes: No such file or directory&#8221;错误,则需要升级gcc版本.</span></p><h1>五,安装Memcached PHP扩展</h1><pre style="border: 1px solid silver; margin-top: 10px; margin-bottom: 10px; padding: 15px 20px; font-size: 12px; line-height: 12px; background-color: #f5f5f5; overflow: auto; width: 590.65625px;">#cd memcached-2.1.0 找到phpize和php-config的路径,我的分别是/usr/local/bin/phpize和/usr/bin/php-config. #/usr/local/bin/phpize #./configure --with-php-config=/usr/bin/php-config  --with-libmemcached-dir=/usr/local/libmemcached #make #make install 安装成功后会生成memcached.so,把路径加到php.ini的extension=xxx里.</pre><img src ="http://www.blogjava.net/xiaomage234/aggbug/404546.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2013-09-27 14:25 <a href="http://www.blogjava.net/xiaomage234/archive/2013/09/27/404546.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux常见信号区别</title><link>http://www.blogjava.net/xiaomage234/archive/2013/09/26/404466.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Thu, 26 Sep 2013 04:39:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2013/09/26/404466.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/404466.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2013/09/26/404466.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/404466.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/404466.html</trackback:ping><description><![CDATA[<table border="0" style="margin: 0px; padding: 0px; color: #494949; font-family: simsun; font-size: 14px; background-color: #f7cdbf; width: 522px; height: 120px;"><tbody><tr><td style="margin: 0px; padding: 0px; font-size: 12px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;">信号</td><td style="margin: 0px; padding: 0px; font-size: 12px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;">产生方式</td><td style="margin: 0px; padding: 0px; font-size: 12px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;">对进程的影响</td></tr><tr><td style="margin: 0px; padding: 0px; font-size: 12px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;">sigint</td><td style="margin: 0px; padding: 0px; font-size: 12px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;">通过ctrl+c将会对当进程发送此信号</td><td style="margin: 0px; padding: 0px; font-size: 12px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;">信号被当前进程树接收到，也就是说，不仅当前进程会收到信号，它的子进程也会收到</td></tr><tr><td style="margin: 0px; padding: 0px; font-size: 12px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;">sigterm</td><td style="margin: 0px; padding: 0px; font-size: 12px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;">kill命令不加参数就是发送这个信号</td><td style="margin: 0px; padding: 0px; font-size: 12px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;">只有当前进程收到信号，子进程不会收到。如果当前进程被kill了，那么它的子进程的父进程将会是init，也就是pid为1的进程</td></tr></tbody></table><br style="color: #333333; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 24px; background-color: #f5f5f5;" /><span style="color: #333333; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 24px; background-color: #f5f5f5;">SIGQUIT</span><br style="color: #333333; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 24px; background-color: #f5f5f5;" /><span style="color: #333333; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 24px; background-color: #f5f5f5;">和SIGINT类似,&nbsp;但由QUIT字符(通常是Ctrl-\)来控制.&nbsp;进程在因收到SIGQUIT退出时会产生core文件,&nbsp;在这个意义上类似于一个程序错误信号。</span><br style="color: #333333; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 24px; background-color: #f5f5f5;" /><br /><span style="color: #333333; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 24px; background-color: #f5f5f5;">SIGSTOP</span><br style="color: #333333; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 24px; background-color: #f5f5f5;" /><span style="color: #333333; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 24px; background-color: #f5f5f5;">停止(stopped)进程的执行.&nbsp;注意它和terminate以及interrupt的区别:该进程还未结束,&nbsp;只是暂停执行.&nbsp;本信号不能被阻塞,&nbsp;处理或忽略.<br /><br /></span>SIGKILL<br />强制杀死<br /><br />头文件信号详解<br /><div></div><div>/* Signals. &nbsp;*/</div><div>#define SIGHUP &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; /* Hangup (POSIX). &nbsp;*/</div><div>#define SIGINT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2 &nbsp; &nbsp; &nbsp; /* Interrupt (ANSI). &nbsp;*/</div><div>#define SIGQUIT &nbsp; &nbsp; &nbsp; &nbsp; 3 &nbsp; &nbsp; &nbsp; /* Quit (POSIX). &nbsp;*/</div><div>#define SIGILL &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;4 &nbsp; &nbsp; &nbsp; /* Illegal instruction (ANSI). &nbsp;*/</div><div>#define SIGTRAP &nbsp; &nbsp; &nbsp; &nbsp; 5 &nbsp; &nbsp; &nbsp; /* Trace trap (POSIX). &nbsp;*/</div><div>#define SIGABRT &nbsp; &nbsp; &nbsp; &nbsp; 6 &nbsp; &nbsp; &nbsp; /* Abort (ANSI). &nbsp;*/</div><div>#define SIGIOT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;6 &nbsp; &nbsp; &nbsp; /* IOT trap (4.2 BSD). &nbsp;*/</div><div>#define SIGBUS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;7 &nbsp; &nbsp; &nbsp; /* BUS error (4.2 BSD). &nbsp;*/</div><div>#define SIGFPE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;8 &nbsp; &nbsp; &nbsp; /* Floating-point exception (ANSI). &nbsp;*/</div><div>#define SIGKILL &nbsp; &nbsp; &nbsp; &nbsp; 9 &nbsp; &nbsp; &nbsp; /* Kill, unblockable (POSIX). &nbsp;*/</div><div>#define SIGUSR1 &nbsp; &nbsp; &nbsp; &nbsp; 10 &nbsp; &nbsp; &nbsp;/* User-defined signal 1 (POSIX). &nbsp;*/</div><div>#define SIGSEGV &nbsp; &nbsp; &nbsp; &nbsp; 11 &nbsp; &nbsp; &nbsp;/* Segmentation violation (ANSI). &nbsp;*/</div><div>#define SIGUSR2 &nbsp; &nbsp; &nbsp; &nbsp; 12 &nbsp; &nbsp; &nbsp;/* User-defined signal 2 (POSIX). &nbsp;*/</div><div>#define SIGPIPE &nbsp; &nbsp; &nbsp; &nbsp; 13 &nbsp; &nbsp; &nbsp;/* Broken pipe (POSIX). &nbsp;*/</div><div>#define SIGALRM &nbsp; &nbsp; &nbsp; &nbsp; 14 &nbsp; &nbsp; &nbsp;/* Alarm clock (POSIX). &nbsp;*/</div><div>#define SIGTERM &nbsp; &nbsp; &nbsp; &nbsp; 15 &nbsp; &nbsp; &nbsp;/* Termination (ANSI). &nbsp;*/</div><div>#define SIGSTKFLT &nbsp; &nbsp; &nbsp; 16 &nbsp; &nbsp; &nbsp;/* Stack fault. &nbsp;*/</div><div>#define SIGCLD &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SIGCHLD /* Same as SIGCHLD (System V). &nbsp;*/</div><div>#define SIGCHLD &nbsp; &nbsp; &nbsp; &nbsp; 17 &nbsp; &nbsp; &nbsp;/* Child status has changed (POSIX). &nbsp;*/</div><div>#define SIGCONT &nbsp; &nbsp; &nbsp; &nbsp; 18 &nbsp; &nbsp; &nbsp;/* Continue (POSIX). &nbsp;*/</div><div>#define SIGSTOP &nbsp; &nbsp; &nbsp; &nbsp; 19 &nbsp; &nbsp; &nbsp;/* Stop, unblockable (POSIX). &nbsp;*/</div><div>#define SIGTSTP &nbsp; &nbsp; &nbsp; &nbsp; 20 &nbsp; &nbsp; &nbsp;/* Keyboard stop (POSIX). &nbsp;*/</div><div>#define SIGTTIN &nbsp; &nbsp; &nbsp; &nbsp; 21 &nbsp; &nbsp; &nbsp;/* Background read from tty (POSIX). &nbsp;*/</div><div>#define SIGTTOU &nbsp; &nbsp; &nbsp; &nbsp; 22 &nbsp; &nbsp; &nbsp;/* Background write to tty (POSIX). &nbsp;*/</div><div>#define SIGURG &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;23 &nbsp; &nbsp; &nbsp;/* Urgent condition on socket (4.2 BSD). &nbsp;*/</div><div>#define SIGXCPU &nbsp; &nbsp; &nbsp; &nbsp; 24 &nbsp; &nbsp; &nbsp;/* CPU limit exceeded (4.2 BSD). &nbsp;*/</div><div>#define SIGXFSZ &nbsp; &nbsp; &nbsp; &nbsp; 25 &nbsp; &nbsp; &nbsp;/* File size limit exceeded (4.2 BSD). &nbsp;*/</div><div>#define SIGVTALRM &nbsp; &nbsp; &nbsp; 26 &nbsp; &nbsp; &nbsp;/* Virtual alarm clock (4.2 BSD). &nbsp;*/</div><div>#define SIGPROF &nbsp; &nbsp; &nbsp; &nbsp; 27 &nbsp; &nbsp; &nbsp;/* Profiling alarm clock (4.2 BSD). &nbsp;*/</div><div>#define SIGWINCH &nbsp; &nbsp; &nbsp; &nbsp;28 &nbsp; &nbsp; &nbsp;/* Window size change (4.3 BSD, Sun). &nbsp;*/</div><div>#define SIGPOLL &nbsp; &nbsp; &nbsp; &nbsp; SIGIO &nbsp; /* Pollable event occurred (System V). &nbsp;*/</div><div>#define SIGIO &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 29 &nbsp; &nbsp; &nbsp;/* I/O now possible (4.2 BSD). &nbsp;*/</div><div>#define SIGPWR &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;30 &nbsp; &nbsp; &nbsp;/* Power failure restart (System V). &nbsp;*/</div><div>#define SIGSYS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;31 &nbsp; &nbsp; &nbsp;/* Bad system call. &nbsp;*/</div><div>#define SIGUNUSED &nbsp; &nbsp; &nbsp; 31</div><img src ="http://www.blogjava.net/xiaomage234/aggbug/404466.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2013-09-26 12:39 <a href="http://www.blogjava.net/xiaomage234/archive/2013/09/26/404466.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux中的php-fpm作为服务安装</title><link>http://www.blogjava.net/xiaomage234/archive/2013/09/26/404465.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Thu, 26 Sep 2013 04:14:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2013/09/26/404465.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/404465.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2013/09/26/404465.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/404465.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/404465.html</trackback:ping><description><![CDATA[服务脚本在 sapi/fpm/init.d.php-fpm<br /><br />cp&nbsp;sapi/fpm/init.d.php-fpm /etc/rc.local/init.d/php-fpm<br /><br />chmod +x&nbsp;/etc/rc.local/init.d/php-fpm<br /><br />
<div>chkconfig --add php-fpm</div><img src ="http://www.blogjava.net/xiaomage234/aggbug/404465.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2013-09-26 12:14 <a href="http://www.blogjava.net/xiaomage234/archive/2013/09/26/404465.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux中的shell</title><link>http://www.blogjava.net/xiaomage234/archive/2013/09/17/404159.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Tue, 17 Sep 2013 03:15:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2013/09/17/404159.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/404159.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2013/09/17/404159.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/404159.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/404159.html</trackback:ping><description><![CDATA[<div id="content" mod-cs-content="" text-content=""  clearfix"="" style="zoom: 1; width: 758px; overflow: hidden; line-height: 1.5; margin: 7px 0px 10px; color: #454545; font-family: tahoma, helvetica, arial;"><p style="margin: 0px; padding: 0px;">一、Shell:命令行编辑的功能（快捷键技巧）</p><p style="margin: 0px; padding: 0px;">Ctrl+a光标移到行首</p><p style="margin: 0px; padding: 0px;"><img src="http://g.hiphotos.baidu.com/space/pic/item/267f9e2f07082838313602b8b899a9014c08f167.jpg" width="758" height="606" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;"  alt="" /></p><p style="margin: 0px; padding: 0px;">按ctrl+a后其结果如下：</p><p style="margin: 0px; padding: 0px;"><img src="http://h.hiphotos.baidu.com/space/pic/item/7aec54e736d12f2e2e3e70cc4fc2d56285356867.jpg" width="758" height="606" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;"  alt="" /></p><p style="margin: 0px; padding: 0px;">&nbsp;</p><p style="margin: 0px; padding: 0px;">Ctrl+e光标移到行尾</p><p style="margin: 0px; padding: 0px;">Ctrl+u删除光标处到行首的内容</p><p style="margin: 0px; padding: 0px;">Ctrl+k删除光标处到行尾的内容</p><p style="margin: 0px; padding: 0px;">Ctrl+arrow（左右箭头）</p><p style="margin: 0px; padding: 0px;">二、globbing：文件名通配</p><p style="margin: 0px; padding: 0px;">&nbsp;通配符有：</p><p style="margin: 0px; padding: 0px;">*：任意长度的任意字符</p><p style="margin: 0px; padding: 0px;">如：a*b：表示以a开头并以b结尾中间含有N个字符的求解，aab,abc,ab</p><p style="margin: 0px; padding: 0px;">？：任意单个字符</p><p style="margin: 0px; padding: 0px;">a?b,表示以a开头并以b结尾中间有且仅含有一个任意字符的求解，aab,ayb,abc,ab</p><p style="margin: 0px; padding: 0px;">[]:指定范围内的任意字符：[abc],[0-9],[a-z],[A-Z]</p><p style="margin: 0px; padding: 0px;">[:lower:]所有小写字母</p><p style="margin: 0px; padding: 0px;">[:upper:]所有大写字母</p><p style="margin: 0px; padding: 0px;">[:digit:]所有数字</p><p style="margin: 0px; padding: 0px;">如：a[a-z]b,aab,ayb,abc,ab</p><p style="margin: 0px; padding: 0px;"><img src="http://e.hiphotos.baidu.com/space/pic/item/8718367adab44aed0add6048b31c8701a08bfb8f.jpg" width="501" height="444" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;"  alt="" /></p><p style="margin: 0px; padding: 0px;">&nbsp;求解/etc文件目录下所有以pass开头并以数字或字母结尾的字符</p><p style="margin: 0px; padding: 0px;">求解所有以字母开头并以数字结尾的字符：</p><p style="margin: 0px; padding: 0px;">ls&nbsp;[a-zA-Z]*[0-9]</p><p style="margin: 0px; padding: 0px;">如在:ab、ab~、ab4、4ab、a4b、ayb、abc、x4y、xy3、3xy、aab中求解上述的值：</p><p style="margin: 0px; padding: 0px;"><img src="http://b.hiphotos.baidu.com/space/pic/item/1b4c510fd9f9d72a3902d3b1d42a2834349bbb3c.jpg" width="441" height="280" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;"  alt="" /></p><p style="margin: 0px; padding: 0px;">&nbsp;[^a-z]表示除了a到z的其他字符，既表示取反：</p><p style="margin: 0px; padding: 0px;">[[:alpha:]]代表所有以字符开头的字符</p><p style="margin: 0px; padding: 0px;">[[:punt:]]代表标点符号的集合</p><p style="margin: 0px; padding: 0px;"><img src="http://a.hiphotos.baidu.com/space/pic/item/77094b36acaf2edd23f58b458d1001e939019312.jpg" width="434" height="496" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;"  alt="" /></p><p style="margin: 0px; padding: 0px;">&nbsp;</p><p style="margin: 0px; padding: 0px;"><img src="http://f.hiphotos.baidu.com/space/pic/item/d6ca7bcb0a46f21ff3409cfff6246b600c33ae22.jpg" width="457" height="401" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;"  alt="" /></p><p style="margin: 0px; padding: 0px;">&nbsp;</p><p style="margin: 0px; padding: 0px;">&nbsp;三、命令行展开的功能</p><p style="margin: 0px; padding: 0px;">1、~</p><p style="margin: 0px; padding: 0px;">cd&nbsp;~rehat</p><p style="margin: 0px; padding: 0px;">2、{}</p><p style="margin: 0px; padding: 0px;"><img src="http://g.hiphotos.baidu.com/space/pic/item/03087bf40ad162d9dca4a0b011dfa9ec8b13cdd0.jpg" width="284" height="33" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;"  alt="" /></p><p style="margin: 0px; padding: 0px;">用一个命令实现它：</p><p style="margin: 0px; padding: 0px;">mkdir&nbsp;-p&nbsp;{x/{y/a1,z/b1},m/n}</p><p style="margin: 0px; padding: 0px;"><img src="http://f.hiphotos.baidu.com/space/pic/item/d50735fae6cd7b8973e8f82f0f2442a7d8330e92.jpg" width="619" height="348" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;"  alt="" /></p><p style="margin: 0px; padding: 0px;">&nbsp;</p><p style="margin: 0px; padding: 0px;"><img src="http://c.hiphotos.baidu.com/space/pic/item/b3fb43166d224f4a626fb1bf09f790529922d1ac.jpg" width="594" height="412" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;"  alt="" /></p><p style="margin: 0px; padding: 0px;">&nbsp;</p><p style="margin: 0px; padding: 0px;"><img src="http://d.hiphotos.baidu.com/space/pic/item/3812b31bb051f8199514cee6dab44aed2e73e76d.jpg" width="181" height="27" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;"  alt="" /></p><p style="margin: 0px; padding: 0px;">实现上述功能mkdir&nbsp;-v{x,m}_{y,z}</p><p style="margin: 0px; padding: 0px;"><img src="http://d.hiphotos.baidu.com/space/pic/item/43a7d933c895d1435e62298f73f082025aaf0702.jpg" width="640" height="368" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;"  alt="" /></p><p style="margin: 0px; padding: 0px;">3、$()或``（`波浪形的那反引号）：命令引用</p><p style="margin: 0px; padding: 0px;"><img src="http://d.hiphotos.baidu.com/space/pic/item/6c224f4a20a446234a6568ce9822720e0df3d7eb.jpg" width="507" height="285" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;"  alt="" /></p><p style="margin: 0px; padding: 0px;">&nbsp;</p><p style="margin: 0px; padding: 0px;">从上面的代码可以看出：</p><p style="margin: 0px; padding: 0px;">（1）echo是输出命令</p><p style="margin: 0px; padding: 0px;">（2）date获取系统日期及时将</p><p style="margin: 0px; padding: 0px;">（3）date&nbsp;+%T获取系统时间</p><p style="margin: 0px; padding: 0px;">（4）$（）与``的作用是等同的，可以替换</p><p style="margin: 0px; padding: 0px;">&nbsp;</p><p style="margin: 0px; padding: 0px;"><img src="http://g.hiphotos.baidu.com/space/pic/item/fc1f4134970a304e9bad6d56d1c8a786c8175c8b.jpg" width="309" height="50" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;"  alt="" /></p><p style="margin: 0px; padding: 0px;"><img src="http://d.hiphotos.baidu.com/space/pic/item/6c224f4a20a446234a4d68ce9822720e0df3d793.jpg" width="758" height="666" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;"  alt="" /></p><p style="margin: 0px; padding: 0px;">&nbsp;四、如何避免字符展开：</p><p style="margin: 0px; padding: 0px;">a*b</p><p style="margin: 0px; padding: 0px;">如何创建a*b的文件</p><p style="margin: 0px; padding: 0px;">touch&nbsp;a*b是修改a*b的解的时间属性<img src="http://a.hiphotos.baidu.com/space/pic/item/d8f9d72a6059252d8c07d1a8349b033b5bb5b90e.jpg" width="640" height="368" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;"  alt="" /></p><p style="margin: 0px; padding: 0px;">&nbsp;</p><p style="margin: 0px; padding: 0px;">&nbsp;</p><p style="margin: 0px; padding: 0px;">&nbsp;</p><p style="margin: 0px; padding: 0px;"><img src="http://c.hiphotos.baidu.com/space/pic/item/55e736d12f2eb938117eb65ed5628535e5dd6f0f.jpg" width="609" height="394" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;"  alt="" /></p><p style="margin: 0px; padding: 0px;">要创建a*b的文件命令用：touch&nbsp;"a*b"即可</p><p style="margin: 0px; padding: 0px;">&nbsp;</p><p style="margin: 0px; padding: 0px;">&nbsp;</p><p style="margin: 0px; padding: 0px;">&nbsp;</p><p style="margin: 0px; padding: 0px;">&nbsp;</p><p style="margin: 0px; padding: 0px;"><img src="http://b.hiphotos.baidu.com/space/pic/item/8326cffc1e178a82b066b30cf603738da877e8c0.jpg" width="367" height="192" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;"  alt="" /></p><p style="margin: 0px; padding: 0px;">&nbsp;</p><p style="margin: 0px; padding: 0px;">五、转义字符：\</p><p style="margin: 0px; padding: 0px;">避免一个字符表示通配的意义</p><p style="margin: 0px; padding: 0px;"><img src="http://c.hiphotos.baidu.com/space/pic/item/64380cd7912397ddd3d854a85982b2b7d1a287fd.jpg" width="393" height="218" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;"  alt="" /></p><p style="margin: 0px; padding: 0px;">六、如何使用命令别名</p><p style="margin: 0px; padding: 0px;">ll=ls&nbsp;-l</p><p style="margin: 0px; padding: 0px;">它是由alias定义的，alias是定义别名的命令</p><p style="margin: 0px; padding: 0px;"><img src="http://h.hiphotos.baidu.com/space/pic/item/91529822720e0cf3902982570a46f21fbf09aa44.jpg" width="640" height="228" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;"  alt="" /></p><p style="margin: 0px; padding: 0px;">&nbsp;</p><p style="margin: 0px; padding: 0px;">&nbsp;</p><p style="margin: 0px; padding: 0px;"><img src="http://b.hiphotos.baidu.com/space/pic/item/342ac65c10385343921f4b8d9313b07ecb80884e.jpg" width="398" height="85" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;"  alt="" /></p><p style="margin: 0px; padding: 0px;">&nbsp;定义别名：alias&nbsp;cls=clear其意义是将clear定义别名cls，此定义只对当前用户有效，而且重启机器后就失效</p><p style="margin: 0px; padding: 0px;"><img src="http://b.hiphotos.baidu.com/space/pic/item/0df3d7ca7bcb0a46bb5d44956b63f6246b60af1b.jpg" width="277" height="43" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;"  alt="" /></p><p style="margin: 0px; padding: 0px;">撤销别名：</p><p style="margin: 0px; padding: 0px;"><img src="http://h.hiphotos.baidu.com/space/pic/item/f3d3572c11dfa9eca56399bb62d0f703908fc1c9.jpg" width="281" height="86" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;"  alt="" /></p><p style="margin: 0px; padding: 0px;">使用原来的意义而非别名的意义可以采用\字符</p><p style="margin: 0px; padding: 0px;"><img src="http://e.hiphotos.baidu.com/space/pic/item/96dda144ad345982c6742a3e0cf431adcaef84a4.jpg" width="420" height="285" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;"  alt="" /></p><p style="margin: 0px; padding: 0px;">七、脚本语言</p><p style="margin: 0px; padding: 0px;">&nbsp;</p><p style="margin: 0px; padding: 0px;">bat，批处理</p><p style="margin: 0px; padding: 0px;">shell</p><p style="margin: 0px; padding: 0px;">bash</p><p style="margin: 0px; padding: 0px;">创建user1,user2,user3用户</p><p style="margin: 0px; padding: 0px;"><img src="http://b.hiphotos.baidu.com/space/pic/item/37d12f2eb9389b50c6d02efe8535e5dde7116e6b.jpg" width="364" height="48" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;"  alt="" />.sh代表脚本，自然Linux并不以后缀名来识别文件</p><p style="margin: 0px; padding: 0px;">其中myuseradd.sh中的内容如下：</p><p style="margin: 0px; padding: 0px;"><img src="http://g.hiphotos.baidu.com/space/pic/item/71cf3bc79f3df8dc1738463dcd11728b47102811.jpg" width="287" height="151" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;"  alt="" /></p><p style="margin: 0px; padding: 0px;">其演示如下：</p><p style="margin: 0px; padding: 0px;">&nbsp;</p><p style="margin: 0px; padding: 0px;"><img src="http://c.hiphotos.baidu.com/space/pic/item/8d5494eef01f3a29b7f01c629925bc315c607c66.jpg" width="565" height="404" style="border: 0px; margin-bottom: 8px; clear: both; max-width: 758px; vertical-align: top;"  alt="" /></p><p style="margin: 0px; padding: 0px;">&nbsp;</p><p style="margin: 0px; padding: 0px;">&nbsp;</p></div><div clearfix"="" style="zoom: 1; color: #454545; font-family: tahoma, helvetica, arial; font-size: 12px; line-height: normal;"><a href="http://hi.baidu.com/tag/Linux%E7%B3%BB%E7%BB%9F/feeds" style="text-decoration: none; color: #a0a0a0; background-clip: padding-box; background-color: #f5f5f5; height: 12px; padding: 4px; border: 1px solid #f5f5f5; border-top-left-radius: 2px; border-top-right-radius: 2px; border-bottom-right-radius: 2px; border-bottom-left-radius: 2px; margin: 0px 5px 10px 0px; line-height: 12px; display: inline-block; zoom: 1; white-space: nowrap; -webkit-background-clip: padding-box; background-position: initial initial; background-repeat: initial initial;">#Linux系统</a></div><img src ="http://www.blogjava.net/xiaomage234/aggbug/404159.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2013-09-17 11:15 <a href="http://www.blogjava.net/xiaomage234/archive/2013/09/17/404159.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> 如何定位死循环或高CPU使用率(linux)【转】</title><link>http://www.blogjava.net/xiaomage234/archive/2013/09/04/403652.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Wed, 04 Sep 2013 05:27:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2013/09/04/403652.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/403652.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2013/09/04/403652.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/403652.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/403652.html</trackback:ping><description><![CDATA[<span style="color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">如何定位死循环或高CPU使用率(linux)</span><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">&nbsp;<span id=".E7.A1.AE.E5.AE.9A.E6.98.AFCPU.E8.BF.87.E9.AB.98" style="word-wrap: break-word;">确定是CPU过高</span></div><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">使用top观察是否存在CPU使用率过高现象</p><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;"><span id=".E6.89.BE.E5.87.BA.E7.BA.BF.E7.A8.8B" style="word-wrap: break-word;">找出线程</span></div><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">对CPU使用率过高的进程的所有线程进行排序</p><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">ps H -e -o pid,tid,pcpu,cmd --sort=pcpu |grep xxx</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">得到如下结果,其中线程2909使用了7.8%的CPU.</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">2907 2913 0.0 ./xxx</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">2907 2909 7.8 ./xxx</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">也可以通过查看/proc中的信息来确定高CPU线程. 打印了4列,线程ID,线程名,用户时间和内核时间(排名未分先后)</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">awk '{print $1,$2,$14,$15}' /proc/2907/task/*/stat&nbsp;&nbsp;</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">&nbsp;</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;"><span style="word-wrap: break-word;">找出调用栈</span></div><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">使用gdb attach nmsagent所在的进程,在gdb中使用 info threads显示所有线程</p><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">gdb gdb&gt;attach 2907</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">gdb&gt;info threads</div><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">得到如下结果,可以发现2909线程的编号是12</p><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">13 Thread 0xad5f2b70 (LWP 2908) 0x004ef0d7 in mq_timedreceive () from /lib/tls/i686/cmov/librt.so.1</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">12 Thread 0xad58eb70 (LWP 2909) 0x006e0422 in __kernel_vsyscall ()</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">11 Thread 0xad52ab70 (LWP 2910) 0x006e0422 in __kernel_vsyscall ()</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">10 Thread 0xad4f8b70 (LWP 2911) 0x006e0422 in __kernel_vsyscall ()</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">9 Thread 0xad4c6b70 (LWP 2912) 0x006e0422 in __kernel_vsyscall ()</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">8 Thread 0xad3feb70 (LWP 2913) 0x004ef0d7 in mq_timedreceive () from /lib/tls/i686/cmov/librt.so.1</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">7 Thread 0xace08b70 (LWP 2914) 0x004ef0d7 in mq_timedreceive () from /lib/tls/i686/cmov/librt.so.1</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">6 Thread 0xac607b70 (LWP 2915) 0x006e0422 in __kernel_vsyscall ()</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">5 Thread 0xac5e6b70 (LWP 2916) 0x006e0422 in __kernel_vsyscall ()</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">4 Thread 0xac361b70 (LWP 2917) 0x006e0422 in __kernel_vsyscall ()</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">3 Thread 0xac2fdb70 (LWP 2918) 0x006e0422 in __kernel_vsyscall ()</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">2 Thread 0xac1fcb70 (LWP 2919) 0x004ef0d7 in mq_timedreceive () from /lib/tls/i686/cmov/librt.so.1</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">* 1 Thread 0xb78496d0 (LWP 2907) 0x006e0422 in __kernel_vsyscall ()</div><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">使用thread 切换线程,使用bt显示线程栈</p><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">gdb&gt;thread 12 gdb&gt;bt</div><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">得到如下线程栈</p><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">#0 0x006e0422 in __kernel_vsyscall ()</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">#1 0x001cca26 in nanosleep () from /lib/tls/i686/cmov/libc.so.6</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">#2 0x001fc2dc in usleep () from /lib/tls/i686/cmov/libc.so.6</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">#3 0x0806b510 in OspTaskDelay ()</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">#4 0x0805c710 in CDispatchTask::NodeMsgSendToSock() ()</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">#5 0x0805cc74 in DispatchTaskEntry ()</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">#6 0x0806a8e9 in OspTaskTemplateFunc(void*) ()</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">#7 0x00d4780e in start_thread () from /lib/tls/i686/cmov/libpthread.so.0</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">#8 0x002027ee in clone () from /lib/tls/i686/cmov/libc.so.6&nbsp;</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;"><span id="ps_.2B_strace" style="word-wrap: break-word;">ps + strace&nbsp;</span>&nbsp;</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">&nbsp;</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">得到进程ID 21465 ps -e |grep cmu 4996&nbsp;? 00:00:25 cmu_fjga_sp3 21465 pts/5 00:08:10 cmu</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">得到线程时间, 其中最占CPU的是 EpollRecvTask 21581</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">ps -eL |grep 21465</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">21465 21579 pts/5 00:00:00 CamApp</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">21465 21580 pts/5 00:00:00 TimerMan Task</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">21465 21581 pts/5 00:09:02 EpollRecvTask</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">21465 21582 pts/5 00:00:00</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">使用 strace -p 21581 得到线程栈 &nbsp;</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">&nbsp;</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">转载地址：<a href="http://www.cnblogs.com/sonic4x/archive/2011/06/17/How_to_deal_with_dead-loop_or_high-cpu_usage_bug.html" target="_blank" style="word-wrap: break-word; text-decoration: none; color: #565656;">http://www.cnblogs.com/sonic4x/archive/2011/06/17/How_to_deal_with_dead-loop_or_high-cpu_usage_bug.html</a></div><img src ="http://www.blogjava.net/xiaomage234/aggbug/403652.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2013-09-04 13:27 <a href="http://www.blogjava.net/xiaomage234/archive/2013/09/04/403652.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>oProfile的安装与使用 </title><link>http://www.blogjava.net/xiaomage234/archive/2013/08/12/402687.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Mon, 12 Aug 2013 06:13:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2013/08/12/402687.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/402687.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2013/08/12/402687.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/402687.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/402687.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: from:&nbsp;http://blog.chinaunix.net/uid-13746440-id-3152484.html0.引言基于DPDK的发包工具的性能今天已经达到双向1900Wpps了，比昨天又高了200Wpps，正是得益于oProfile检测与调优的结果，而且今天还只是很简单的用了一下（类似于下面的示例），跟踪出对几个结构体字段的访问比较缓慢，于是对结构体字段进行了仔细的顺序调整...&nbsp;&nbsp;<a href='http://www.blogjava.net/xiaomage234/archive/2013/08/12/402687.html'>阅读全文</a><img src ="http://www.blogjava.net/xiaomage234/aggbug/402687.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2013-08-12 14:13 <a href="http://www.blogjava.net/xiaomage234/archive/2013/08/12/402687.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>栈和堆的区别【总结】</title><link>http://www.blogjava.net/xiaomage234/archive/2013/05/20/399513.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Mon, 20 May 2013 08:40:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2013/05/20/399513.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/399513.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2013/05/20/399513.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/399513.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/399513.html</trackback:ping><description><![CDATA[<h2><br /></h2><div style="font-family: Arial; background-color: #ffffff;"><p style="margin: 0px 0px 1em; padding: 0px; color: #6d6d6d; line-height: 19px; word-break: break-all; font-family: arial; font-size: 12px;"><strong><span style="line-height: 22px; color: #4b4b4b; font-size: 10.5pt;">1.1内存分配方面</span></strong><span style="line-height: 22px; color: #4b4b4b; font-size: 10.5pt;">：</span></p><p style=" padding: 0px; color: #6d6d6d; line-height: 26px; font-family: arial; font-size: 12px;"><strong>堆</strong>：一般由程序员分配释放，若程序员不释放，程序结束时可能由OS回收 。注意它与数据结构中的堆是两回事，分配方式是类似于链表。可能用到的关键字如下：new、malloc、delete、free等等。</p><p style=" padding: 0px; color: #6d6d6d; line-height: 26px; font-family: arial; font-size: 12px;"><strong>栈</strong>：由编译器(Compiler)自动分配释放，存放函数的参数值，局部变量的值等。其操作方式类似于数据结构中的栈。</p><p style="margin: 0px 0px 1em; padding: 0px; color: #6d6d6d; line-height: 19px; word-break: break-all; font-family: arial; font-size: 12px;"><strong>1.2</strong><strong><span style="line-height: 22px; color: #4b4b4b; font-size: 10.5pt;">申请方式方面：</span></strong></p><p style=" padding: 0px; color: #6d6d6d; line-height: 26px; font-family: arial; font-size: 12px;"><strong>堆</strong>：需要程序员自己申请，并指明大小。在c中malloc函数如p1 = (char *)malloc(10)；在C++中用new运算符，但是注意p1、p2本身是在栈中的。因为他们还是可以认为是局部变量。</p><p style=" padding: 0px; color: #6d6d6d; line-height: 26px; font-family: arial; font-size: 12px;"><strong>栈</strong>：由系统自动分配。 例如，声明在函数中一个局部变量&nbsp;int b；系统自动在栈中为b开辟空间。</p><p style="margin: 0px 0px 1em; padding: 0px; color: #6d6d6d; line-height: 19px; word-break: break-all; font-family: arial; font-size: 12px;"><strong>1.3</strong><strong><span style="line-height: 22px; color: #4b4b4b; font-size: 10.5pt;">系统响应方面：</span></strong></p><p style=" padding: 0px; color: #6d6d6d; line-height: 26px; font-family: arial; font-size: 12px;"><strong>堆</strong>：操作系统有一个记录空闲内存地址的链表，当系统收到程序的申请时，会遍历该链表，寻找第一个空间大于所申请空间的堆结点，然后将该结点从空闲结点链表中删除，并将该结点的空间分配给程序，另外，对于大多数系统，会在这块内存空间中的首地址处记录本次分配的大小，这样代码中的delete语句才能正确的释放本内存空间。另外由于找到的堆结点的大小不一定正好等于申请的大小，系统会自动的将多余的那部分重新放入空闲链表中。</p><p style=" padding: 0px; color: #6d6d6d; line-height: 26px; font-family: arial; font-size: 12px;"><strong>栈</strong>：只要栈的剩余空间大于所申请空间，系统将为程序提供内存，否则将报异常提示栈溢出。</p><p style="margin: 0px 0px 1em; padding: 0px; color: #6d6d6d; line-height: 19px; word-break: break-all; font-family: arial; font-size: 12px;"><strong>1.4</strong><strong><span style="line-height: 22px; color: #4b4b4b; font-size: 10.5pt;">大小限制方面：</span></strong></p><p style=" padding: 0px; color: #6d6d6d; line-height: 26px; font-family: arial; font-size: 12px;"><strong>堆</strong>：是向高地址扩展的数据结构，是不连续的内存区域。这是由于系统是用链表来存储的空闲内存地址的，自然是不连续的，而链表的遍历方向是由低地址向高地址。堆的大小受限于计算机系统中有效的虚拟内存。由此可见，堆获得的空间比较灵活，也比较大。</p><p style=" padding: 0px; color: #6d6d6d; line-height: 26px; font-family: arial; font-size: 12px;"><strong>栈</strong>：在Windows下,&nbsp;栈是向低地址扩展的数据结构，是一块连续的内存的区域。这句话的意思是栈顶的地址和栈的最大容量是系统预先规定好的，在WINDOWS下，栈的大小是固定的（是一个编译时就确定的常数），如果申请的空间超过栈的剩余空间时，将提示overflow。因此，能从栈获得的空间较小。</p><p style="margin: 0px 0px 1em; padding: 0px; color: #6d6d6d; line-height: 19px; word-break: break-all; font-family: arial; font-size: 12px;"><strong>1.5</strong><strong><span style="line-height: 22px; color: #4b4b4b; font-size: 10.5pt;">效率方面：</span></strong></p><p style=" padding: 0px; color: #6d6d6d; line-height: 26px; font-family: arial; font-size: 12px;"><strong>堆</strong>：是由new分配的内存，一般速度比较慢，而且容易产生内存碎片，不过用起来最方便，另外，在WINDOWS下，最好的方式是用VirtualAlloc分配内存，他不是在堆，也不是在栈是直接在进程的地址空间中保留一快内存，虽然用起来最不方便。但是速度快，也最灵活。</p><p style=" padding: 0px; color: #6d6d6d; line-height: 26px; font-family: arial; font-size: 12px;"><strong>栈</strong>：由系统自动分配，速度较快。但程序员是无法控制的。</p><p style="margin: 0px 0px 1em; padding: 0px; color: #6d6d6d; line-height: 19px; word-break: break-all; font-family: arial; font-size: 12px;"><strong>1.6</strong><strong><span style="line-height: 22px; color: #4b4b4b; font-size: 10.5pt;">存放内容方面：</span></strong></p><p style=" padding: 0px; color: #6d6d6d; line-height: 26px; font-family: arial; font-size: 12px;"><strong>堆</strong>：一般是在堆的头部用一个字节存放堆的大小。堆中的具体内容有程序员安排。</p><p style=" padding: 0px; color: #6d6d6d; line-height: 26px; font-family: arial; font-size: 12px;"><strong>栈</strong>：在函数调用时第一个进栈的是<strong>主函数中后的下一条指令</strong>（函数调用语句的下一条可执行语句）的地址然后是函数的各个<strong>参数</strong>，在大多数的C编译器中，参数是由右往左入栈，然后是函数中的<strong>局部变量</strong>。&nbsp;注意:&nbsp;<strong>静态变量是不入栈的</strong>。当本次函数调用结束后，局部变量先出栈，然后是参数，最后栈顶指针指向最开始存的地址，也就是主函数中的下一条指令，程序由该点继续运行。</p><p style="margin: 0px 0px 1em; padding: 0px; color: #6d6d6d; line-height: 19px; word-break: break-all; font-family: arial; font-size: 12px;"><strong>1.7</strong><strong><span style="line-height: 22px; color: #4b4b4b; font-size: 10.5pt;">存取效率方面：</span></strong></p><p style=" padding: 0px; color: #6d6d6d; line-height: 26px; font-family: arial; font-size: 12px;"><strong>堆</strong>：char *s1 = "Hellow Word"；是在编译时就确定的；</p><p style=" padding: 0px; color: #6d6d6d; line-height: 26px; font-family: arial; font-size: 12px;"><strong>栈</strong>：char s1[] = "Hellow Word"；&nbsp;是在运行时赋值的；用数组比用指针速度要快一些，因为指针在底层汇编中需要用edx寄存器中转一下，而数组在栈上直接读取。</p><p style=" padding: 0px; color: #6d6d6d; line-height: 26px; font-family: arial; font-size: 12px;"><strong><span style="line-height: 22px; color: #4b4b4b; font-size: 10.5pt;"><br />小结</span></strong><strong></strong></p><p style=" padding: 0px; color: #6d6d6d; line-height: 26px; font-family: arial; font-size: 12px;">1、静态变量不入栈。&nbsp;<br />2、栈由编译器自动分配和释放。栈中存放局部变量和参数，函数调用结束后，局部变量先出栈，然后是参数。&nbsp;<br />3、数组比用指针速度要快一些，因为指针在底层汇编中需要用edx寄存器中转一下，而数组在栈上直接读取。&nbsp;<br />4、堆是由程序员通过new、malloc、free、delete等指令进行分配和释放。如果程序员没有进行释放，程序结束时可能有OS回收。&nbsp;<br />5、堆是由new分配的内存，速度较慢；栈是由系统自动分配，速度较快。&nbsp;<br />6、比如存放在栈里面的数组，是在运行时赋值。而存在堆里面的指针数据，是在编译时就确定的。</p><p style=" padding: 0px; color: #6d6d6d; line-height: 26px; font-family: arial; font-size: 12px;"></p><p style=" padding: 0px; color: #6d6d6d; line-height: 26px; font-family: arial; font-size: 12px;">附：</p><p style=" padding: 0px; color: #6d6d6d; line-height: 26px; font-family: arial; font-size: 12px;"></p><p style="margin: 0px 0px 1em; padding: 0px; color: #6d6d6d; line-height: 26px; font-family: arial; font-size: 12px;"><strong>一. 在c中分为这几个存储区</strong></p><p style="margin: 0px 0px 1em; padding: 0px; color: #6d6d6d; line-height: 26px; font-family: arial; font-size: 12px;">1.栈 - 由编译器自动分配释放<br />2.堆 - 一般由程序员分配释放，若程序员不释放，程序结束时可能由OS回收<br />3.全局区（静态区），全局变量和静态变量的存储是放在一块的，初始化的全局变量和静态变量在一块区域，未初始化的全局变量和未初始化的静态变量在相邻的另一块区域。- 程序结束释放<br />4.另外还有一个专门放常量的地方。- 程序结束释放<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />在函数体中定义的变量通常是在栈上，用malloc, calloc, realloc等分配内存的函数分配得到的就是在堆上。在所有函数体外定义的是全局量，加了static修饰符后不管在哪里都存放在全局区（静态区）,在所有函数体外定义的static变量表示在该文件中有效，不能extern到别的文件用，在函数体内定义的static表示只在该函数体内有效。另外，函数中的"adgfdf"这样的字符串存放在常量区。比如：<br /></p><div style="word-wrap: break-word; border-left-color: #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; width: 750px; font-size: 13px; word-break: break-all; color: #9a9a9a; font-family: arial; line-height: 18px;"><img src="http://hiphotos.baidu.com/youngky2008/pic/item/c92aa0caf50ac74f90457e79.jpg" alt="" style="border: none;" /><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;a&nbsp;</span><span style="color: #000000;">=</span>&nbsp;<span style="color: #000000;">0</span><span style="color: #000000;">;&nbsp;</span><span style="color: #008000;">//</span><span style="color: #008000;">全局初始化区</span><span style="color: #008000;"><br /><img src="http://hiphotos.baidu.com/youngky2008/pic/item/c22b9f07aab2edc4d63f7c79.jpg" alt="" style="border: none;" /></span><span style="color: #0000ff;">char</span>&nbsp;<span style="color: #000000;">*</span><span style="color: #000000;">p1;&nbsp;</span><span style="color: #008000;">//</span><span style="color: #008000;">全局未初始化区</span><span style="color: #008000;"><br /><img src="http://hiphotos.baidu.com/youngky2008/pic/item/9393b58ceec8bcd8a6c27279.jpg" alt="" style="border: none;" /></span><span style="color: #0000ff;">void</span><span style="color: #000000;">&nbsp;main()<br /><img src="http://hiphotos.baidu.com/youngky2008/pic/item/d5e9e49098354652d01b7079.jpg" alt="" style="border: none;" /></span><span style="color: #000000;">{<br /><img src="http://hiphotos.baidu.com/youngky2008/pic/item/1a03ce6a9f336a9683cb4a79.jpg" alt="" style="border: none;" />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">int</span>&nbsp;b;&nbsp;<span style="color: #008000;">//</span><span style="color: #008000;">栈</span><span style="color: #008000;"><br /><img src="http://hiphotos.baidu.com/youngky2008/pic/item/dc1232dec53c0297b4fd4879.jpg" alt="" style="border: none;" /></span>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">char</span>&nbsp;s[]&nbsp;=&nbsp;"abc";&nbsp;<span style="color: #008000;">//</span><span style="color: #008000;">栈</span><span style="color: #008000;"><br /><img src="http://hiphotos.baidu.com/youngky2008/pic/item/b8c4abf8f639f8b1fe037f79.jpg" alt="" style="border: none;" /></span>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">char</span>&nbsp;*p2;&nbsp;<span style="color: #008000;">//</span><span style="color: #008000;">栈</span><span style="color: #008000;"><br /><img src="http://hiphotos.baidu.com/youngky2008/pic/item/801d5adff00a692ad2164e79.jpg" alt="" style="border: none;" /></span>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">char</span>&nbsp;*p3&nbsp;=&nbsp;"123456";&nbsp;<span style="color: #008000;">//</span><span style="color: #008000;">123456{post.content}在常量区，p3在栈上</span><span style="color: #008000;"><br /><img src="http://hiphotos.baidu.com/youngky2008/pic/item/b72b316298e13268a9184c79.jpg" alt="" style="border: none;" /></span>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">static</span>&nbsp;<span style="color: #0000ff;">int</span>&nbsp;c&nbsp;=&nbsp;0;&nbsp;<span style="color: #008000;">//</span><span style="color: #008000;">全局（静态）初始化区</span><span style="color: #008000;"><br /><img src="http://hiphotos.baidu.com/youngky2008/pic/item/d1c06a20e1efac67d6074279.jpg" alt="" style="border: none;" /></span>&nbsp;&nbsp;&nbsp;&nbsp; p1&nbsp;=&nbsp;(<span style="color: #0000ff;">char</span>&nbsp;*)malloc(10);&nbsp;<span style="color: #008000;">//</span><span style="color: #008000;">分配得来得10字节的区域在堆区</span><span style="color: #008000;"><br /><img src="http://hiphotos.baidu.com/youngky2008/pic/item/aacef42f98f00eb6e4cd4079.jpg" alt="" style="border: none;" /></span>&nbsp;&nbsp;&nbsp;&nbsp; p2&nbsp;=&nbsp;(<span style="color: #0000ff;">char</span>&nbsp;*)malloc(20);&nbsp;<span style="color: #008000;">//</span><span style="color: #008000;">分配得来得20字节的区域在堆区</span><span style="color: #008000;"><br /><img src="http://hiphotos.baidu.com/youngky2008/pic/item/d5d156fea83a40c59c514679.jpg" alt="" style="border: none;" /></span>&nbsp;&nbsp;&nbsp;&nbsp; strcpy(p1,&nbsp;"123456");<br /><img src="http://hiphotos.baidu.com/youngky2008/pic/item/fdd5f141ef7fef7385947379.jpg" alt="" style="border: none;" />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">//</span><span style="color: #008000;">123456{post.content}放在常量区，编译器可能会将它与p3所指向的"123456"优化成一块</span><span style="color: #008000;"><br /><img src="http://hiphotos.baidu.com/youngky2008/pic/item/e71b188dcea634ff0d244479.jpg" alt="" style="border: none;" /></span>}</span><span style="color: #000000;"><br /><img src="http://hiphotos.baidu.com/youngky2008/pic/item/9f876cb75dd379ebdb335a79.jpg" alt="" style="border: none;" /></span></div><p style="margin: 0px 0px 1em; padding: 0px; color: #6d6d6d; line-height: 26px; font-family: arial; font-size: 12px;"><br /><strong><span style="color: red;"><strong>二.在C++中，内存分成5个区，他们分别是堆、栈、自由存储区、全局/静态存储区和常量存储区<br /></strong></span>1.栈，</strong>就是那些由编译器在需要的时候分配，在不需要的时候自动清楚的变量的存储区。里面的变量通常是局部变量、函数参数等。<br /><strong>2.堆，</strong>就是那些由new分配的内存块，他们的释放编译器不去管，由我们的应用程序去控制，一般一个new就要对应一个delete。如果程序员没有释放掉，那么在程序结束后，操作系统会自动回收。<br /><strong>3.自由存储区，</strong>就是那些由malloc等分配的内存块，他和堆是十分相似的，不过它是用free来结束自己的生命的。<br /><strong>4.全局/静态存储区</strong>，全局变量和静态变量被分配到同一块内存中，在以前的C语言中，全局变量又分为初始化的和未初始化的，在C++里面没有这个区分了，他们共同占用同一块内存区。<br /><strong>5.常量存储区，</strong>这是一块比较特殊的存储区，他们里面存放的是常量，不允许修改（当然，你要通过非正当手段也可以修改）<br /><br /><strong>三. 谈谈堆与栈的关系与区别<br /></strong>具体地说，现代计算机(串行执行机制)，都直接在代码底层支持栈的数据结构。这体现在，有专门的寄存器指向栈所在的地址，有专门的机器指令完成数据入栈出栈的操作。这种机制的特点是效率高，支持的数据有限，一般是整数，指针，浮点数等系统直接支持的数据类型，并不直接支持其他的数据结构。因为栈的这种特点，对栈的使用在程序中是非常频繁的。对子程序的调用就是直接利用栈完成的。机器的call指令里隐含了把返回地址推入栈，然后跳转至子程序地址的操作，而子程序中的ret指令则隐含从堆栈中弹出返回地址并跳转之的操作。C/C++中的自动变量是直接利用栈的例子，这也就是为什么当函数返回时，该函数的<strong>自动变量自动失效</strong>的原因。&nbsp;<br /><br />和栈不同，堆的数据结构并不是由系统(无论是机器系统还是操作系统)支持的，而是由函数库提供的。基本的malloc/realloc/free 函数维护了一套内部的堆数据结构。当程序使用这些函数去获得新的内存空间时，这套函数首先试图从内部堆中寻找可用的内存空间，如果没有可以使用的内存空间，则试图利用系统调用来动态增加程序数据段的内存大小，新分配得到的空间首先被组织进内部堆中去，然后再以适当的形式返回给调用者。当程序释放分配的内存空间时，这片内存空间被返回内部堆结构中，可能会被适当的处理(比如和其他空闲空间合并成更大的空闲空间)，以更适合下一次内存分配申请。这套复杂的分配机制实际上相当于一个<strong>内存分配的缓冲池</strong>(Cache)，使用这套机制有如下若干原因：<br />1. 系统调用可能不支持任意大小的内存分配。有些系统的系统调用只支持固定大小及其倍数的内存请求(按页分配)；这样的话对于大量的小内存分类来说会造成浪费。<br />2. 系统调用申请内存可能是代价昂贵的。系统调用可能涉及用户态和核心态的转换。<br />3. 没有管理的内存分配在大量复杂内存的分配释放操作下很容易造成内存碎片。<br /><br /><strong>堆和栈的对比<br /></strong>从以上知识可知，栈是系统提供的功能，特点是快速高效，缺点是有限制，数据不灵活；而栈是函数库提供的功能，特点是灵活方便，数据适应面广泛，但是效率有一定降低。栈是系统数据结构，对于进程/线程是唯一的；堆是函数库内部数据结构，不一定唯一。不同堆分配的内存无法互相操作。栈空间分静态分配和动态分配两种。静态分配是编译器完成的，比如自动变量(auto)的分配。动态分配由alloca函数完成。栈的动态分配无需释放(是自动的)，也就没有释放函数。为可移植的程序起见，栈的动态分配操作是不被鼓励的！堆空间的分配总是动态的，虽然程序结束时所有的数据空间都会被释放回系统，但是精确的申请内存/ 释放内存匹配是良好程序的基本要素。<br /><br />&nbsp;&nbsp;&nbsp; 1.碎片问题：对于堆来讲，<strong>频繁的new/delete势必会造成内存空间的不连续，从而造成大量的碎片，使程序效率降低</strong>。对于栈来讲，则不会存在这个问题，因为栈是先进后出的队列，他们是如此的一一对应，以至于永远都不可能有一个内存块从栈中间弹出，在他弹出之前，在他上面的后进的栈内容已经被弹出，详细的可以&gt;参考数据结构，这里我们就不再一一讨论了。<br />&nbsp;&nbsp;&nbsp; 2.生长方向：对于堆来讲，生长方向是向上的，也就是向着内存地址增加的方向；对于栈来讲，它的生长方向是向下的，是向着内存地址减小的方向增长。<br />&nbsp;&nbsp;&nbsp; 3.分配方式：堆都是动态分配的，没有静态分配的堆。栈有2种分配方式：静态分配和动态分配。静态分配是编译器完成的，比如局部变量的分配。动态分配由alloca函数进行分配，但是栈的动态分配和堆是不同的，他的动态分配是由编译器进行释放，无需我们手工实现。<br />&nbsp;&nbsp;&nbsp; 4.分配效率：栈是机器系统提供的数据结构，计算机会在底层对栈提供支持：分配专门的寄存器存放栈的地址，压栈出栈都有专门的指令执行，这就决定了<strong>栈的效率比较高</strong>。堆则是C/C++函数库提供的，它的机制是很复杂的，例如为了分配一块内存，库函数会按照一定的算法（具体的算法可以参考数据结构/操作系统）在堆内存中搜索可用的足够大小的空间，如果没有足够大小的空间（可能是由于内存碎片太多），就有可能调用系统功能去增加程序数据段的内存空间，这样就有机会分到足够大小的内存，然后进行返回。显然，堆的效率比栈要低得多。<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;<strong>明确区分堆与栈</strong>:<br />&nbsp;&nbsp;&nbsp; 在bbs上，堆与栈的区分问题，似乎是一个永恒的话题，由此可见，初学者对此往往是混淆不清的，所以我决定拿他第一个开刀。<br />&nbsp;&nbsp;&nbsp; 首先，我们举一个例子：<br /></p><div style="word-wrap: break-word; border-left-color: #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; width: 750px; font-size: 13px; word-break: break-all; color: #9a9a9a; font-family: arial; line-height: 18px;"><img src="http://hiphotos.baidu.com/youngky2008/pic/item/0ef221a38dc4f3d9d3435879.jpg" alt="" style="border: none;" /><span style="color: #0000ff;">void</span><span style="color: #000000;">&nbsp;f()<br /><img src="http://hiphotos.baidu.com/youngky2008/pic/item/d8e5ab9187b49607d3135e79.jpg" alt="" style="border: none;" /></span><span style="color: #000000;">{&nbsp;<br /><img src="http://hiphotos.baidu.com/youngky2008/pic/item/83d439abf8f870b7f9ed5079.jpg" alt="" style="border: none;" />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">int</span>*&nbsp;p=<span style="color: #0000ff;">new</span>&nbsp;<span style="color: #0000ff;">int</span>[5];<br /><img src="http://hiphotos.baidu.com/youngky2008/pic/item/a5d928ffa51a9028014f5679.jpg" alt="" style="border: none;" />}</span><span style="color: #000000;"><br /><img src="http://hiphotos.baidu.com/youngky2008/pic/item/02991bf495c1948f7b31aa7a.jpg" alt="" style="border: none;" /></span></div><p style="margin: 0px 0px 1em; padding: 0px; color: #6d6d6d; line-height: 26px; font-family: arial; font-size: 12px;">这条短短的一句话就包含了堆与栈，看到new，我们首先就应该想到，我们分配了一块堆内存，那么指针p呢？他分配的是一块栈内存，所以这句话的意思就是：<strong>在栈内存中存放了一个指向一块堆内存的指针p</strong>。在程序会先确定在堆中分配内存的大小，然后调用operator new分配内存，然后返回这块内存的首地址，放入栈中，他在VC6下的汇编代码如下：<br />&nbsp;&nbsp;&nbsp; 00401028&nbsp;&nbsp;&nbsp; push&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 14h<br />&nbsp;&nbsp;&nbsp; 0040102A&nbsp;&nbsp;&nbsp; call&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; operator new (00401060)<br />&nbsp;&nbsp;&nbsp; 0040102F&nbsp;&nbsp;&nbsp; add&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; esp,4<br />&nbsp;&nbsp;&nbsp; 00401032&nbsp;&nbsp;&nbsp; mov&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dword ptr [ebp-8],eax<br />&nbsp;&nbsp;&nbsp; 00401035&nbsp;&nbsp;&nbsp; mov&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; eax,dword ptr [ebp-8]<br />&nbsp;&nbsp;&nbsp; 00401038&nbsp;&nbsp;&nbsp; mov&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dword ptr [ebp-4],eax<br />&nbsp;&nbsp;&nbsp; 这里，我们为了简单并没有释放内存，那么该怎么去释放呢？是delete p么？澳，错了，应该是<strong>delete []p</strong>，这是为了告诉编译器：我删除的是一个数组，VC6就会根据相应的Cookie信息去进行释放内存的工作。<br />&nbsp;&nbsp;&nbsp; 好了，我们回到我们的主题：堆和栈究竟有什么区别？<br />&nbsp;&nbsp;&nbsp; 主要的区别由以下几点：<br />&nbsp;&nbsp;&nbsp; 1、管理方式不同；<br />&nbsp;&nbsp;&nbsp; 2、空间大小不同；<br />&nbsp;&nbsp;&nbsp; 3、能否产生碎片不同；<br />&nbsp;&nbsp;&nbsp; 4、生长方向不同；<br />&nbsp;&nbsp;&nbsp; 5、分配方式不同；<br />&nbsp;&nbsp;&nbsp; 6、分配效率不同；<br />&nbsp;&nbsp;&nbsp; 管理方式：对于栈来讲，是由编译器自动管理，无需我们手工控制；对于堆来说，释放工作由程序员控制，容易产生memory leak。<br />&nbsp;&nbsp;&nbsp; 空间大小：一般来讲在32位系统下，堆内存可以达到4G的空间，从这个角度来看堆内存几乎是没有什么限制的。但是对于栈来讲，一般都是有一定的空间大小的，例如，在VC6下面，默认的栈空间大小是1M（好像是，记不清楚了）。当然，我们可以修改：<br />&nbsp;&nbsp;&nbsp; 打开工程，依次操作菜单如下：Project-&gt;Setting-&gt;Link，在Category 中选中Output，然后在Reserve中设定堆栈的最大值和commit。<br />注意：reserve最小值为4Byte；commit是保留在虚拟内存的页文件里面，它设置的较大会使栈开辟较大的值，可能增加内存的开销和启动时间。<br />&nbsp;&nbsp;&nbsp; 堆和栈相比，由于大量new/delete的使用，容易造成大量的内存碎片；由于没有专门的系统支持，效率很低；由于可能引发用户态和核心态的切换，内存的申请，代价变得更加昂贵。所以栈在程序中是应用最广泛的，就算是函数的调用也利用栈去完成，函数调用过程中的参数，返回地址，EBP和局部变量都采用栈的方式存放。所以，我们推荐大家尽量用栈，而不是用堆。<br /><br />另外对存取效率的比较:<br />代码:<br /></p><div style="word-wrap: break-word; border-left-color: #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; width: 750px; font-size: 13px; word-break: break-all; color: #9a9a9a; font-family: arial; line-height: 18px;"><img src="http://hiphotos.baidu.com/youngky2008/pic/item/f6e0ccc71dc63119b119a87a.jpg" alt="" style="border: none;" /><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;s1[]&nbsp;</span><span style="color: #000000;">=</span>&nbsp;<span style="color: #000000;">"</span><span style="color: #000000;">aaaaaaaaaaaaaaa</span><span style="color: #000000;">"</span><span style="color: #000000;">;<br /><img src="http://hiphotos.baidu.com/youngky2008/pic/item/78e76951d5eed088b545ae7a.jpg" alt="" style="border: none;" /></span><span style="color: #0000ff;">char</span>&nbsp;<span style="color: #000000;">*</span><span style="color: #000000;">s2&nbsp;</span><span style="color: #000000;">=</span>&nbsp;<span style="color: #000000;">"</span><span style="color: #000000;">bbbbbbbbbbbbbbbbb</span><span style="color: #000000;">"</span><span style="color: #000000;">;<img src="http://hiphotos.baidu.com/youngky2008/pic/item/b2cf88c0dfb278e58026ac7a.jpg" alt="" style="border: none;" /></span></div><p style="margin: 0px 0px 1em; padding: 0px; color: #6d6d6d; line-height: 26px; font-family: arial; font-size: 12px;">aaaaaaaaaaa是在运行时刻赋值的；<br />而bbbbbbbbbbb是在编译时就确定的；<br />但是，在以后的存取中，<strong>在栈上的数组比指针所指向的字符串(例如堆)快</strong>。<br />比如：<br /></p><div style="word-wrap: break-word; border-left-color: #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; width: 750px; font-size: 13px; word-break: break-all; color: #9a9a9a; font-family: arial; line-height: 18px;"><img src="http://hiphotos.baidu.com/youngky2008/pic/item/b69320ade8d1f4b01c17a27a.jpg" alt="" style="border: none;" /><span style="color: #0000ff;">void</span><span style="color: #000000;">&nbsp;main()<br /><img src="http://hiphotos.baidu.com/youngky2008/pic/item/83f0acf872e0b1cebb01a07a.jpg" alt="" style="border: none;" /></span><span style="color: #000000;">{<br /><img src="http://hiphotos.baidu.com/youngky2008/pic/item/f7d51089db80025eb11bba7a.jpg" alt="" style="border: none;" />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">char</span>&nbsp;a&nbsp;=&nbsp;1;<br /><img src="http://hiphotos.baidu.com/youngky2008/pic/item/a8a15a16c7ec8b1dfa19b87a.jpg" alt="" style="border: none;" />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">char</span>&nbsp;c[]&nbsp;=&nbsp;"1234567890";<br /><img src="http://hiphotos.baidu.com/youngky2008/pic/item/b2cdd3558eeebd54347abe7a.jpg" alt="" style="border: none;" />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">char</span>&nbsp;*p&nbsp;="1234567890";<br /><img src="http://hiphotos.baidu.com/youngky2008/pic/item/f9cfe51c4e8de1f848edbc7a.jpg" alt="" style="border: none;" />&nbsp;&nbsp;&nbsp;&nbsp; a&nbsp;=&nbsp;c[1];<br /><img src="http://hiphotos.baidu.com/youngky2008/pic/item/37acb9b0301a153f89d4b27a.jpg" alt="" style="border: none;" />&nbsp;&nbsp;&nbsp;&nbsp; a&nbsp;=&nbsp;p[1];<br /><img src="http://hiphotos.baidu.com/youngky2008/pic/item/4b3b4d77f72388508501b07a.jpg" alt="" style="border: none;" />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">return</span>;<br /><img src="http://hiphotos.baidu.com/youngky2008/pic/item/8a02d018f9f69ac785d6b67a.jpg" alt="" style="border: none;" />}</span></div><p style="margin: 0px 0px 1em; padding: 0px; color: #6d6d6d; line-height: 26px; font-family: arial; font-size: 12px;">对应的汇编代码<br />10: a = c[1];<br />00401067 8A 4D F1 mov cl,byte ptr [ebp-0Fh]<br />0040106A 88 4D FC mov byte ptr [ebp-4],cl<br />11: a = p[1];<br />0040106D 8B 55 EC mov edx,dword ptr [ebp-14h]<br />00401070 8A 42 01 mov al,byte ptr [edx+1]<br />00401073 88 45 FC mov byte ptr [ebp-4],al<br />第一种在读取时直接就把字符串中的元素读到寄存器cl中，而第二种则要先把指针值读到edx中，在根据edx读取字符，显然慢了.<br />&nbsp;&nbsp;&nbsp; 无论是堆还是栈，都要防止越界现象的发生（除非你是故意使其越界），因为越界的结果要么是程序崩溃，要么是摧毁程序的堆、栈结构，产生以想不到的结果,就算是在你的程序运行过程中，没有发生上面的问题，你还是要小心，说不定什么时候就崩掉,编写稳定安全的代码才是最重要的</p></div><img src ="http://www.blogjava.net/xiaomage234/aggbug/399513.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2013-05-20 16:40 <a href="http://www.blogjava.net/xiaomage234/archive/2013/05/20/399513.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>机械存储设计及实现</title><link>http://www.blogjava.net/xiaomage234/archive/2013/04/23/398249.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Tue, 23 Apr 2013 01:56:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2013/04/23/398249.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/398249.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2013/04/23/398249.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/398249.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/398249.html</trackback:ping><description><![CDATA[<p dir="ltr" style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; font-size: 12px; line-height: 17px; background-color: #ffffff;"><strong>主要阐述以下内容：</strong></p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; font-size: 12px; line-height: 17px; background-color: #ffffff;"><strong>磁盘的内部结构及实现机制<br />分区的结构及实现机制<br />块的构造及原理<br />扇区的构造及结构</strong></p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; font-size: 12px; line-height: 17px; background-color: #ffffff;">&nbsp;</p><p dir="ltr" style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; font-size: 12px; line-height: 17px; background-color: #ffffff;">由于机械硬盘的访问机制为移动磁头，并等待磁碟旋转，因此在设计磁盘时，需要考虑如何组织数据为顺序访问，并且最大限度提供一次顺序访问尽可能多的数据</p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; font-size: 12px; line-height: 17px; background-color: #ffffff;"><strong>由于块大小设计直影响到性能、内存、空间等因素，因此需要合理设置块大小，同时需要合理的为业务扩展预留升级空间</strong></p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; font-size: 12px; line-height: 17px; background-color: #ffffff;">机械磁盘读写原理</p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; font-size: 12px; line-height: 17px; background-color: #ffffff;"><img src="https://lh4.googleusercontent.com/q0OItgZAMuIz4VpbSV78oWJVaVfh4zOFM0a7OmnX2PYRCl22IDLVVze8sPoHyVOj0E7d3JBucCeMx6fZe7Z-bnW3JcZ9CYYkIZ1gvaNDxrBjU03HpDM" alt="" width="614px;" height="543px;" style="border: 0px; max-width: 600px;" /></p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; font-size: 12px; line-height: 17px; background-color: #ffffff;">&nbsp;</p><p dir="ltr" style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; font-size: 12px; line-height: 17px; background-color: #ffffff;">机械硬盘获取数据的方式为：</p><p dir="ltr" style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; font-size: 12px; line-height: 17px; background-color: #ffffff;">1、通过查找meta数据（图中的Data Meta，它是用于描述数据的数据，所以称为数据元，通常这些数据会被Cache在磁盘Cache或OS Cache中)，捕获数据存储物理区域。包括：磁头指向的磁道位置、磁道的起始、结束位置等，其中还包含了数据块的标记，如使用状态，分区、块、卷、扇区等等存储细节等，是磁盘运作机制的核心组件</p><p dir="ltr" style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; font-size: 12px; line-height: 17px; background-color: #ffffff;">2、驱动磁碟旋转（服务器通常磁盘会一直旋转，但为了省电及减少对驱动轴的损耗，通常会对旋转进行优化，即空闲时降低磁盘旋转速度或停止转动，但重新驱动磁盘也会消耗大量的功耗，厂家进行了很多节能减排的优化措施，为绿色环保做了不少贡献）</p><p dir="ltr" style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; font-size: 12px; line-height: 17px; background-color: #ffffff;">3、将磁头（图中的head）移动到指定的磁道，并从指定的起始位置开始读取bit流，一直至指定的结束位置，并将信号传送至处理程序，最后转化为OS识别的数据</p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; font-size: 12px; line-height: 17px; background-color: #ffffff;"><strong><br /></strong></p><p dir="ltr" style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; font-size: 12px; line-height: 17px; background-color: #ffffff;">机械硬盘核心组件：</p><p dir="ltr" style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; font-size: 12px; line-height: 17px; background-color: #ffffff;">1、磁盘控制器：内部包含用于控制多磁碟并行访问的机制，包括磁头移动、盘片旋转、供电、缓存、写保护等，是整个磁盘的核心组件</p><p dir="ltr" style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; font-size: 12px; line-height: 17px; background-color: #ffffff;">2、分区（LUN）：机械硬盘要被使用，通常先要被分区，并基于分区进行格式化，格式化将产生Meta数据，Meta数据通常会占用部分磁盘空间。空间大小取决于Block大小、分区量，Block越小，需要消耗的空间，用于于索引磁盘数据，接下来我们将还会介绍块及扇区的组合方式，多碟磁盘中，磁盘控制器将在每块磁碟中划分一块空间用于该分区使用，达到并行访问的目的，提升响应速度（通常某些访问需要集中访问的数据都集中在某些分区中），此处的分区不同于OS中的分区，此处为物理分区</p><p dir="ltr" style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; font-size: 12px; line-height: 17px; background-color: #ffffff;">3、块：块由扇区构成，块大小决定了数据访问的性能，如果大数据如果存储在小块中会导致浪费大量的数据元空间，并消耗更多的Cache、更多的寻道时间（数据是被分散再分区中的各个位置），所以当应用数据块比较小的时候，我们建议将数据划分成更大的块，提升性能，但如果块划的太大，会导致存储空间的浪费，当这些不需要的数据被LOAD到应用中时，同样会消耗额外的OS内存，通常我们建议根据业务的类型，在应用层选择合适的数据集大小，并设置合理的磁盘块大小</p><p dir="ltr" style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; font-size: 12px; line-height: 17px; background-color: #ffffff;">块由扇区构成，扇区直接构建再磁碟的磁面上，每个扇区为512byte，业绩意味着4KB的块大小将需要8个扇区组成（通常Linux设置块大小为4K），但再某些数据库应用中我们将数据库的数据设置为更大，如8K、16K、64K，日志设置为更大，如8K、16K、64K等，结构如下</p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; font-size: 12px; line-height: 17px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; font-size: 12px; line-height: 17px; background-color: #ffffff;"><img src="https://lh5.googleusercontent.com/luxai0pcdLXQr24CAP6WAOpdLy9C-U62LxkEjsKDImJWFD0wkH_QoKM30xqeci4axhO9gYAQa1rESD_fL5gdOh8477I4pgd4mxuIPdN1gDlLQCCqZJ0" alt="" width="616px;" height="462px;" style="border: 0px; max-width: 600px;" /></p><p dir="ltr" style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; font-size: 12px; line-height: 17px; background-color: #ffffff;">4、扇区：扇区是磁盘存储的单元，扇区顾名思义，机械硬盘是圆形的，通过分区格式化后将得到一个一个的扇形结构，一条磁道的存储空间被格式化后将的到大量的扇形结构，磁盘的扇区大小为512byte，其在磁盘的结构如下图：</p><p style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; font-size: 12px; line-height: 17px; background-color: #ffffff;"><strong><img src="https://lh3.googleusercontent.com/Yn0pJAj3kfMAREByq-KUBGVldfgJ9A1pt7crKLH4rNTomiLTJk0T_DcWeGMuJzSIn56bl1DbWiNpOrucAiP7tw6FaP9blKa76VmhslfJtHdl8QSt05Y" alt="" width="558px;" height="418px;" style="border: 0px; max-width: 600px;" /><br /></strong></p><p dir="ltr" style="margin: 0px 0px 10px; padding: 0px; color: #555555; font-family: Verdana, 'BitStream vera Sans', Tahoma, Helvetica, sans-serif; font-size: 12px; line-height: 17px; background-color: #ffffff;">图中我们可以看到扇区结构非常复杂，包含数据区域、扇区分界标识区域、扇区间隙区域，磁盘在处理数据时为了更好的保护数据及容错、设计了扇区分界标识及扇区间隙（当然远远不止如此）</p><img src ="http://www.blogjava.net/xiaomage234/aggbug/398249.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2013-04-23 09:56 <a href="http://www.blogjava.net/xiaomage234/archive/2013/04/23/398249.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Hadoop及子项目介绍</title><link>http://www.blogjava.net/xiaomage234/archive/2013/04/22/398194.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Mon, 22 Apr 2013 04:39:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2013/04/22/398194.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/398194.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2013/04/22/398194.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/398194.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/398194.html</trackback:ping><description><![CDATA[<p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef;"><a href="http://www.linuxidc.com/topicnews.aspx?tid=13" target="_blank" title="Hadoop" style="color: #b32bd5;">Hadoop</a>是Apache的一个项目(<a title="" href="http://hadoop.apache.org/" target="_blank" style="color: #b32bd5;">http://hadoop.apache.org/</a>),它是一个实现了MapReduce计算模型的可以运用于大型集群并行计算的分布式并行计算编程框架。</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef;">目前，整个Hadoop家族由以下几个子项目组成：</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef;">Hadoop Common<br />Hadoop体系最底层的一个模块，为Hadoop各子项目提供各种工具，如：配置文件和日志操作等。</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef;">Avro<br />Avro是doug cutting主持的RPC项目，有点类似Google的protobuf和Facebook的thrift。avro用来做以后hadoop的RPC，使hadoop的RPC模块通信速度更快、数据结构更紧凑。</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef;">Chukwa<br />Chukwa是基于Hadoop的大集群监控系统，由yahoo贡献。</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef;">HBase<br />基于Hadoop Distributed File System，是一个开源的，基于列存储模型的分布式数据库。</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef;">HDFS<br />分布式文件系统</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef;">Hive<br />hive类似CloudBase，也是基于hadoop分布式计算平台上的提供data warehouse的sql功能的一套软件。使得存储在hadoop里面的海量数据的汇总，即席查询简单化。hive提供了一套QL的查询语言，以sql为基础，使用起来很方便。</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef;">MapReduce<br />实现了MapReduce编程框架</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef;">Pig<br />Pig是SQL-like语言，是在MapReduce上构建的一种高级查询语言，把一些运算编译进MapReduce模型的Map和Reduce中，并且用户可以定义自己的功能。Yahoo网格运算部门开发的又一个克隆Google的项目Sawzall。</p><p style="color: #333333; font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef;">ZooKeeper<br />Zookeeper是Google的Chubby一个开源的实现。它是一个针对大型分布式系统的可靠协调系统，提供的功能包括：配置维护、名字服务、分布式同步、组服务等。ZooKeeper的目标就是封装好复杂易出错的关键服务，将简单易用的接口和性能高效、功能稳定的系统提供给用户。</p><img src ="http://www.blogjava.net/xiaomage234/aggbug/398194.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2013-04-22 12:39 <a href="http://www.blogjava.net/xiaomage234/archive/2013/04/22/398194.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在CentOS 6.2 上安装和配置 KVM</title><link>http://www.blogjava.net/xiaomage234/archive/2013/04/11/397684.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Thu, 11 Apr 2013 01:59:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2013/04/11/397684.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/397684.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2013/04/11/397684.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/397684.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/397684.html</trackback:ping><description><![CDATA[<p align="left"><a href="http://www.vpsee.com/2010/04/redhat-released-rhel6-beta/"><span style="font-size:12.0pt;font-family:宋体;color:#3FA7CB;text-decoration:none;text-underline:none">RHEL6 <span style="font-size: 12pt; text-decoration: none;">已经推出很久了</span></span></a><span style="font-size: 12pt; font-family: 宋体;">，没想到在 RedHat 自家的 RHEL6 上安装 KVM 还有这么多问题，难道不应该是像 Apache/MySQL 那样安装完就可以用的么？（注：<a href="http://www.vpsee.com/2009/06/128mb-vps-optimize-centos5/"><span style="color:#3FA7CB;text-decoration:none;text-underline:none">除去商标，CentOS <span style="text-decoration: none;">就是 RHEL</span></span></a></span>，CentOS6 和 RHEL6 是一回事）。以下操作在 CentOS 6.2 最小化安装版本 CentOS-6.2-x86_64-minimal.iso 上完成，其他版本可能不会遇到本文提到的部分问题。</p>  <p align="left"><strong><span style="font-size: 12pt; font-family: 宋体;">检查 CPU</span></strong></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">和 Xen 不同，KVM 需要有 CPU 的支持（Intel VT 或 AMD SVM），在安装 KVM 之前检查一下 CPU 是否提供了虚拟技术的支持：</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;"># egrep '(vmx|svm)' --color=always /proc/cpuinfo<br /> flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx pdpe1gb rdtscp lm constant_tsc ida nonstop_tsc arat pni monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr sse4_1 sse4_2 popcnt lahf_lm<br /> flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx pdpe1gb rdtscp lm constant_tsc ida nonstop_tsc arat pni monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr sse4_1 sse4_2 popcnt lahf_lm<br /> flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx pdpe1gb rdtscp lm constant_tsc ida nonstop_tsc arat pni monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr sse4_1 sse4_2 popcnt lahf_lm<br /> flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx pdpe1gb rdtscp lm constant_tsc ida nonstop_tsc arat pni monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr sse4_1 sse4_2 popcnt lahf_lm<br /> flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx pdpe1gb rdtscp lm constant_tsc ida nonstop_tsc arat pni monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr sse4_1 sse4_2 popcnt lahf_lm<br /> flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx pdpe1gb rdtscp lm constant_tsc ida nonstop_tsc arat pni monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr sse4_1 sse4_2 popcnt lahf_lm<br /> flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx pdpe1gb rdtscp lm constant_tsc ida nonstop_tsc arat pni monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr sse4_1 sse4_2 popcnt lahf_lm<br /> flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx pdpe1gb rdtscp lm constant_tsc ida nonstop_tsc arat pni monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr sse4_1 sse4_2 popcnt lahf_lm<br /> flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx pdpe1gb rdtscp lm constant_tsc ida nonstop_tsc arat pni monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr sse4_1 sse4_2 popcnt lahf_lm<br /> flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx pdpe1gb rdtscp lm constant_tsc ida nonstop_tsc arat pni monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr sse4_1 sse4_2 popcnt lahf_lm<br /> flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx pdpe1gb rdtscp lm constant_tsc ida nonstop_tsc arat pni monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr sse4_1 sse4_2 popcnt lahf_lm<br /> flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx pdpe1gb rdtscp lm constant_tsc ida nonstop_tsc arat pni monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr sse4_1 sse4_2 popcnt lahf_lm<br /> flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx pdpe1gb rdtscp lm constant_tsc ida nonstop_tsc arat pni monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr sse4_1 sse4_2 popcnt lahf_lm<br /> flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx pdpe1gb rdtscp lm constant_tsc ida nonstop_tsc arat pni monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr sse4_1 sse4_2 popcnt lahf_lm<br /> flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx pdpe1gb rdtscp lm constant_tsc ida nonstop_tsc arat pni monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr sse4_1 sse4_2 popcnt lahf_lm<br /> flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx pdpe1gb rdtscp lm constant_tsc ida nonstop_tsc arat pni monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr sse4_1 sse4_2 popcnt lahf_lm</span></p>  <p align="left"><strong><span style="font-size: 12pt; font-family: 宋体;">安装KVM</span></strong></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">安装 KVM 很容易，要正常运行的话还需要折腾一下：</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">#yum -y install qemu-kvm libvirt python-virtinst bridge-utils</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">安装完后关闭 selinux 并重启系统，然后确认一下是否 kvm 安装成功：</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">#vi /etc/sysconfig/selinux<br /> SELINUX=disabled</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">#reboot</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">#lsmod | grep kvm<br /> kvm_intel 50412 3<br /> kvm 305988 1 kvm_intel</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">#stat /dev/kvm<br /> File: `/dev/kvm' <br /> Size: 0 Blocks: 0 IO Block: 4096 character special fileDevice: 5h/5d Inode: 10584 Links: 1 Device type: a,e8Access: (0666/crw-rw-rw-) Uid: ( 0/ root) Gid: ( 36/ kvm)<br /> Access: 2012-04-18 16:00:46.276341129 +0200<br /> Modify: 2012-04-18 16:00:46.276341129 +0200<br /> Change: 2012-04-18 16:00:46.276341129 +0200</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">再来确认一下 libvirt 是否能正常启动和关闭。重启 libvirtd 服务的话会报错，查看日志发现 internal error Failed to create mDNS client 错误，这个问题容易改正，安装 avahi 即可，也可以去 /etc/libvirt/libvirtd.conf 设置 mdns_adv = 0， 这里采用安装 avahi 的方法：</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;"># /etc/init.d/libvirtd restart<br /> Stopping libvirtd daemon: [FAILED]<br /> Starting libvirtd daemon: [ OK ]<br /> #tail /var/log/libvirt/libvirtd.log<br /> 2012-04-18 13:51:03.032+0000: 18149: info : libvirt version: 0.9.4, package: 23.el6_2.7 CentOSBuildSystem , 2012-04-16-14:12:59, c6b5.bsys.dev.centos.org)<br /> 2012-04-18 13:51:03.032+0000: 18149: error : virNetServerMDNSStart:460 : internal error Failed to create mDNS client: Daemon not running<br /> # yum -y install avahi<br /> # /etc/init.d/messagebus restart<br /> # /etc/init.d/avahi-daemon restart<br /> </span><span style="font-size: 12pt; font-family: 宋体;">重启 libvirtd 服务继续报错，发现缺少 dmidecode 包，安装 dmidecode 后终于重启 libvirtd 成功 ：</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;"># /etc/init.d/libvirtd restart<br /> Stopping libvirtd daemon: [FAILED]<br /> Starting libvirtd daemon: [ OK ]</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;"># tail /var/log/libvirt/libvirtd.log<br /> 2012-04-18 13:54:54.654+0000: 18320: info : libvirt version: 0.9.4, package: 23.el6_2.7 (CentOS BuildSystem , 2012-04-16-14:12:59, c6b5.bsys.dev.centos.org)<br /> 2012-04-18 13:54:54.654+0000: 18320: error : virSysinfoRead:465 : internal error Failed to find path for dmidecode binary</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;"># yum -y install dmidecode</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;"># /etc/init.d/libvirtd restart<br /> Stopping libvirtd daemon: [ OK ]<br /> Starting libvirtd daemon: [ OK ]<br /> </span><span style="font-size: 12pt; font-family: 宋体;">现在 kvm 和 libvirt 都安装成功和运行了，但并不表示可用了，问题接着来。</span></p>  <p align="left"><strong><span style="font-size: 12pt; font-family: 宋体;">配置网络桥接</span></strong></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">桥接网络配置文件，从ifcfg-eth0复制现有网卡的配置文件，改名为ifcfg-br0：</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-br0</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">修改ifcfg-br0，注意红色的两行，其他部分基本上不用改。</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">vi /etc/sysconfig/network-scripts/ifcfg-br0</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">DEVICE=br0</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">TYPE=Bridge</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">BOOTPROTO=static</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">BROADCAST=192.168.200.255</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">IPADDR=192.168.200.180</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">NETMASK=255.255.255.0</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">NETWORK=192.168.200.0</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">ONBOOT=yes</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">修改ifcfg-br0，注意红色的行，其他部分基本上不用改。</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">vi /etc/sysconfig/network-scripts/ifcfg-eth0</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">DEVICE=eth0</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">HWADDR=</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">ONBOOT=yes</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">BRIDGE=br0</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">#BOOTPROTO=static</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">#BROADCAST=192.168.200.255</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">#IPADDR=192.168.200.180</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">#NETMASK=255.255.255.0</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">#NETWORK=192.168.200.0</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">重启network服务 </span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">service network restart</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">这里需要注意，如果启用了NetworkManager，最好关闭该服务，因为该服务与network有冲突。</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">配置转发<br /> 执行以下命令：</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">echo 1 &gt; /proc/sys/net/ipv4/ip_forward</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">这一步虽然只有简单的一条命令，但却很关键。如果不执行这一步，所有的虚拟机将无法上网。另外，上一步配置完桥接之后重启network，会自动将ip_forward改为0，所以重新配置网络后，不要忘了执行该命令。发现虚拟机无法上网的时候，也可以检查一下ip_forward值。</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;"><br /> </span><strong><span style="font-size: 12pt; font-family: 宋体;">安装虚拟机</span></strong><span style="font-size: 12pt; font-family: 宋体;"><br /> </span><span style="font-size: 12pt; font-family: 宋体;">从 6 系列开始 RedHat 推荐使用 virt-install/virsh 系列工具操作 kvm，而不是直接使用 qemu-kvm，所以 qemu-kvm 被移到一个不起眼的地方 /usr/libexec/：</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;"># qemu-kvm-bash: qemu-kvm: command not found# ls /usr/libexec/qemu-kvm/usr/libexec/qemu-kvm<br /> VPSee </span><span style="font-size: 12pt; font-family: 宋体;">采用 RedHat 推荐的方式（virt-install）安装虚拟机，这里以安装 ubuntu-11.10-server-amd64.iso 为例：</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;"># virt-install \<br /> --name ubuntu \<br /> --ram 512 \<br /> --vcpus=1 \<br /> --disk path=/root/ubuntu.img,size=10 \<br /> --accelerate \<br /> --cdrom /root/ubuntu-11.10-server-amd64.iso \<br /> --graphics vnc<br /> </span><span style="font-size: 12pt; font-family: 宋体;">开始安装，创建硬盘 ubuntu.img 后就报错，用的是 root 帐号居然还 Permission denied?！</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">Starting install...Creating storage file ubuntu.img | 10.0 GB 00:00ERROR internal error Process exited while reading console log output: char device redirected to /dev/pts/1qemu-kvm: -drive file=/root/ubuntu.img,if=none,id=drive-ide0-0-0,format=raw,cache=none: could not open disk image /root/ubuntu.img: Permission denied<br /> Domain installation does not appear to have been successful.If it was, you can restart your domain by running: virsh --connect qemu:///system start ubuntuotherwise, please restart your installation.<br /> </span><span style="font-size: 12pt; font-family: 宋体;">修改 qemu.conf 配置，把下面几个地方的注释去掉，然后把 dynamic_ownership 的值改成0，禁止 libvirtd 动态修改文件的归属：</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;"># vi /etc/libvirt/qemu.conf</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">...</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">user = "root"</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">group = "root"</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">dynamic_ownership = 0</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">...<br /> </span><span style="font-size: 12pt; font-family: 宋体;">重启 libvirtd 服务再用上面的 virt-install 命令安装就应该可以了。这个时候 vnc 默认绑定的是本机 127.0.0.1，如果其他机器想用 vnc 客户端访问这台 kvm 服务器正在安装的 ubuntu 的话需要把 vnc 绑定到服务器的 IP 地址或者绑定到全局 0.0.0.0. 修改 qemu.conf 文件取消 vnc_listen 一行前面的注释，记得重启 libvirtd：</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;"># vi /etc/libvirt/qemu.conf</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">...</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">vnc_listen = "0.0.0.0"</span></p>  <p align="left"><span style="font-size: 12pt; font-family: 宋体;">...<br /> </span><span style="font-size: 12pt; font-family: 宋体;">在 CentOS 5.x 安装 KVM 可以看：在 CentOS 5上安装和配置 KVM</span></p>  <p>&nbsp;</p><img src ="http://www.blogjava.net/xiaomage234/aggbug/397684.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2013-04-11 09:59 <a href="http://www.blogjava.net/xiaomage234/archive/2013/04/11/397684.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> Centos6.2 KVM 虚拟机安装配置 </title><link>http://www.blogjava.net/xiaomage234/archive/2013/04/11/397682.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Thu, 11 Apr 2013 01:51:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2013/04/11/397682.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/397682.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2013/04/11/397682.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/397682.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/397682.html</trackback:ping><description><![CDATA[<p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">说明：</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">只有RHEL5.5以上 64位 server版才可以安装KVM，Centos相同。client版本和32位都安装不了KVM。</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">安装前期准备：&nbsp;因为有些CPU不支持kvm虚拟化，Need查看主板(BIOS)是否启动了虚拟化选项；&nbsp;另外在安<span style="word-wrap: break-word;">装Centos的软件包时，勾选虚拟化，&nbsp;如果没有选，&nbsp;可以用命令：<span style="word-wrap: break-word;">yum&nbsp;install&nbsp;virt*&nbsp;安装即可</span></span></p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">&nbsp;</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;"><strong style="word-wrap: break-word;">0.&nbsp;配置BIOS</strong></p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">使BIOS支持虚拟化，</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;"><span style="word-wrap: break-word; color: #99bb00;">如果没配置的话会报错：</span></p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;"><span style="word-wrap: break-word; color: #99bb00;">&#8220;Error polling connection 'qemu:///system': internal error Cannot find suitable emulator for x86_64</span><span style="word-wrap: break-word; color: #99bb00;">&nbsp;&#8221;</span></p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">&nbsp;</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;"><strong style="word-wrap: break-word;">1.需要软件</strong></p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.1Kvm&nbsp;模块</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2.6.29之后内核大多包含了kvm模块，&nbsp;Slackware13.37内核版本为2.6.32已经包含&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;了kvm模块，所以无需从网上下载kvm-mod模块，否则模块无法正常启动，kvm虚拟机&nbsp;&nbsp;速度极慢。</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.2用户空间组件</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;目前两种版本qemu-kvm&nbsp;和&nbsp;kvm&nbsp;的用户空间组件，kvm&nbsp;现在已经不提倡使用，最好使用qemu-kvm，从网上下载qemu-kvm-1.0.tar.gz，&nbsp;版本号1.0</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.3&nbsp;yum&nbsp;install&nbsp;&nbsp;tunctl&nbsp;组件，版本号1.5，&nbsp;主要用来实现虚拟机联网packages is in&nbsp; DVD.</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;"><br style="word-wrap: break-word;" /></p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;"><strong style="word-wrap: break-word;">2.安装步骤</strong>&nbsp;</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2.1&nbsp;&nbsp;安装&nbsp;&nbsp;&nbsp;qemu-kvm（如果yum 安装了qemu-kvn可以不安装这一步。）</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">&nbsp;<span style="word-wrap: break-word;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;./configure&nbsp;--disable-vnc-tls&nbsp;--disable-vnc-sasl&nbsp;&nbsp;&nbsp;&nbsp;把这个VNC选项禁掉否则会报错；</span></p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;"><span style="word-wrap: break-word;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;make</span></p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;"><span style="word-wrap: break-word;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;make&nbsp;install</span></p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2.2&nbsp;&nbsp;安装&nbsp;&nbsp;&nbsp;tunctl&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;yum&nbsp;install&nbsp;&nbsp;tunctl&nbsp;-y</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">重启server，调试CPU.</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;"><br style="word-wrap: break-word;" /></p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;"><strong style="word-wrap: break-word;">3.主机和客户机联网</strong></p><div id="detail" style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; background-color: #ffffff; line-height: 1.3;"><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px;"><a href="http://blog.chinaunix.net/.:;" target="_blank" style="word-wrap: break-word; text-decoration: none; color: #19599b;"><span style="word-wrap: break-word; color: #63401b; font-size: medium;">设置网卡桥接模式</span></a>&nbsp;&nbsp;</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px;">一&nbsp; 真实机上配置</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px;">[root@localhost src]# cd /etc/sysconfig/network-scripts/<br style="word-wrap: break-word;" />1/ 备份网卡<br style="word-wrap: break-word;" />&nbsp;cp -rap ifcfg-eth0 bak.ifcfg-eth0<br style="word-wrap: break-word;" />2/新的桥接网卡使用eth0的配置文件<br style="word-wrap: break-word;" />&nbsp; cp -rap ifcfg-eth0 ifcfg-br33<br style="word-wrap: break-word;" />3/编辑这两个配置文件 注意编辑这个文件会导致网卡ip宕掉。可以先编辑下面的配置文件。<br style="word-wrap: break-word;" /><br style="word-wrap: break-word;" />vim ifcfg-eth0<br style="word-wrap: break-word;" />DEVICE=eth0<br style="word-wrap: break-word;" />BOOTPROTO=none<br style="word-wrap: break-word;" />HWADDR=bc:ae:c5:df:93:96<br style="word-wrap: break-word;" />NM_CONTROLLED=yes<br style="word-wrap: break-word;" />ONBOOT=yes<br style="word-wrap: break-word;" />BRIDGE="br33"<br style="word-wrap: break-word;" />IPV6INIT=no<br style="word-wrap: break-word;" />USERCTL=no<br style="word-wrap: break-word;" /><br style="word-wrap: break-word;" />保存推出<br style="word-wrap: break-word;" /><br style="word-wrap: break-word;" />vim /etc/sysconfig/network-scripts/ifcfg-br33&nbsp;<br style="word-wrap: break-word;" />DEVICE=br33<br style="word-wrap: break-word;" />BOOTPROTO=static<br style="word-wrap: break-word;" />HWADDR=bc:ae:c5:df:93:96<br style="word-wrap: break-word;" />NM_CONTROLLED=yes<br style="word-wrap: break-word;" />ONBOOT=yes<br style="word-wrap: break-word;" />TYPE=Bridge<br style="word-wrap: break-word;" />IPADDR=192.168.1.202<br style="word-wrap: break-word;" />NETMASK=255.255.255.0<br style="word-wrap: break-word;" />GATEWAY=192.168.1.1<br style="word-wrap: break-word;" />DNS1=8.8.8.8<br style="word-wrap: break-word;" />保存推出<br style="word-wrap: break-word;" />重启网卡<br style="word-wrap: break-word;" /><br style="word-wrap: break-word;" />/etc/init.d/network restart</p></div><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">3. 关闭centos的NetworkManager（这一步可以不做）</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">一定要关闭这个服务，否则网卡的脚本配置文件可能不会生效，上不了网</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">service&nbsp;NetworkManager&nbsp;stop</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">&nbsp;</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">3.4重启网络服务</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">service&nbsp;network&nbsp;restart</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;"><br style="word-wrap: break-word;" /></p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">3.5开启转发（这一步可以不做）</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">echo&nbsp;1&nbsp;&gt;<strong style="word-wrap: break-word;">&nbsp;</strong>/proc/sys/net/ipv4/ip_forward</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;"><br style="word-wrap: break-word;" />3.6 Review network card status:<br style="word-wrap: break-word;" /><br style="word-wrap: break-word;" />[root@localhost ~]# ifconfig<br style="word-wrap: break-word;" />br33&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Link encap:Ethernet&nbsp; HWaddr 00:25:64:97:BA:51 &nbsp;<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inet addr:192.168.120.96&nbsp; Bcast:192.168.120.255&nbsp; Mask:255.255.255.0<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inet6 addr: fe80::225:64ff:fe97:ba51/64 Scope:Link<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; UP BROADCAST RUNNING MULTICAST&nbsp; MTU:1500&nbsp; Metric:1<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RX packets:641005 errors:0 dropped:0 overruns:0 frame:0<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TX packets:4785 errors:0 dropped:0 overruns:0 carrier:0<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; collisions:0 txqueuelen:0&nbsp;<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RX bytes:64019315 (61.0 MiB)&nbsp; TX bytes:278717 (272.1 KiB)<br style="word-wrap: break-word;" /><br style="word-wrap: break-word;" />eth0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Link encap:Ethernet&nbsp; HWaddr 00:25:64:97:BA:51 &nbsp;<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inet6 addr: fe80::225:64ff:fe97:ba51/64 Scope:Link<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; UP BROADCAST RUNNING PROMISC MULTICAST&nbsp; MTU:1500&nbsp; Metric:1<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RX packets:1410323 errors:0 dropped:0 overruns:0 frame:0<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TX packets:465818 errors:0 dropped:0 overruns:0 carrier:0<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; collisions:0 txqueuelen:1000&nbsp;<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RX bytes:254264481 (242.4 MiB)&nbsp; TX bytes:293774426 (280.1 MiB)<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Interrupt:21 Memory:fe6e0000-fe700000&nbsp;<br style="word-wrap: break-word;" /><br style="word-wrap: break-word;" />lo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Link encap:Local Loopback &nbsp;<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inet addr:127.0.0.1&nbsp; Mask:255.0.0.0<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inet6 addr: ::1/128 Scope:Host<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; UP LOOPBACK RUNNING&nbsp; MTU:16436&nbsp; Metric:1<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RX packets:468571 errors:0 dropped:0 overruns:0 frame:0<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TX packets:468571 errors:0 dropped:0 overruns:0 carrier:0<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; collisions:0 txqueuelen:0&nbsp;<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RX bytes:898319692 (856.7 MiB)&nbsp; TX bytes:898319692 (856.7 MiB)<br style="word-wrap: break-word;" /><br style="word-wrap: break-word;" />virbr0&nbsp;&nbsp;&nbsp; Link encap:Ethernet&nbsp; HWaddr 52:54:00:B3:44:41 &nbsp;<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inet addr:192.168.122.1&nbsp; Bcast:192.168.122.255&nbsp; Mask:255.255.255.0<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; UP BROADCAST RUNNING MULTICAST&nbsp; MTU:1500&nbsp; Metric:1<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RX packets:0 errors:0 dropped:0 overruns:0 frame:0<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TX packets:4293 errors:0 dropped:0 overruns:0 carrier:0<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; collisions:0 txqueuelen:0&nbsp;<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RX bytes:0 (0.0 b)&nbsp; TX bytes:205669 (200.8 KiB)<br style="word-wrap: break-word;" /><br style="word-wrap: break-word;" />vnet0&nbsp;&nbsp;&nbsp;&nbsp; Link encap:Ethernet&nbsp; HWaddr FE:54:00:11:CE:91 &nbsp;<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inet6 addr: fe80::fc54:ff:fe11:ce91/64 Scope:Link<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; UP BROADCAST RUNNING MULTICAST&nbsp; MTU:1500&nbsp; Metric:1<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RX packets:182999 errors:0 dropped:0 overruns:0 frame:0<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TX packets:911932 errors:0 dropped:0 overruns:0 carrier:0<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; collisions:0 txqueuelen:500&nbsp;<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RX bytes:266186182 (253.8 MiB)&nbsp; TX bytes:110334183 (105.2 MiB)<br style="word-wrap: break-word;" /><br style="word-wrap: break-word;" />vnet1&nbsp;&nbsp;&nbsp;&nbsp; Link encap:Ethernet&nbsp; HWaddr FE:54:00:A5:0F:52 &nbsp;<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inet6 addr: fe80::fc54:ff:fea5:f52/64 Scope:Link<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; UP BROADCAST RUNNING MULTICAST&nbsp; MTU:1500&nbsp; Metric:1<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RX packets:161319 errors:0 dropped:0 overruns:0 frame:0<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TX packets:783482 errors:0 dropped:0 overruns:0 carrier:0<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; collisions:0 txqueuelen:500&nbsp;<br style="word-wrap: break-word;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RX bytes:20856924 (19.8 MiB)&nbsp; TX bytes:97247791 (92.7 MiB)<br style="word-wrap: break-word;" /><br style="word-wrap: break-word;" />[root@localhost ~]#&nbsp;<br style="word-wrap: break-word;" /><span style="word-wrap: break-word; font-size: 14px; color: #e53333; background-color: #60d978;">Summary: eth0 don't have IP address, only br33 has valid IP. That is to say, br33 IP address is server's IP address.</span></p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">小结：之前主机不能上网，虚拟机可以上网，可能的：1.没有写网桥的配置文件而是参照KVM官网上面，用命令来添加网桥，绑定网卡，故网桥就没有配置网关2.开启了NetworkManager&nbsp;这个服务，导致用ifconfig命令来配置网络失效3.没有正确的设置好DNS</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;"><span style="word-wrap: break-word; color: #f00000; font-size: small;">##########&nbsp; 新建完虚拟机后，千万不要使用默认的硬盘类型，要删除默认的硬盘，然后再添加一块硬盘，硬盘类型要vda的，硬盘格式要raw的，缓存模式要none，即可。&nbsp; #########<br style="word-wrap: break-word;" />使用默认的硬盘类型会出现死机情况和老牛拉破车情况---慢！！！</span></p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">###########&nbsp; 注意选择架构和虚拟机类型，一定要选择kvm，架构符合你的虚拟机的实际情况，我的虚拟机选择kvm和i686，否则虚拟机非常慢，都没法使用了。&nbsp; ################################</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;"><a href="http://blog.chinaunix.net/attachment/201301/5/15866552_1357374822uSe7.png" target="_blank" style="word-wrap: break-word; text-decoration: none; color: #19599b;"><img src="http://blog.chinaunix.net/attachment/201301/5/15866552_1357374822uSe7.png"  ;="" .="imgResize(this, 650);" height="528" width="462" border="0" style="word-wrap: break-word; border: 0px;"  alt="" /></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;"><strong style="word-wrap: break-word;">4.0&nbsp;新建KVM虚拟机</strong></p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;"><strong style="word-wrap: break-word;">安装虚拟机时，选择高级-网卡-br33，即可。</strong></p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;切换到root用户：&nbsp;su&nbsp;&#8211;l</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;安装kvm模块&nbsp;&nbsp;&nbsp;&nbsp;modprobe&nbsp;kvm &amp;&amp; modprobe kvm_intel</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;查看模块安装;&nbsp;lsmod&nbsp;|&nbsp;grep&nbsp;kvm</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">&nbsp;</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;"><span style="word-wrap: break-word; color: #e53333; font-size: 14px;">新建虚拟机的步骤：</span></p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">1. 在服务器上键入命令：（因为要选择镜像格式qcow2来做快照，所以不能使用图形界面默认的格式）</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">[root@PLASPACSHCN14 ~]# cd /var/lib/libvirt/images/</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">[root@PLASPACSHCN14 images]# qemu-img create -f qcow2 test.img 10G</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">Formatting 'test1.img', fmt=qcow2 size=10737418240 encryption=off cluster_size=65536</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">大小我给10G，根据需求自己可以定义，镜像名称是test.img。</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">2. 打开图形界面：</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">[root@PLASPACSHCN14 images]# virt-manager&nbsp;<br style="word-wrap: break-word;" />Xlib:&nbsp; extension "RANDR" missing on display "localhost:10.0".</p><img alt="" src="http://blog.chinaunix.net/attachment/201301/23/15866552_13589309184YQK.png" height="239" width="563" style="word-wrap: break-word; border: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;" /><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">选择new，来新建一个虚拟机：</p><img alt="" src="http://blog.chinaunix.net/attachment/201301/23/15866552_1358930991Pzvv.png" height="401" width="462" style="word-wrap: break-word; border: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;" /><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">这里输入虚拟机的名字，然后注意，一定要选择&#8220;import existing disk image&#8221;,这样才可以选择刚才创建好的镜像。</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">选择&#8220;Forward&#8221;</p><img alt="" src="http://blog.chinaunix.net/attachment/201301/23/15866552_13589312880MMo.png" height="399" width="459" style="word-wrap: break-word; border: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;" /><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">这里输入刚才创建的镜像的路径即可。</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">选择下一步。</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">一路下一步，等待设置完成之后，会发现，没有选择光驱。</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">选择Details选项</p><img alt="" src="http://blog.chinaunix.net/attachment/201301/23/15866552_13589314550GUB.png" height="564" width="700" style="word-wrap: break-word; border: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;" /><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">这里选择&#8220;Add Hardware&#8221;</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">下面需要修改光盘文件的路径，指向操作系统镜像文件即可。</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">然后Device type:这里选择"IDE cdrom"即可。如图：</p><img alt="" src="http://blog.chinaunix.net/attachment/201301/23/15866552_13589317418Wog.png" height="472" width="662" style="word-wrap: break-word; border: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;" /><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">&nbsp;</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">接下来，点击finish。重启之后继续安装系统就OK啦！</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">&nbsp;</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">&nbsp;</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">&nbsp;<span style="word-wrap: break-word; font-size: 14px;">kvm相关命令：</span></p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">开启虚拟机：</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">virt-manager</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">4.1为客户机新建一个硬盘镜像</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;qemu-img create&nbsp;-f&nbsp;qcow2&nbsp;vdisk.img&nbsp;50G</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">4.2安装客户机操作系统：</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;光盘启动：</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;qemu-system-x86_64-hda&nbsp;vdisk.img&nbsp;-cdrom&nbsp;/dev/cdrom&nbsp;-boot&nbsp;d&nbsp;-m&nbsp;512</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.iso文件启动:</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;qemu-system-x86_64-hda&nbsp;vdisk.img&nbsp;-cdrom&nbsp;/Centos6.0.iso(此处为iso文件路径)&nbsp;-bootd&nbsp;&nbsp;-m512</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">4.3启动操作系统：</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;qemu-system-x86_64&#8211;had&nbsp;vdisk.img&#8211;net&nbsp;nic,macaddr=自定义物理地址&#8211;net&nbsp;tap&nbsp;&#8211;&nbsp;&nbsp;m&nbsp;512</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">启动客户机后，可以如一般操作系统来使用，如果要联网配下客户机的ip和网关即可上网</p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;"><br style="word-wrap: break-word;" /></p><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">过程中碰到的问题如：Centos6.2&nbsp;下KVM&nbsp;虚拟机&nbsp;花屏死机问题，&nbsp;VNC错误等参见博客的其他文章，如有其他问题欢迎留言共同探讨，&nbsp;另外以上命令可写成脚本简化安装。</p><img src ="http://www.blogjava.net/xiaomage234/aggbug/397682.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2013-04-11 09:51 <a href="http://www.blogjava.net/xiaomage234/archive/2013/04/11/397682.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Xmanager连接CentOS6</title><link>http://www.blogjava.net/xiaomage234/archive/2013/04/10/397656.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Wed, 10 Apr 2013 11:04:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2013/04/10/397656.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/397656.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2013/04/10/397656.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/397656.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/397656.html</trackback:ping><description><![CDATA[<div style="margin: 5px 0px; font-size: 20px; line-height: 30px; font-family: 'Microsoft YaHei'; background-color: #ffffff;"><h3><span style="color: #333333; font-family: Arial; line-height: 26px; font-size: 14px;">1 修改 /etc/X11/xdm/Xaccess</span></h3></div><div id="article_content" style="margin: 20px 0px 0px; line-height: 26px; font-family: Arial; color: #333333; background-color: #ffffff;"><p>去掉下面的注释<br /></p><p>&nbsp;</p><div bg_cpp"="" style="width: 687.046875px;"><div><div><strong>[cpp]</strong>&nbsp;<a href="http://blog.csdn.net/ppdouble/article/details/8483107#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">view plain</a><a href="http://blog.csdn.net/ppdouble/article/details/8483107#" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">copy</a><div style="position: absolute; left: 715px; top: 449px; width: 18px; height: 18px; z-index: 99;"></div></div></div><ol start="1"><li style="line-height: 18px;">#*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#any&nbsp;host&nbsp;can&nbsp;get&nbsp;a&nbsp;login&nbsp;window&nbsp;&nbsp;</li></ol></div><p>2 修改启动模式/etc/inittab</p><p>&nbsp;</p><div bg_cpp"="" style="width: 687.046875px;"><div><div><strong>[cpp]</strong>&nbsp;<a href="http://blog.csdn.net/ppdouble/article/details/8483107#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">view plain</a><a href="http://blog.csdn.net/ppdouble/article/details/8483107#" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">copy</a><div style="position: absolute; left: 715px; top: 562px; width: 18px; height: 18px; z-index: 99;"></div></div></div><ol start="1"><li style="line-height: 18px;">id:5:initdefault:&nbsp;&nbsp;</li></ol></div>3修改/etc/gdm/custom.conf<br /><p>&nbsp;</p><p>&nbsp;</p><div bg_cpp"="" style="width: 687.046875px;"><div><div><strong>[cpp]</strong>&nbsp;<a href="http://blog.csdn.net/ppdouble/article/details/8483107#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">view plain</a><a href="http://blog.csdn.net/ppdouble/article/details/8483107#" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">copy</a><div style="position: absolute; left: 715px; top: 675px; width: 18px; height: 18px; z-index: 99;"></div></div></div><ol start="1"><li style="line-height: 18px;">#&nbsp;GDM&nbsp;configuration&nbsp;storage&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">[daemon]&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">[security]&nbsp;&nbsp;</li><li style="line-height: 18px;">AllowRemoteRoot=true&nbsp;&nbsp;</li><li style="line-height: 18px;">DisallowTCP=false&nbsp;&nbsp;</li><li style="line-height: 18px;">[xdmcp]&nbsp;&nbsp;</li><li style="line-height: 18px;">Enable=true&nbsp;&nbsp;</li><li style="line-height: 18px;">Port=177&nbsp;&nbsp;</li><li style="line-height: 18px;">[greeter]&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">[chooser]&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;</li><li style="line-height: 18px;">[debug]&nbsp;&nbsp;</li></ol></div><p>4修改/etc/X11/xdm/xdm-config用 ! 注释下面的语句</p><p>&nbsp;</p><div bg_cpp"="" style="width: 687.046875px;"><div><div><strong>[cpp]</strong>&nbsp;<a href="http://blog.csdn.net/ppdouble/article/details/8483107#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">view plain</a><a href="http://blog.csdn.net/ppdouble/article/details/8483107#" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">copy</a><div style="position: absolute; left: 715px; top: 1040px; width: 18px; height: 18px; z-index: 99;"></div></div></div><ol start="1"><li style="line-height: 18px;">!DisplayManager.requestPort:&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;</li></ol></div>5 修改以下文件权限，确保有444权限<br /><p>&nbsp;</p><p>&nbsp;</p><div bg_cpp"="" style="width: 687.046875px;"><div><div><strong>[cpp]</strong>&nbsp;<a href="http://blog.csdn.net/ppdouble/article/details/8483107#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">view plain</a><a href="http://blog.csdn.net/ppdouble/article/details/8483107#" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">copy</a><div style="position: absolute; left: 715px; top: 1153px; width: 18px; height: 18px; z-index: 99;"></div></div></div><ol start="1"><li style="line-height: 18px;">#&nbsp;ll&nbsp;/etc/X11/xdm/Xservers&nbsp;&nbsp;</li><li style="line-height: 18px;">-rw-r--r--.&nbsp;1&nbsp;root&nbsp;root&nbsp;485&nbsp;Jan&nbsp;&nbsp;6&nbsp;22:35&nbsp;/etc/X11/xdm/Xservers&nbsp;&nbsp;</li><li style="line-height: 18px;">#&nbsp;ll&nbsp;/etc/X11/xdm/Xsetup_0&nbsp;&nbsp;</li><li style="line-height: 18px;">-rwxr-xr-x.&nbsp;1&nbsp;root&nbsp;root&nbsp;938&nbsp;Aug&nbsp;20&nbsp;&nbsp;2010&nbsp;/etc/X11/xdm/Xsetup_0&nbsp;&nbsp;</li></ol></div><p>7 修改/etc/securetty<br /></p><p>&nbsp;</p><div bg_cpp"="" style="width: 687.046875px;"><div><div><strong>[cpp]</strong>&nbsp;<a href="http://blog.csdn.net/ppdouble/article/details/8483107#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">view plain</a><a href="http://blog.csdn.net/ppdouble/article/details/8483107#" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">copy</a><div style="position: absolute; left: 715px; top: 1320px; width: 18px; height: 18px; z-index: 99;"></div></div></div><ol start="1"><li style="line-height: 18px;">tty1&nbsp;&nbsp;</li><li style="line-height: 18px;">tty2&nbsp;&nbsp;</li><li style="line-height: 18px;">tty3&nbsp;&nbsp;</li><li style="line-height: 18px;">tty4&nbsp;&nbsp;</li><li style="line-height: 18px;">tty5&nbsp;&nbsp;</li><li style="line-height: 18px;">tty6&nbsp;&nbsp;</li><li style="line-height: 18px;">tty7&nbsp;&nbsp;</li><li style="line-height: 18px;">tty8&nbsp;&nbsp;</li><li style="line-height: 18px;">tty9&nbsp;&nbsp;</li><li style="line-height: 18px;">tty10&nbsp;&nbsp;</li><li style="line-height: 18px;">tty11&nbsp;&nbsp;</li><li style="line-height: 18px;">rsh&nbsp;&nbsp;</li><li style="line-height: 18px;">rexec&nbsp;&nbsp;</li><li style="line-height: 18px;">rlogin&nbsp;&nbsp;</li></ol></div>添加<div bg_cpp"="" style="width: 687.046875px;"><div><div><strong>[cpp]</strong>&nbsp;<a href="http://blog.csdn.net/ppdouble/article/details/8483107#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">view plain</a><a href="http://blog.csdn.net/ppdouble/article/details/8483107#" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">copy</a><div style="position: absolute; left: 715px; top: 1667px; width: 18px; height: 18px; z-index: 99;"></div></div></div><ol start="1"><li style="line-height: 18px;">pts/0&nbsp;&nbsp;</li><li style="line-height: 18px;">pts/1&nbsp;&nbsp;</li><li style="line-height: 18px;">pts/2&nbsp;&nbsp;</li><li style="line-height: 18px;">pts/3&nbsp;&nbsp;</li><li style="line-height: 18px;">pts/4&nbsp;&nbsp;</li></ol></div>8 修改/etc/pam.d/login<br /><p>&nbsp;</p><p>&nbsp;</p><div bg_cpp"="" style="width: 687.046875px;"><div><div><strong>[cpp]</strong>&nbsp;<a href="http://blog.csdn.net/ppdouble/article/details/8483107#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">view plain</a><a href="http://blog.csdn.net/ppdouble/article/details/8483107#" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">copy</a><div style="position: absolute; left: 715px; top: 1852px; width: 18px; height: 18px; z-index: 99;"></div></div></div><ol start="1"><li style="line-height: 18px;">#%PAM-1.0&nbsp;&nbsp;</li></ol></div>注释掉<div bg_cpp"="" style="width: 687.046875px;"><div><div><strong>[cpp]</strong>&nbsp;<a href="http://blog.csdn.net/ppdouble/article/details/8483107#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">view plain</a><a href="http://blog.csdn.net/ppdouble/article/details/8483107#" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">copy</a><div style="position: absolute; left: 715px; top: 1965px; width: 18px; height: 18px; z-index: 99;"></div></div></div><ol start="1"><li style="line-height: 18px;">#auth&nbsp;[user_unknown=ignore&nbsp;success=ok&nbsp;ignore=ignore&nbsp;default=bad]&nbsp;pam_securetty.so&nbsp;&nbsp;</li></ol></div><div bg_cpp"="" style="width: 687.046875px;"><div><div><strong>[cpp]</strong>&nbsp;<a href="http://blog.csdn.net/ppdouble/article/details/8483107#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">view plain</a><a href="http://blog.csdn.net/ppdouble/article/details/8483107#" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">copy</a><div style="position: absolute; left: 715px; top: 2034px; width: 18px; height: 18px; z-index: 99;"></div></div></div><ol start="1"><li style="line-height: 18px;">auth&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;include&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;system-auth&nbsp;&nbsp;</li><li style="line-height: 18px;">account&nbsp;&nbsp;&nbsp;&nbsp;required&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pam_nologin.so&nbsp;&nbsp;</li><li style="line-height: 18px;">account&nbsp;&nbsp;&nbsp;&nbsp;include&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;system-auth&nbsp;&nbsp;</li><li style="line-height: 18px;">password&nbsp;&nbsp;&nbsp;include&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;system-auth&nbsp;&nbsp;</li><li style="line-height: 18px;">#&nbsp;pam_selinux.so&nbsp;close&nbsp;should&nbsp;be&nbsp;the&nbsp;first&nbsp;session&nbsp;rule&nbsp;&nbsp;</li><li style="line-height: 18px;">session&nbsp;&nbsp;&nbsp;&nbsp;required&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pam_selinux.so&nbsp;close&nbsp;&nbsp;</li><li style="line-height: 18px;">session&nbsp;&nbsp;&nbsp;&nbsp;required&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pam_loginuid.so&nbsp;&nbsp;</li><li style="line-height: 18px;">session&nbsp;&nbsp;&nbsp;&nbsp;optional&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pam_console.so&nbsp;&nbsp;</li><li style="line-height: 18px;">#&nbsp;pam_selinux.so&nbsp;open&nbsp;should&nbsp;only&nbsp;be&nbsp;followed&nbsp;by&nbsp;sessions&nbsp;to&nbsp;be&nbsp;executed&nbsp;in&nbsp;the&nbsp;user&nbsp;context&nbsp;&nbsp;</li><li style="line-height: 18px;">session&nbsp;&nbsp;&nbsp;&nbsp;required&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pam_selinux.so&nbsp;open&nbsp;&nbsp;</li><li style="line-height: 18px;">session&nbsp;&nbsp;&nbsp;&nbsp;required&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pam_namespace.so&nbsp;&nbsp;</li><li style="line-height: 18px;">session&nbsp;&nbsp;&nbsp;&nbsp;optional&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pam_keyinit.so&nbsp;force&nbsp;revoke&nbsp;&nbsp;</li><li style="line-height: 18px;">session&nbsp;&nbsp;&nbsp;&nbsp;include&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;system-auth&nbsp;&nbsp;</li><li style="line-height: 18px;">-session&nbsp;&nbsp;&nbsp;optional&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pam_ck_connector.so&nbsp;&nbsp;</li></ol></div>9 修改&nbsp;/etc/pam.d/remote<div bg_cpp"="" style="width: 687.046875px;"><div><div><strong>[cpp]</strong>&nbsp;<a href="http://blog.csdn.net/ppdouble/article/details/8483107#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">view plain</a><a href="http://blog.csdn.net/ppdouble/article/details/8483107#" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">copy</a><div style="position: absolute; left: 715px; top: 2398px; width: 18px; height: 18px; z-index: 99;"></div></div></div><ol start="1"><li style="line-height: 18px;">#%PAM-1.0&nbsp;&nbsp;</li></ol></div>注释掉<div bg_cpp"="" style="width: 687.046875px;"><div><div><strong>[cpp]</strong>&nbsp;<a href="http://blog.csdn.net/ppdouble/article/details/8483107#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">view plain</a><a href="http://blog.csdn.net/ppdouble/article/details/8483107#" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">copy</a><div style="position: absolute; left: 715px; top: 2511px; width: 18px; height: 18px; z-index: 99;"></div></div></div><ol start="1"><li style="line-height: 18px;">#auth&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;required&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pam_securetty.so&nbsp;&nbsp;</li></ol></div><div bg_cpp"="" style="width: 687.046875px;"><div><div><strong>[cpp]</strong>&nbsp;<a href="http://blog.csdn.net/ppdouble/article/details/8483107#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">view plain</a><a href="http://blog.csdn.net/ppdouble/article/details/8483107#" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">copy</a><div style="position: absolute; left: 715px; top: 2580px; width: 18px; height: 18px; z-index: 99;"></div></div></div><ol start="1"><li style="line-height: 18px;">auth&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;include&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;password-auth&nbsp;&nbsp;</li><li style="line-height: 18px;">account&nbsp;&nbsp;&nbsp;&nbsp;required&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pam_nologin.so&nbsp;&nbsp;</li><li style="line-height: 18px;">account&nbsp;&nbsp;&nbsp;&nbsp;include&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;password-auth&nbsp;&nbsp;</li><li style="line-height: 18px;">password&nbsp;&nbsp;&nbsp;include&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;password-auth&nbsp;&nbsp;</li><li style="line-height: 18px;">#&nbsp;pam_selinux.so&nbsp;close&nbsp;should&nbsp;be&nbsp;the&nbsp;first&nbsp;session&nbsp;rule&nbsp;&nbsp;</li><li style="line-height: 18px;">session&nbsp;&nbsp;&nbsp;&nbsp;required&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pam_selinux.so&nbsp;close&nbsp;&nbsp;</li><li style="line-height: 18px;">session&nbsp;&nbsp;&nbsp;&nbsp;required&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pam_loginuid.so&nbsp;&nbsp;</li><li style="line-height: 18px;">#&nbsp;pam_selinux.so&nbsp;open&nbsp;should&nbsp;only&nbsp;be&nbsp;followed&nbsp;by&nbsp;sessions&nbsp;to&nbsp;be&nbsp;executed&nbsp;in&nbsp;the&nbsp;user&nbsp;context&nbsp;&nbsp;</li><li style="line-height: 18px;">session&nbsp;&nbsp;&nbsp;&nbsp;required&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pam_selinux.so&nbsp;open&nbsp;&nbsp;</li><li style="line-height: 18px;">session&nbsp;&nbsp;&nbsp;&nbsp;required&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pam_namespace.so&nbsp;&nbsp;</li><li style="line-height: 18px;">session&nbsp;&nbsp;&nbsp;&nbsp;optional&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pam_keyinit.so&nbsp;force&nbsp;revoke&nbsp;&nbsp;</li><li style="line-height: 18px;">session&nbsp;&nbsp;&nbsp;&nbsp;include&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;password-auth&nbsp;&nbsp;</li></ol></div>9关闭防火墙，或开放UDP 177端口<p>可以使用system-config-firewall操作防火墙</p><p>可以使用/etc/init.d/iptables stop关闭防火墙</p><p>10重启机器<br /></p><p>&nbsp;</p>以上操作，顺序及原因不详，望指点，很多操作都是照葫芦画瓢，不讲原因，弄对了就OK，下次还是不明白。<br /><p>参考：</p><p><a target="_blank" href="http://lmdkfs.blog.163.com/blog/static/7461132420124445749639/" style="color: #336699; text-decoration: none;">http://lmdkfs.blog.163.com/blog/static/7461132420124445749639/</a></p><p><a target="_blank" href="http://wenku.baidu.com/view/ac4a2f1aa8114431b90dd842.html" style="color: #336699; text-decoration: none;">http://wenku.baidu.com/view/ac4a2f1aa8114431b90dd842.html</a></p><p><a target="_blank" href="http://blog.sina.com.cn/s/blog_7065a1e40100mahz.html" style="color: #336699; text-decoration: none;">http://blog.sina.com.cn/s/blog_7065a1e40100mahz.html</a></p><p><a target="_blank" href="http://hi.baidu.com/edeed/item/7e511dd9d1e4003e48e1dd8a" style="color: #336699; text-decoration: none;">http://hi.baidu.com/edeed/item/7e511dd9d1e4003e48e1dd8a</a></p></div><img src ="http://www.blogjava.net/xiaomage234/aggbug/397656.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2013-04-10 19:04 <a href="http://www.blogjava.net/xiaomage234/archive/2013/04/10/397656.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ext4，Ext3的特点和区别</title><link>http://www.blogjava.net/xiaomage234/archive/2013/04/10/397638.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Wed, 10 Apr 2013 04:35:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2013/04/10/397638.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/397638.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2013/04/10/397638.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/397638.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/397638.html</trackback:ping><description><![CDATA[<p align="center" style="text-align:center"><strong><span style="font-size:14.0pt;">Ext4</span></strong><strong><span style="font-size:14.0pt;font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，</span></strong><strong><span style="font-size:14.0pt;">Ext3</span></strong><strong><span style="font-size:14.0pt;font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的特点和区别</span></strong><strong></strong></p>  <p align="center" style="text-align:center">&nbsp;</p>  <p>&nbsp;Linux kernel <span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">自</span> 2.6.28 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">开始正式支持新的文件系统</span> Ext4<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span> Ext4 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">是</span> Ext3 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的改进版，修改了</span> Ext3 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">中部分重要的数据结构，而不仅仅像</span> Ext3 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">对</span> Ext2 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">那样，只是增加了一个日志功能而已。</span>Ext4 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">可以提供更佳的性能和可靠性，还有更为丰富的功能：</span></p>  <p>&nbsp;</p>  <p>1. <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">与</span> Ext3 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">兼容。</span> <span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">执行若干条命令，就能从</span> Ext3 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">在线迁移到</span> Ext4<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，而无须重新格式化磁盘或重新安装系统。原有</span> Ext3 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">数据结构照样保留，</span>Ext4 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">作用于新数据，当然，整个文件系统因此也就获得了</span> Ext4 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">所支持的更大容量。</span></p>  <p>&nbsp;</p>  <p>2. <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">更大的文件系统和更大的文件。</span> <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">较之</span> Ext3 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">目前所支持的最大</span> 16TB <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件系统和最大</span> 2TB <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件，</span>Ext4 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">分别支持</span> 1EB<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">（</span>1,048,576TB<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，</span> 1EB=1024PB<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，</span> 1PB=1024TB<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）的文件系统，以及</span> 16TB <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的文件。</span></p>  <p>&nbsp;</p>  <p>3. <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">无限数量的子目录。</span> Ext3 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">目前只支持</span> 32,000 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个子目录，而</span> Ext4 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">支持无限数量的子目录。</span></p>  <p>&nbsp;</p>  <p>4. Extents<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">。</span> Ext3 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">采用间接块映射，当操作大文件时，效率极其低下。比如一个</span> 100MB <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">大小的文件，在</span> Ext3 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">中要建立</span> 25,600 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个数据块（每个数据块大小为</span> 4KB<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）的映射表。而</span> Ext4 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">引入了现代文件系统中流行的</span> extents <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">概念，每个</span> extent <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">为一组连续的数据块，上述文件则表示为</span>&#8220;<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">该文件数据保存在接下来的</span> 25,600 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个数据块中</span>&#8221;<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">，提高了不少效率。</span></p>  <p>&nbsp;</p>  <p>5. <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">多块分配。</span> <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">当</span> <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">写入数据到</span> Ext3 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件系统中时，</span>Ext3 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的数据块分配器每次只能分配一个</span> 4KB <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的块，写一个</span> 100MB <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件就要调用</span> 25,600 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">次数据块分配器，而</span> Ext4 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的多块分配器</span>&#8220;multiblock allocator&#8221;<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">（</span>mballoc<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）</span> <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">支持一次调用分配多个数据块。</span></p>  <p>&nbsp;</p>  <p>6. <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">延迟分配。</span> Ext3 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的数据块分配策略是尽快分配，而</span> Ext4 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和其它现代文件操作系统的策略是尽可能地延迟分配，直到文件在</span> cache <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">中写完才开始分配数据块并写入磁盘，这样就能优化整个文件的数据块分配，与前两种特性搭配起来可以显著提升性能。</span></p>  <p>&nbsp;</p>  <p>7. <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">快速</span> fsck<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span> <span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">以前执行</span> fsck <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">第一步就会很慢，因为它要检查所有的</span> inode<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，现在</span> Ext4 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">给每个组的</span> inode <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">表中都添加了一份未使用</span> inode <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的列表，今后</span> fsck Ext4 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件系统就可以跳过它们而只去检查那些在用的</span> inode <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">了。</span></p>  <p>&nbsp;</p>  <p>8. <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">日志校验。</span> <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">日志是最常用的部分，也极易导致磁盘硬件故障，而从损坏的日志中恢复数据会导致更多的数据损坏。</span>Ext4 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的日志校验功能可以很方便地判断日志数据是否损坏，而且它将</span> Ext3 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的两阶段日志机制合并成一个阶段，在增加安全性的同时提高了性能。</span></p>  <p>&nbsp;</p>  <p>9. &#8220;<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">无日志</span>&#8221;<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">（</span>No Journaling<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）模式。</span> <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">日志总归有一些开销，</span>Ext4 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">允许关闭日志，以便某些有特殊需求的用户可以借此提升性能。</span></p>  <p>&nbsp;</p>  <p>10. <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">在线碎片整理。</span> <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">尽管延迟分配、多块分配和</span> extents <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">能有效减少文件系统碎片，但碎片还是不可避免会产生。</span>Ext4 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">支持在线碎片整理，并将提供</span> e4defrag <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">工具进行个别文件或整个文件系统的碎片整理。</span></p>  <p>&nbsp;</p>  <p style="margin-left:0cm;text-indent:0cm;">11. inode <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">相关特性。</span> Ext4 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">支持更大的</span> inode<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，较之</span> Ext3 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">默认的</span> inode <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">大小</span> 128 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">字节，</span>Ext4 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">为了在</span> inode <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">中容纳更多的扩展属性（如纳秒时间戳或</span> inode <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">版本），默认</span> inode <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">大小为</span> 256 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">字节。</span>Ext4 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">还支持快速扩展属性（</span>fast extended attributes<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）和</span> inode <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">保留（</span>inodes reservation<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）。</span></p>  <p>&nbsp;</p>  <p>12. <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">持久预分配（</span>Persistent preallocation<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）。</span> P2P <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">软件为了保证下载文件有足够的空间存放，常常会预先创建一个与所下载文件大小相同的空文件，以免未来的数小时或数天之内磁盘空间不足导致下载失败。</span> Ext4 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">在文件系统层面实现了持久预分配并提供相应的</span> API<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">（</span>libc <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">中的</span> posix_fallocate()<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">），比应用软件自己实现更有效率。</span></p>  <p>&nbsp;</p>  <p>13. <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">默认启用</span> barrier<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span> <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">磁</span> <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">盘上配有内部缓存，以便重新调整批量数据的写操作顺序，优化写入性能，因此文件系统必须在日志数据写入磁盘之后才能写</span> commit <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">记录，若</span> commit <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">记录写入在先，而日志有可能损坏，那么就会影响数据完整性。</span>Ext4 <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">默认启用</span> barrier<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，只有当</span> barrier <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">之前的数据全部写入磁盘，才能写</span> barrier <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">之后的数据。（可通过</span> "mount -o barrier=0" <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">命令禁用该特性。）</span> </p>  <p>&nbsp;</p><img src ="http://www.blogjava.net/xiaomage234/aggbug/397638.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2013-04-10 12:35 <a href="http://www.blogjava.net/xiaomage234/archive/2013/04/10/397638.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>CentOS6.0安装配置</title><link>http://www.blogjava.net/xiaomage234/archive/2013/04/10/397637.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Wed, 10 Apr 2013 04:29:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2013/04/10/397637.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/397637.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2013/04/10/397637.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/397637.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/397637.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: CentOS6.0安装配置1、准备安装1.1 系统简介CentOS 是什么？CentOS是一个基于Red Hat 企业级 Linux&nbsp;提供的可自由使用的源代码企业级的 Linux 发行版本。每个版本的CentOS&nbsp;都会获得七年的支持（通过安全更新方式）。新版本的&nbsp;CentOS&nbsp;每两年发行一次，而每个版本的 CentOS 会定期（大概每六个月）更新一次，以便支...&nbsp;&nbsp;<a href='http://www.blogjava.net/xiaomage234/archive/2013/04/10/397637.html'>阅读全文</a><img src ="http://www.blogjava.net/xiaomage234/aggbug/397637.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2013-04-10 12:29 <a href="http://www.blogjava.net/xiaomage234/archive/2013/04/10/397637.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在CentOS 6.0上通过repo源安装Xen 4.1.1</title><link>http://www.blogjava.net/xiaomage234/archive/2013/04/10/397629.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Wed, 10 Apr 2013 02:46:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2013/04/10/397629.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/397629.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2013/04/10/397629.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/397629.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/397629.html</trackback:ping><description><![CDATA[<p style="margin: 0px 0px 10px; padding: 0px; text-indent: 2em; color: #2a2a2a; font-family: 'Segoe UI', Tahoma, Arial, sans-serif; line-height: 25px; -webkit-text-size-adjust: none; background-color: #f5faff;">2008年 RedHat 收购 Qumranet 以后就一直在家搞他的 KVM，没有对 Xen 做任何升级，RHEL/CentOS 5.5 上默认的 Xen 依旧是很老很老的公元2007年发布的 Xen 3.1.2 版本。更糟糕的是 RedHat 在后续的 RedHat Enterprise Linux 6 里彻底放弃了 Xen. 如果以后想在新版本的 RHEL/CentOS 上用 Xen 的话就需要使用第三方源或者自己动手编译 Xen 源代码。自己编译源代码问题多多，所以没有特殊要求的话，还是建议直接使用第三方源。</p><p style="margin: 0px 0px 10px; padding: 0px; text-indent: 2em; color: #2a2a2a; font-family: 'Segoe UI', Tahoma, Arial, sans-serif; line-height: 25px; -webkit-text-size-adjust: none; background-color: #f5faff;"></p><ol style="margin: 0px; padding: 0px; color: #2a2a2a; font-family: 'Segoe UI', Tahoma, Arial, sans-serif; line-height: 25px; -webkit-text-size-adjust: none; background-color: #f5faff;"><li style="margin: 0px; padding: 0px; list-style: none;">#&nbsp;<a href="http://www.linuxso.com/command/cd.html" target="_blank" style="color: #0841d6; text-decoration: none;"><u>cd</u></a>&nbsp;/etc/yum.repos.d/ &nbsp;&nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">#&nbsp;wget&nbsp;http://www.linux<a href="http://www.linuxso.com/command/id.html" target="_blank" style="color: #0841d6; text-decoration: none;"><u>id</u></a>c.com/repo/GITCO-XEN4.1.1_x86_64.repo &nbsp;&nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">#&nbsp;yum&nbsp;up<a href="http://www.linuxso.com/command/date.html" target="_blank" style="color: #0841d6; text-decoration: none;"><u>date</u></a>&nbsp;&nbsp;&nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">#&nbsp;reboot&nbsp;&nbsp;</li></ol><p style="margin: 0px 0px 10px; padding: 0px; text-indent: 2em; color: #2a2a2a; font-family: 'Segoe UI', Tahoma, Arial, sans-serif; line-height: 25px; -webkit-text-size-adjust: none; background-color: #f5faff;">如果上面的 yum update 没问题的话重启系统就可以了进入 xen 4.1.1 了，如果有问题导致一些依赖需要解决的话可以彻底删除 xen 后重新升级安装：</p><ol style="margin: 0px; padding: 0px; color: #2a2a2a; font-family: 'Segoe UI', Tahoma, Arial, sans-serif; line-height: 25px; -webkit-text-size-adjust: none; background-color: #f5faff;"><li style="margin: 0px; padding: 0px; list-style: none;">#&nbsp;yum&nbsp;groupremove&nbsp;Virtualization &nbsp;&nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">#&nbsp;yum&nbsp;groupinstall&nbsp;Virtualization &nbsp;&nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">#&nbsp;reboot&nbsp;</li></ol><p style="margin: 0px 0px 10px; padding: 0px; text-indent: 2em; color: #2a2a2a; font-family: 'Segoe UI', Tahoma, Arial, sans-serif; line-height: 25px; -webkit-text-size-adjust: none; background-color: #f5faff;">在重启之前最好检查一下 grub 是否配置正确、默认启动是否是 xen.gz-4.1.1：</p><ol style="margin: 0px; padding: 0px; color: #2a2a2a; font-family: 'Segoe UI', Tahoma, Arial, sans-serif; line-height: 25px; -webkit-text-size-adjust: none; background-color: #f5faff;"><li style="margin: 0px; padding: 0px; list-style: none;">#&nbsp;vi&nbsp;/boot/grub/menu.<a href="http://www.linuxso.com/command/ls.html" target="_blank" style="color: #0841d6; text-decoration: none;"><u>ls</u></a>t &nbsp;&nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">... &nbsp;&nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">title&nbsp;CentOS&nbsp;(2.6.18-194.26.1.el5xen) &nbsp;&nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;root&nbsp;(hd0,0) &nbsp;&nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;kernel&nbsp;/xen.gz-4.1.1&nbsp;&nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mo<a href="http://www.linuxso.com/command/du.html" target="_blank" style="color: #0841d6; text-decoration: none;"><u>du</u></a>le&nbsp;/vmlinuz-2.6.18-194.26.1.el5xen&nbsp;ro&nbsp;root=LABEL=/ &nbsp;&nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;module&nbsp;/ini<a href="http://www.linuxso.com/command/tr.html" target="_blank" style="color: #0841d6; text-decoration: none;"><u>tr</u></a>d-2.6.18-194.26.1.el5xen.img &nbsp;&nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">...&nbsp;&nbsp;</li></ol><span style="color: #2a2a2a; font-family: 'Segoe UI', Tahoma, Arial, sans-serif; line-height: 25px; -webkit-text-size-adjust: none; background-color: #f5faff;">http://www.linuxso.com/linuxxitongguanli/7298.html</span><img src ="http://www.blogjava.net/xiaomage234/aggbug/397629.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2013-04-10 10:46 <a href="http://www.blogjava.net/xiaomage234/archive/2013/04/10/397629.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>CentOS6 安装 Xen 4.1.2</title><link>http://www.blogjava.net/xiaomage234/archive/2013/04/10/397626.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Wed, 10 Apr 2013 02:27:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2013/04/10/397626.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/397626.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2013/04/10/397626.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/397626.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/397626.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 系统：CentOS6.0&nbsp; 安装的Xen版本：4.1.2在centos下安装xen不是很顺利，遇到很多问题。安装过程主要参考了以下两个文档：http://wiki.xen.org/xenwiki/RHEL6Xen4Tutorial?action=fullsearch&amp;value=linkto%3A%22RHEL6Xen4Tutorial%22&amp;context=180这个方...&nbsp;&nbsp;<a href='http://www.blogjava.net/xiaomage234/archive/2013/04/10/397626.html'>阅读全文</a><img src ="http://www.blogjava.net/xiaomage234/aggbug/397626.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2013-04-10 10:27 <a href="http://www.blogjava.net/xiaomage234/archive/2013/04/10/397626.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>CentOS 5.5  配置YUM服务器</title><link>http://www.blogjava.net/xiaomage234/archive/2013/04/09/397606.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Tue, 09 Apr 2013 14:35:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2013/04/09/397606.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/397606.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2013/04/09/397606.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/397606.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/397606.html</trackback:ping><description><![CDATA[<div>CentOS 5.5 &nbsp;配置YUM服务器</div><div>目标： 1、建立YUM服务器</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2、配置YUM客户端</div><div>Yum（全称为 Yellow dog Updater, Modified）是一个在Fedora和RedHat以及</div><div>SUSE、CentOS中的Shell前端软件包管理器基于RPM包管理，能够从指定的</div><div>服务器自动下载RPM包并且安装，可以自动处理依赖性关系，并且一次安装</div><div>所有依赖的软体包，无须繁琐地一次次下载、安装。</div><div>IP地址规划:</div><div>&nbsp; &nbsp;YUM服务器&#8212;192.168.1.10</div><div>&nbsp; &nbsp;YUM客户端&#8212;192.168.1.200</div><div>YUM服务器的配置</div><div>&nbsp; &nbsp;一 配置YUM服务器IP地址</div><div>&nbsp; &nbsp; 1 &nbsp;修改配置文件的方法</div><div>&nbsp; &nbsp; &nbsp; a、vim /etc/sysconfig/network-scripts/ifcfg-eth0</div><div>&nbsp;&nbsp;</div><div>&nbsp; &nbsp;b &nbsp;使用setup命令配置IP</div><div>&nbsp; &nbsp;</div><div>&nbsp; &nbsp; &nbsp;2 &nbsp; 配置完IP &nbsp; 地址后，利用service network restart命令重启网络服务</div><div>&nbsp; &nbsp;二 查看YUM服务必需的软件，默认已安装齐全。</div><div>&nbsp; &nbsp; 三 挂载系统安装光盘，然后安装vsftpd软件包。</div><div>&nbsp; &nbsp; &nbsp; 1 &nbsp; mkdir &nbsp; /cdrom</div><div>&nbsp; &nbsp; &nbsp; 2 &nbsp; mount &nbsp; /dev/cdrom &nbsp;/cdrom &nbsp; &nbsp;把光盘挂载到新建的目录／cdrom上。</div><div>&nbsp; &nbsp; &nbsp; 3 &nbsp; cd &nbsp; /cdrom/CentOS &nbsp; &nbsp;切换到有vsftpd 安装包的CentOS目录。 &nbsp; &nbsp; &nbsp; &nbsp; （各个</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;版本的RPM包存放路径不一样）</div><div>&nbsp; &nbsp; 四 在/var/ftp里新建yumservers目录用于存放YUM服务所用到的RPM包及&nbsp;</div><div>&nbsp; &nbsp; &nbsp; 相关文件。</div><div>&nbsp; &nbsp; &nbsp;Mkdir &nbsp; /var/ftp/yumservers</div><div>&nbsp; &nbsp;五 把整个光盘的所有目录和文件拷到/var/ftp/yumservers &nbsp; 里，注意要加上-f &nbsp;-r &nbsp;</div><div>&nbsp; &nbsp; &nbsp;六 查看/var/ftpd/yumservers目录，检查复制是否成功。</div><div>&nbsp; &nbsp;七 安装createrepo软件包，在CentOS 5.0中安装没有依赖，而在CentOS 6.0中&nbsp;</div><div>&nbsp; &nbsp; 安装则有依赖，如果不清楚依赖则可以先连外网后用yum install 安装。</div><div>&nbsp; &nbsp;八 利用repomd.xml生成Server数据库。（各个版本的repomd.xml文件有所不</div><div>同，但是，基本上在repodata目录下都能找到）</div><div>&nbsp; &nbsp;九 最后是启动vsftpd服务和配置防火墙。</div><div>也可以用命令service iptables stop 把防火墙关闭，但不建议如此。</div><div>客户端的配置</div><div>&nbsp; &nbsp;一 配置客户端的IP地址。</div><div>&nbsp; &nbsp;二 备份后修改/etc/yum.repos.d/CentOS-Media.repo &nbsp;重要文件建议备份后修改</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;其中gpgcheck与enabled &nbsp; &nbsp;参数的修改很重要，按默认值则不能成功。</div><div>&nbsp; &nbsp;三 重命名/etc/yum.repos.d/CentOS-Base.repo, 如果少了这一步则会提示错误。</div><div>&nbsp; 四YUM &nbsp;list显示所有的安装程序包</div><div>&nbsp; &nbsp;五 利用yum install 安装软件检验配置是否成功。</div><div>所依赖的软件包<br /><br /><br /><p style="color: #464646; font-family: simsun; background-color: #ffffff;">yum源很好配置，比较简单，一般放到httpd服务器上，通过http提供yum，但是如果只是拷贝Packages目录，虽然可以实现软件安装，但是groupinstall却无法实现。原因是缺少comps-x.xml文件。所以，需要多做几个步骤</p><p style="color: #464646; font-family: simsun; background-color: #ffffff;">1。使用createrepo创建完yum仓库后，找到光盘里面的comps文件，rhel6.1的是xxx-comps-rhel6-Server.xml，位置在Server/repodata下</p><p style="color: #464646; font-family: simsun; background-color: #ffffff;">2。使用createrepo -g 导入组件安装</p><p style="color: #464646; font-family: simsun; background-color: #ffffff;">createrepo -g /mnt/cdrom/Server/repodata/5819e9580b5a81a9eec9e2c6<wbr>e91fc9992a7ccadaa3bcd5ec<wbr>b2e87a8669eefcec-comps-rhel6-Server.xml .</p><p style="color: #464646; font-family: simsun; background-color: #ffffff;">这样就可以实现groupinstall功能</p><p style="color: #464646; font-family: simsun; background-color: #ffffff;">如果系统是中文，那么grouplist出来的组件是中文的，比较不方便。要实现英文显示，可以这么作</p><p style="color: #464646; font-family: simsun; background-color: #ffffff;">LANG= yum grouplist</p></div><img src ="http://www.blogjava.net/xiaomage234/aggbug/397606.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2013-04-09 22:35 <a href="http://www.blogjava.net/xiaomage234/archive/2013/04/09/397606.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Centos6.0 yum源配置</title><link>http://www.blogjava.net/xiaomage234/archive/2013/04/09/397605.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Tue, 09 Apr 2013 14:34:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2013/04/09/397605.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/397605.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2013/04/09/397605.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/397605.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/397605.html</trackback:ping><description><![CDATA[<p style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;">在CentOS下运行yum install flash-plugin或yum install mplayer的时候，提示库里没有找到这个软件？为什么会这样？因为<span style="color: #0000f0;">CentOS是RHEL编译过来的，去掉了所有关于版权问题的东西。因此，在没有使用第三方软件库的情况下，很多软件无法用yum install来直接安装</span>。</p><p style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;">&nbsp;EPEL(Extra Packages for Enterprise Linux)软件库提供为RHEL系列(4.x、5.x、6.x等等)重新编译的Fedora组件。这个软件库在不替换系统组件方面下了功夫。在某些情况下它尝试直接针对CentOS兼容性的问题，但坚决否定软件库间的兼容性是目标之一。当它与其它第三方软件库混合使用时，问题可能会出现。故此，当你使用EPEL时，尤其是当你亦会运用其它件库的组件时，请确保你使用yum的Priorities插件。<br /></p><p style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;">RPMForge库现在已经拥有超过10000种的CentOS的软件包，被CentOS社区认为是最安全也是最稳定的一个第三方软件库。</p><p style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="color: #f00000;"><strong>一、配置基本源</strong></span><br /></p><p style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="color: #000000;"><strong>安装CentOS yum源优先级插件yum-priorities</strong></span><br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<span style="color: #0000f0;">yum install yum-priorities</span>&nbsp;&nbsp; #输入y安装</p><p style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="color: #0000ff;"><span style="color: #000000;"><strong>设置CentOS默认yum源的优先级为最高</strong></span><br /></span>系统运维&nbsp;&nbsp;<a href="http://www.osyunwei.com/" target="_blank" style="color: #6a3906; text-decoration: none;">www.osyunwei.com</a>&nbsp; 温馨提醒：qihang01原创内容&#169;版权所有,转载请注明出处及原文链接<br />&nbsp;&nbsp;&nbsp; &nbsp;cd&nbsp; /etc/yum.repos.d/&nbsp;&nbsp; #进入yum源目录<br />&nbsp;&nbsp; &nbsp; vi CentOS-Base.repo&nbsp;&nbsp;&nbsp;&nbsp;#在[base]、[updates]、[extras]组下面添加priority=1，在[centosplus]、[contrib]组下面添加priority=2<br /></p><div style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;"><div><p>点击(<span style="color: red;">此处</span>)折叠或打开</p></div><div id="code141"><ol start="1" style="margin: 0px 1px 0px 0px; padding-left: 40px;"><li>################################################################</li><li>[base]</li><li>name=CentOS-$releasever - Base</li><li>mirrorlist=http://mirrorlist.centos.org/?release=$releasever&amp;arch=$basearch&amp;repo=os</li><li>#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/</li><li>gpgcheck=1</li><li>gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6</li><li><span style="color: #0000f0;">priority=1</span></li><li><br /></li><li>[updates]</li><li>name=CentOS-$releasever - Updates</li><li>mirrorlist=http://mirrorlist.centos.org/?release=$releasever&amp;arch=$basearch&amp;repo=updates</li><li>#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/</li><li>gpgcheck=1</li><li>gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6</li><li><span style="color: #0000f0;">priority=1</span></li><li><br /></li><li>[extras]</li><li>name=CentOS-$releasever - Extras</li><li>mirrorlist=http://mirrorlist.centos.org/?release=$releasever&amp;arch=$basearch&amp;repo=extras</li><li>#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/</li><li>gpgcheck=1</li><li>gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6</li><li><span style="color: #0000f0;">priority=1</span></li><li><br /></li><li>[centosplus]</li><li>name=CentOS-$releasever - Plus</li><li>mirrorlist=http://mirrorlist.centos.org/?release=$releasever&amp;arch=$basearch&amp;repo=centosplus</li><li>#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/</li><li>gpgcheck=1</li><li>enabled=0</li><li>gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6</li><li><span style="color: #0000f0;">priority=2</span></li><li><br /></li><li>[contrib]</li><li>name=CentOS-$releasever - Contrib</li><li>mirrorlist=http://mirrorlist.centos.org/?release=$releasever&amp;arch=$basearch&amp;repo=contrib</li><li>#baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/</li><li>gpgcheck=1</li><li>enabled=0</li><li>gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6</li><li><span style="color: #0000f0;">priority=2</span></li></ol></div></div><p style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="color: #f00000;"><strong>二、EPEL(Extra Packages for Enterprise Linux)</strong></span>（<span style="color: #0000f0;">http://fedoraproject.org/wiki/EPEL</span>）<br /></p><p style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;">添加方法： 打开终端，输入<br /><br />32位系统：<br />[root@CentOS ~]#<span style="color: #0000f0;">rpm -ivh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-7.noarch.rpm</span>&nbsp;(这里需要注意随着fedora系统的更新-6-7是会变的当提示你不能下载时就出网站看看)<br /><br />64位系统：<br />[root@CentOS ~]#<span style="color: #0000f0;">rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-7.noarch.rpm</span><br /><br />然后导入公钥(不导入的话会出错)<br /><span style="color: #0000f0;">rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6</span></p><p style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;">在<span style="color: #0000f0;">/etc/yum.repos.d/epel.repo</span>&nbsp;里设置epel源的优先级为priority=11<br /></p><div style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;"><div><p>点击(<span style="color: red;">此处</span>)折叠或打开</p></div><div id="code279"><ol start="1" style="margin: 0px 1px 0px 0px; padding-left: 40px;"><li>[epel]</li><li>name=Extra Packages for Enterprise Linux 6 - $basearch</li><li>#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch</li><li>mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&amp;arch=$basearch</li><li>failovermethod=priority</li><li>enabled=1</li><li>gpgcheck=1</li><li>gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6</li><li><span style="color: #0000f0;">priority=11</span></li></ol></div></div><span style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;">最后执行</span><span style="font-family: Arial; line-height: 26px; background-color: #ffffff; color: #0000f0;">yum update</span><span style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;">即可。</span><p style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;"><strong><span style="color: #f00000;">三、下载与安装相应rpmforge的rpm文件包</span></strong></p><p style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;">1、下载rpmforge的rpm文件包（http://wiki.centos.org/AdditionalResources/Repositories/RPMForge）</p><p style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;">32位系统</p><p style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;">[root@CentOS ~]#&nbsp;<span style="color: #0000f0;">wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm</span></p><p style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;">64位系统</p><p style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;">[root@CentOS ~]# wget&nbsp;<span style="color: #0000f0;">http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm</span></p><p style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;">2、安装DAG的PGP Key</p><p style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;">[root@CentOS ~]#&nbsp;<span style="color: #0000f0;">rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt</span></p><p style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;">3、验证rpmforge的rpm文件包</p><span style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;">[root@CentOS ~]#&nbsp;</span><span style="font-family: Arial; line-height: 26px; background-color: #ffffff; color: #0000f0;">rpm -K rpmforge-release-0.5.2-2.el6.rf.*.rpm</span><p style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;">如果报XXX not an rpm package的错，查看是否wget下载的包不完整，包的大小是12K&nbsp;<br /></p><p style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;">4、安装rpmforge的rpm文件包&nbsp;<br /></p><p style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;">[root@CentOS ~]#&nbsp;<span style="color: #0000f0;">rpm -ivh rpmforge-release-0.5.2-2.el6.rf.*.rpm&nbsp;</span><br /></p><p style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;">5、设置<span style="color: #0000f0;">/etc/yum.repos.d/rpmforge.repo</span>文件中源的级别，就是添加priority=12这句<br /></p><div style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;"><div><p>点击(<span style="color: red;">此处</span>)折叠或打开</p></div><div id="code69"><ol start="1" style="margin: 0px 1px 0px 0px; padding-left: 40px;"><li>### Name: RPMforge RPM Repository for RHEL 6 - dag</li><li>### URL: http://rpmforge.net/</li><li>[rpmforge]</li><li>name = RHEL $releasever - RPMforge.net - dag</li><li>baseurl = http://apt.sw.be/redhat/el6/en/$basearch/rpmforge</li><li>mirrorlist = http://apt.sw.be/redhat/el6/en/mirrors-rpmforge</li><li>#mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge</li><li>enabled = 1</li><li>protect = 0</li><li>gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag</li><li>gpgcheck = 1</li><li><span style="color: #0000f0;">priority=12</span></li></ol></div></div><p style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;"><strong><span style="color: #f00000;">四、<span id=".E5.AE.9A.E4.B9.89yum.E7.9A.84.E9.9D.9E.E5.AE.98.E6.96.B9.E5.BA.93">定义yum的非官方库</span></span></strong></p><p style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;">在服务器构建的过程中，我们将要用到的一些工具不存在于CentOS中yum的官方库中，所以需要定义yum的非官方库文件，让一些必需的工具通过yum也能够安装。&nbsp;<br /></p><span style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;">[root@sample ~]#&nbsp;</span><span style="font-family: Arial; line-height: 26px; background-color: #ffffff; color: #0000f0;">vi /etc/yum.repos.d/dag.repo</span><span style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;">　 &#8592; 建立dag.repo，定义非官方库</span><p style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;">点击(<span style="color: red;">此处</span>)折叠或打开</p><div style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;"><div id="code184"><ol start="1" style="margin: 0px 1px 0px 0px; padding-left: 40px;"><li>[dag]</li><li>name=Dag RPM Repository for Red Hat Enterprise Linux</li><li>baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag</li><li>gpgcheck=1</li><li>enabled=1</li></ol></div></div><span style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;">[root@sample ~]#&nbsp;</span><span style="font-family: Arial; line-height: 26px; background-color: #ffffff; color: #0000f0;">rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.tx</span><span style="color: #362e2b; font-family: Arial; line-height: 26px; background-color: #ffffff;">t　 &#8592; 导入非官方库的GPG</span><img src ="http://www.blogjava.net/xiaomage234/aggbug/397605.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2013-04-09 22:34 <a href="http://www.blogjava.net/xiaomage234/archive/2013/04/09/397605.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>