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

<channel>
	<title>P.Linux Laboratory &#187; 操作系统</title>
	<atom:link href="http://www.penglixun.com/category/tech/system/feed" rel="self" type="application/rss+xml" />
	<link>http://www.penglixun.com</link>
	<description>MySQL DBA &#38; Linux SA</description>
	<lastBuildDate>Sun, 22 Jan 2012 16:34:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Linux Cache 机制探究</title>
		<link>http://www.penglixun.com/tech/system/linux_cache_discovery.html</link>
		<comments>http://www.penglixun.com/tech/system/linux_cache_discovery.html#comments</comments>
		<pubDate>Fri, 27 Aug 2010 04:56:31 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[操作系统]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Radix Tree]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/?p=1160</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明网址: http://www.penglixun.com/tech/system/linux_cache_discovery.html 经过研究了下Linux相关代码，把对Lin... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br>网址: http://www.penglixun.com/tech/system/linux_cache_discovery.html </p>
<p></span>经过研究了下Linux相关代码，把对Linux Cache实现的方式做一些总结。<br />
相关源码主要在：<br />
./fs/fscache/cache.c    Cache实现的代码<br />
./mm/slab.c                                     SLAB管理器代码<br />
./mm/swap.c                                   缓存替换算法代码<br />
./mm/mmap.c             内存管理器代码<br />
./mm/mempool.c       内存池实现代码</p>
<h2>0. 预备：Linux内存管理基础</h2>
<p>创建进程fork()、程序载入execve()、映射文件mmap()、动态内存分配malloc()/brk()等进程相关操作都需要分配内存给进程。不过这时进程申请和获得的还不是实际内存，而是虚拟内存，准确的说是“内存区域”。Linux除了内核以外，App都不能直接使用内存，因为Linux采用Memory Map的管理方式，App拿到的全部是内核映射自物理内存的一块虚拟内存。malloc分配很少会失败，因为malloc只是通知内存App需要内存，在没有正式使用之前，这段内存其实只在真正开始使用的时候才分配，所以malloc成功了并不代表使用的时候就真的可以拿到这么多内存。据说Google的tcmalloc改进了这一点。</p>
<p>进程对内存区域的分配最终多会归结到do_mmap()函数上来（brk调用被单独以系统调用实现，不用do_mmap()）。内核使用do_mmap()函数创建一个新的线性地址区间，如果创建的地址区间和一个已经存在的地址区间相邻，并且它们具有相同的访问权限的话，那么两个区间将合并为一个。如果不能合并，那么就确实需要创建一个新的VMA了。但无论哪种情况， do_mmap()函数都会将一个地址区间加入到进程的地址空间中，无论是扩展已存在的内存区域还是创建一个新的区域。同样释放一个内存区域使用函数do_ummap()，它会销毁对应的内存区域。</p>
<p>另一个重要的部分是SLAB分配器。在Linux中以页为最小单位分配内存对于内核管理系统物理内存来说是比较方便的，但内核自身最常使用的内存却往往是很小（远远小于一页）的内存块，因为大都是一些描述符。一个整页中可以聚集多个这种这些小块内存，如果一样按页分配，那么会被频繁的创建/销毁，开始是非常大的。</p>
<p>为了满足内核对这种小内存块的需要，Linux系统采用了SLAB分配器。Slab分配器的实现相当复杂，但原理不难，其核心思想就是Memory Pool。内存片段（小块内存）被看作对象，当被使用完后，并不直接释放而是被缓存到Memory Pool里，留做下次使用，这就避免了频繁创建与销毁对象所带来的额外负载。</p>
<p>Slab技术不但避免了内存内部分片带来的不便，而且可以很好利用硬件缓存提高访问速度。但Slab仍然是建立在页面基础之上，Slab将页面分成众多小内存块以供分配，Slab中的对象分配和销毁使用kmem_cache_alloc与kmem_cache_free。</p>
<p>关于SALB分配器有一份资料：<a href="http://lsec.cc.ac.cn/~tengfei/doc/ldd3/ch08s02.html">http://lsec.cc.ac.cn/~tengfei/doc/ldd3/ch08s02.html</a><br />
关于内存管理的两份资料：<a href="http://lsec.cc.ac.cn/~tengfei/doc/ldd3/ch15.html">http://lsec.cc.ac.cn/~tengfei/doc/ldd3/ch15.html</a><br />
<a href="http://memorymyann.javaeye.com/blog/193061">http://memorymyann.javaeye.com/blog/193061</a></p>
<h2>1. Linux Cache的体系</h2>
<p>在 Linux 中，当App需要读取Disk文件中的数据时，Linux先分配一些内存，将数据从Disk读入到这些内存中，然后再将数据传给App。当需要往文件中写数据时，Linux先分配内存接收用户数据，然后再将数据从内存写到Disk上。Linux Cache  管理指的就是对这些由Linux分配，并用来存储文件数据的内存的管理。</p>
<p>下图描述了 Linux 中文件 Cache 管理与内存管理以及文件系统的关系。从图中可以看到，在 Linux 中，具体的文件系统，如  ext2/ext3/ext4 等，负责在文件  Cache和存储设备之间交换数据，位于具体文件系统之上的虚拟文件系统VFS负责在应用程序和文件 Cache 之间通过 read/write  等接口交换数据，而内存管理系统负责文件 Cache 的分配和回收，同时虚拟内存管理系统(VMM)则允许应用程序和文件 Cache 之间通过  memory map的方式交换数据，FS Cache底层通过SLAB管理器来管理内存。</p>
<p style="text-align: left;"><a title="Linux Cache体系 1" href="http://www.yupoo.com/photos/plinux/77106238/"><img class="aligncenter" src="http://pic.yupoo.com/plinux/AqzqMw23/eSwSS.jpg" border="0" alt="Linux Cache体系 1" width="567" height="484" /></a><br />
下图则非常清晰的描述了Cache所在的位置，磁盘与VFS之间的纽带。</p>
<p style="text-align: center;"><a title="Linux Cache体系 2" href="http://www.yupoo.com/photos/plinux/77106302/"><img class="aligncenter" src="http://pic.yupoo.com/plinux/AqzrM4oI/JfuYd.jpg" border="0" alt="Linux Cache体系 2" width="313" height="432" /></a></p>
<h2 style="text-align: left;">2. Linux Cache的结构</h2>
<p style="text-align: left;">在 Linux 中，文件 Cache 分为两层，一是 Page Cache，另一个 Buffer Cache，每一个 Page  Cache 包含若干 Buffer Cache。内存管理系统和 VFS 只与 Page Cache 交互，内存管理系统负责维护每项 Page  Cache 的分配和回收，同时在使用 memory map 方式访问时负责建立映射；VFS 负责 Page Cache  与用户空间的数据交换。而具体文件系统则一般只与 Buffer Cache 交互，它们负责在外围存储设备和 Buffer Cache  之间交换数据。读缓存以Page Cache为单位，每次读取若干个Page Cache，回写磁盘以Buffer Cache为单位，每次回写若干个Buffer Cache。<br />
Page Cache、Buffer Cache、文件以及磁盘之间的关系如下图所示。</p>
<p style="text-align: left;">
<p style="text-align: center;"><a title="Linux Cache实现" href="http://www.yupoo.com/photos/plinux/77106240/"><img class="aligncenter" src="http://pic.yupoo.com/plinux/AqzqMUfN/K05Tc.jpg" border="0" alt="Linux Cache实现" width="389" height="268" /></a></p>
<p style="text-align: left;">Page 结构和 buffer_head  数据结构的关系如下图所示。Page指向一组Buffer的头指针，Buffer的头指针指向磁盘块。在这两个图中，假定了 Page 的大小是 4K，磁盘块的大小是 1K。</p>
<p style="text-align: center;"><a title="Page Cache结构" href="http://www.yupoo.com/photos/plinux/77106241/"><img class="aligncenter" src="http://pic.yupoo.com/plinux/AqzqMRAZ/4YDuW.jpg" border="0" alt="Page Cache结构" width="373" height="258" /></a></p>
<p>在 Linux 内核中，文件的每个数据块最多只能对应一个 Page Cache  项，它通过两个数据结构来管理这些 Cache 项，一个是 Radix Tree，另一个是双向链表。Radix Tree 是一种搜索树，Linux  内核利用这个数据结构来通过文件内偏移快速定位 Cache 项，图 4 是 radix tree的一个示意图，该 radix tree  的分叉为4(22)，树高为4，用来快速定位8位文件内偏移。Linux(2.6.7) 内核中的分叉为 64(26)，树高为 6(64位系统)或者  11(32位系统)，用来快速定位 32 位或者 64 位偏移，Radix tree 中的每一个到叶子节点的路径上的Key所拼接起来的字串都是一个地址，指向文件内相应偏移所对应的Cache项。</p>
<p style="text-align: center;"><a title="Page Cache使用的Radix Tree 1" href="http://www.yupoo.com/photos/plinux/77106242/"><img src="http://pic.yupoo.com/plinux/AqzqMTB3/tnoPA.gif" border="0" alt="Page Cache使用的Radix Tree 1" width="521" height="362" /></a></p>
<p>查看Page Cache的核心数据结构struct address_space就可以看到上述结构（略去了无关结构）：</p>

<div class="wp_codebox"><table><tr id="p11604"><td class="code" id="p1160code4"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">struct</span> address_space  <span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">struct</span> inode             <span style="color: #000040;">*</span>host<span style="color: #008080;">;</span>              <span style="color: #ff0000; font-style: italic;">/* owner: inode, block_device */</span>
<span style="color: #0000ff;">struct</span> radix_tree_root      page_tree<span style="color: #008080;">;</span>         <span style="color: #ff0000; font-style: italic;">/* radix tree of all pages */</span>
<span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">long</span>           nrpages<span style="color: #008080;">;</span>  <span style="color: #ff0000; font-style: italic;">/* number of total pages */</span>
<span style="color: #0000ff;">struct</span> address_space       <span style="color: #000040;">*</span>assoc_mapping<span style="color: #008080;">;</span>      <span style="color: #ff0000; font-style: italic;">/* ditto */</span>
......
<span style="color: #008000;">&#125;</span> __attribute__<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>aligned<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">long</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></td></tr></table></div>

<p style="text-align: left;">下面是一个Radix Tree实例：</p>
<p style="text-align: center;"><a title="Page Cache使用的Radix Tree 2" href="http://www.yupoo.com/photos/plinux/77106308/"><img class="aligncenter" src="http://pic.yupoo.com/plinux/AqzslYCb/3D95i.jpg" border="0" alt="Page Cache使用的Radix Tree 2" width="442" height="423" /></a></p>
<p>另一个数据结构是双向链表，Linux内核为每一片物理内存区域(zone)  维护active_list和inactive_list两个双向链表，这两个list主要用来实现物理内存的回收。这两个链表上除了文件Cache之 外，还包括其它匿名(Anonymous)内存，如进程堆栈等。</p>
<p style="text-align: center;"><a title="Linux Cache 置换算法" href="http://www.yupoo.com/photos/plinux/77107061/"><img class="aligncenter" src="http://pic.yupoo.com/plinux/AqzJSDWK/cc9PP.png" border="0" alt="Linux Cache 置换算法" width="547" height="243" /></a></p>
<p style="text-align: left;">相关数据结构如下：</p>

<div class="wp_codebox"><table><tr id="p11605"><td class="code" id="p1160code5"><pre class="cpp" style="font-family:monospace;">truct page<span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">struct</span> list_head list<span style="color: #008080;">;</span>   <span style="color: #666666;">//通过使用它进入下面的数据结构free_area_struct结构中的双向链队列</span>
    <span style="color: #0000ff;">struct</span> address_space <span style="color: #000040;">*</span> mapping<span style="color: #008080;">;</span>   <span style="color: #666666;">//用于内存交换的数据结构</span>
    <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">long</span> index<span style="color: #008080;">;</span><span style="color: #666666;">//当页面进入交换文件后</span>
    <span style="color: #0000ff;">struct</span> page <span style="color: #000040;">*</span>next_hash<span style="color: #008080;">;</span> <span style="color: #666666;">//自身的指针，这样就可以链接成一个链表</span>
    atomic t count<span style="color: #008080;">;</span> <span style="color: #666666;">//用于页面交换的计数,若页面为空闲则为0，分配就赋值1，没建立或恢复一次映射就加1，断开映射就减一</span>
    <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">long</span> flags<span style="color: #008080;">;</span><span style="color: #666666;">//反应页面各种状态，例如活跃，不活跃脏，不活跃干净，空闲</span>
   <span style="color: #0000ff;">struct</span> list_head lru<span style="color: #008080;">;</span>
   <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">long</span> age<span style="color: #008080;">;</span> <span style="color: #666666;">//表示页面寿命</span>
   wait_queue_head_t wait<span style="color: #008080;">;</span>
   <span style="color: #0000ff;">struct</span> page <span style="color: #000040;">**</span> pprev_hash<span style="color: #008080;">;</span>
   <span style="color: #0000ff;">struct</span> buffer_head <span style="color: #000040;">*</span> buffers<span style="color: #008080;">;</span>
   <span style="color: #0000ff;">void</span> <span style="color: #000040;">*</span> <span style="color: #0000ff;">virtual</span>
   <span style="color: #0000ff;">struct</span> zone_struct <span style="color: #000040;">*</span> zone<span style="color: #008080;">;</span> <span style="color: #666666;">//指向所属的管理区</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #0000ff;">typedef</span> <span style="color: #0000ff;">struct</span> free_area_struct <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">struct</span> list_head free_list<span style="color: #008080;">;</span>   <span style="color: #666666;">//linux 中通用的双向链队列</span>
    <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> <span style="color: #000040;">*</span> map<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span> free_area_t<span style="color: #008080;">;</span>
<span style="color: #0000ff;">typedef</span> <span style="color: #0000ff;">struct</span> zone_struct<span style="color: #008000;">&#123;</span>
    spinlock_t        lock<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">long</span> offset<span style="color: #008080;">;</span>  <span style="color: #666666;">//表示该管理区在mem-map数组中，起始的页号</span>
    <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">long</span> <span style="color: #0000dd;">free</span> pages<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">long</span> inactive_clean_pages<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">long</span> inactive_dirty_pages<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">unsigned</span> pages_min, pages_low, pages_high<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">struct</span> list_head inactive_clean_list<span style="color: #008080;">;</span>   <span style="color: #666666;">//用于页面交换的队列，基于linux页面交换的机制。这里存贮的是不活动“干净”页面</span>
    free_area_t free_area<span style="color: #008000;">&#91;</span>MAX_ORDER<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span> <span style="color: #666666;">//一组“空闲区间”队列，free_area_t定义在上面，其中空闲下标表示的是页面大小，例如：数组第一个元素0号，表示所有区间大小为2的 0次方的页面链接成的双向队列，1号表示所有2的1次方页面链接链接成的双向队列，2号表示所有2的2次方页面链接成的队列，其中要求是这些页面地址连续</span>
    <span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span> name<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">long</span> size<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">struct</span> pglist_data <span style="color: #000040;">*</span> zone_pgdat<span style="color: #008080;">;</span>   <span style="color: #666666;">//用于指向它所属的存贮节点，及下面的数据结构</span>
    <span style="color: #0000ff;">unsigned</span>  <span style="color: #0000ff;">long</span>  zone_start_paddr<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">unsigned</span>  <span style="color: #0000ff;">long</span>    zone_start_mapnr<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">struct</span> page <span style="color: #000040;">*</span> zone_mem_map<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span> zone_t<span style="color: #008080;">;</span></pre></td></tr></table></div>

<h2 style="text-align: left;">3. Cache预读与换出</h2>
<p style="text-align: left;">Linux  内核中文件预读算法的具体过程是这样的：<br />
对于每个文件的第一个读请求，系统读入所请求的页面并读入紧随其后的少数几个页面(不少于一个页面，通常是三个页 面)，这时的预读称为同步预读。对于第二次读请求，如果所读页面不在Cache中，即不在前次预读的group中，则表明文件访问不是顺序访问，系统继续 采用同步预读；如果所读页面在Cache中，则表明前次预读命中，操作系统把预读group扩大一倍，并让底层文件系统读入group中剩下尚不在  Cache中的文件数据块，这时的预读称为异步预读。无论第二次读请求是否命中，系统都要更新当前预读group的大小。<br />
此外，系统中定义了一个  window，它包括前一次预读的group和本次预读的group。任何接下来的读请求都会处于两种情况之一：<br />
第一种情况是所请求的页面处于预读  window中，这时继续进行异步预读并更新相应的window和group；<br />
第二种情况是所请求的页面处于预读window之外，这时系统就要进行同步 预读并重置相应的window和group。<br />
下图是Linux内核预读机制的一个示意图，其中a是某次读操作之前的情况，b是读操作所请求页面不在  window中的情况，而c是读操作所请求页面在window中的情况。</p>
<p style="text-align: center;"><a title="Cache预读算法" href="http://www.yupoo.com/photos/plinux/77106243/"><img class="aligncenter" src="http://pic.yupoo.com/plinux/AqzqN7jG/EEuVU.gif" border="0" alt="Cache预读算法" width="494" height="298" /></a></p>
<p>Linux内核中文件Cache替换的具体过程是这样的：刚刚分配的Cache项链入到inactive_list头部，并将其状态设置为active，当内存不够需要回收Cache时，系统首先从尾部开始反向扫描  active_list并将状态不是referenced的项链入到inactive_list的头部，然后系统反向扫描inactive_list，如果所扫描的项的处于合适的状态就回收该项，直到回收了足够数目的Cache项。其中Active_list的含义是热访问数据，及多次被访问的，inactive_list是冷访问数据，表示尚未被访问的。如果数据被访问了，Page会被打上一个Refrence标记，如果Page没有被访问过，则打上Unrefrence标记。这些处理在swap.c中可以找到。<br />
下图也描述了这个过程。</p>
<p style="text-align: center;"><a title="Linux Cache 置换算法" href="http://www.yupoo.com/photos/plinux/77107061/"><img class="aligncenter" src="http://pic.yupoo.com/plinux/AqzJSDWK/cc9PP.png" border="0" alt="Linux Cache 置换算法" width="547" height="243" /></a></p>
<p>下面的代码描述了一个Page被访问它的标记为变化：</p>

<div class="wp_codebox"><table><tr id="p11606"><td class="code" id="p1160code6"><pre class="cpp" style="font-family:monospace;"><span style="color: #000040;">*</span>
 <span style="color: #000040;">*</span> Mark a page as having seen activity.
 <span style="color: #000040;">*</span>
 <span style="color: #000040;">*</span> inactive,unreferenced        <span style="color: #000040;">-</span><span style="color: #000040;">&amp;</span>gt<span style="color: #008080;">;</span>      inactive,referenced
 <span style="color: #000040;">*</span> inactive,referenced          <span style="color: #000040;">-</span><span style="color: #000040;">&amp;</span>gt<span style="color: #008080;">;</span>      active,unreferenced
 <span style="color: #000040;">*</span> active,unreferenced          <span style="color: #000040;">-</span><span style="color: #000040;">&amp;</span>gt<span style="color: #008080;">;</span>      active,referenced
 <span style="color: #000040;">*/</span>
<span style="color: #0000ff;">void</span> mark_page_accessed<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">struct</span> page <span style="color: #000040;">*</span>page<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #000040;">!</span>PageActive<span style="color: #008000;">&#40;</span>page<span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span><span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span> <span style="color: #000040;">!</span>PageUnevictable<span style="color: #008000;">&#40;</span>page<span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span><span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span>
                        PageReferenced<span style="color: #008000;">&#40;</span>page<span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span><span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span> PageLRU<span style="color: #008000;">&#40;</span>page<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
                activate_page<span style="color: #008000;">&#40;</span>page<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
                ClearPageReferenced<span style="color: #008000;">&#40;</span>page<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        <span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #000040;">!</span>PageReferenced<span style="color: #008000;">&#40;</span>page<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
                SetPageReferenced<span style="color: #008000;">&#40;</span>page<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>参考文章：<br />
<a href="http://lsec.cc.ac.cn/~tengfei/doc/ldd3/">http://lsec.cc.ac.cn/~tengfei/doc/ldd3/</a><br />
<a href="http://memorymyann.javaeye.com/blog/193061">http://memorymyann.javaeye.com/blog/193061</a><br />
<a href="http://www.cublog.cn/u/20047/showart.php?id=121850">http://www.cublog.cn/u/20047/showart.php?id=121850</a><br />
<a href="http://blog.chinaunix.net/u2/74194/showart_1089736.html">http://blog.chinaunix.net/u2/74194/showart_1089736.html</a><br />
关于内存管理，Linux有一个网页：<a href="http://linux-mm.org/">http://linux-mm.org/</a></p><h2  class="related_post_title">类似的文章</h2><ul class="related_post"><li>2009年12月14日 -- <a href="http://www.penglixun.com/tech/system/buffer_and_cache_diff.html" title="Buffer与Cache">Buffer与Cache</a> (1)</li><li>2009年10月20日 -- <a href="http://www.penglixun.com/tech/system/manual_free_linux_memory.html" title="[转]手工释放Linux内存——/proc/sys/vm/drop_caches ">[转]手工释放Linux内存——/proc/sys/vm/drop_caches </a> (0)</li><li>2012年01月23日 -- <a href="http://www.penglixun.com/tech/database/case_about_innodb_faster_than_oracle.html" title="一个InnoDB性能超过Oracle的调优Case">一个InnoDB性能超过Oracle的调优Case</a> (1)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/tech/system/linux_cache_discovery.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Load和CPU利用率是如何算出来的</title>
		<link>http://www.penglixun.com/tech/system/how_to_calc_load_cpu.html</link>
		<comments>http://www.penglixun.com/tech/system/how_to_calc_load_cpu.html#comments</comments>
		<pubDate>Tue, 10 Aug 2010 09:19:50 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[操作系统]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Load]]></category>
		<category><![CDATA[top]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/?p=1158</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明网址: http://www.penglixun.com/tech/system/how_to_calc_load_cpu.html 相信很多人都对Linux中top命令里“load... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br>网址: http://www.penglixun.com/tech/system/how_to_calc_load_cpu.html </p>
<p></span>相信很多人都对Linux中top命令里“<strong>load average</strong>”这一栏困惑过，到底什么是Load，Load代表了什么含义，Load高会有什么后果？“<strong>%CPU</strong>”这一栏为什么会超过100%，它是如何计算的？<br />
带着这些问题，我们通过一些测试，来探索下其中的不解之处。</p>
<p>首先，我们通过实验来大概确定其计算方式：<br />
测试服务器：4核Xeon处理器<br />
测试软件：MySQL 5.1.40<br />
服务器上除了MySQL没有运行其他任何非系统自带软件。因为MySQL只能单线程运行单条<acronym title="Structured Query Language">SQL</acronym>，所以可以很好的通过增加查询并发来控制使用的CPU核数。</p>
<p>空载时，top的信息为：</p>
<blockquote><p>top &#8211; 14:51:47 up 35 days,  4:43,  1 user,  load average: 0.00, 0.00, 0.00<br />
Tasks:  76 total,   1 running,  75 sleeping,   0 stopped,   0 zombie<br />
Cpu(s):  0.0%us,  0.0%sy,  0.0%ni, 99.5%id,  0.1%wa,  0.2%hi,  0.2%si,  0.0%st</p></blockquote>
<p>在数据库中启动一个大查询：</p>
<blockquote><p>top &#8211; 15:28:09 up 35 days,  5:19,  3 users,  load average: 0.99, 0.92, 0.67<br />
Tasks:  80 total,   1 running,  79 sleeping,   0 stopped,   0 zombie<br />
Cpu0  :  0.0%us,  0.0%sy,  0.0%ni, 96.3%id,  0.0%wa,  1.3%hi,  2.3%si,  0.0%st<br />
Cpu1  :  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st<br />
Cpu2  : 98.7%us,  1.3%sy,  0.0%ni,  0.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st<br />
Cpu3  :  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st</p></blockquote>
<p>同时可以看到%CPU也是在100%</p>
<blockquote><p>PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND<br />
877 mysql     15   0  308m 137m 4644 S 99.9  6.8  15:13.28 mysqld</p></blockquote>
<p>然后开启第二个大查询，不久就可以看到top信息的变化，Load到了2：</p>
<blockquote><p>top &#8211; 15:36:44 up 35 days,  5:28,  3 users,  load average: 1.99, 1.62, 1.08<br />
Tasks:  80 total,   1 running,  79 sleeping,   0 stopped,   0 zombie<br />
Cpu0  :  0.0%us,  0.0%sy,  0.0%ni, 97.7%id,  0.0%wa,  1.0%hi,  1.3%si,  0.0%st<br />
Cpu1  : 99.0%us,  1.0%sy,  0.0%ni,  0.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st<br />
Cpu2  :  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st<br />
Cpu3  : 99.0%us,  1.0%sy,  0.0%ni,  0.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st</p></blockquote>
<p>也可以观察到%CPU增加到了200%：</p>
<blockquote><p>PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND<br />
877 mysql     15   0  312m 141m 4644 S 199.8  7.0  22:31.27 mysqld</p></blockquote>
<p>由此可以简单的做出如下临时结论：<br />
<strong>1. %CPU是由每个核的CPU占用律之和算出来的。</strong><br />
<strong>2. load跟执行的任务数有关</strong><br />
不过要想准确的知道其含义，还是必须从源码入手。<br />
<span id="more-1158"></span><br />
</br></p>
<h1>CPU利用率的计算方法</h1>
<p>下载busybox的源码，在procps目录下有top.c的源码，查看第293行附近（1.17.1版），可以看到</p>

<div class="wp_codebox"><table><tr id="p115813"><td class="code" id="p1158code13"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>prev_hist_count<span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">do</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>prev_hist<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span>.<span style="color: #007788;">pid</span> <span style="color: #000080;">==</span> pid<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
                cur<span style="color: #000040;">-</span><span style="color: #000040;">&amp;</span>gt<span style="color: #008080;">;</span>pcpu <span style="color: #000080;">=</span> cur<span style="color: #000040;">-</span><span style="color: #000040;">&amp;</span>gt<span style="color: #008080;">;</span>ticks <span style="color: #000040;">-</span> prev_hist<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span>.<span style="color: #007788;">ticks</span><span style="color: #008080;">;</span>
                total_pcpu <span style="color: #000040;">+</span><span style="color: #000080;">=</span> cur<span style="color: #000040;">-</span><span style="color: #000040;">&amp;</span>gt<span style="color: #008080;">;</span>pcpu<span style="color: #008080;">;</span>
                <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
        <span style="color: #008000;">&#125;</span>
        i <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>i<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">%</span> prev_hist_count<span style="color: #008080;">;</span>
        <span style="color: #ff0000; font-style: italic;">/* hist_iterations++; */</span>
<span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">while</span> <span style="color: #008000;">&#40;</span>i <span style="color: #000040;">!</span><span style="color: #000080;">=</span> last_i<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></td></tr></table></div>

<p>这就是计算%CPU的代码，很明显total_pcpu就是累加了每个线程对每个核的使用率，所以<strong>%CPU的最大值就是核数*100%</strong>。</p>
<p>而CPU利用率又是怎么计算的呢，跟踪代码可以发现，是从系统的<strong>/proc/stat</strong>这里读取的，这个文件的格式可以参考：http://www.linuxhowtos.org/System/procstat.htm，下面是我笔记本上读出来的内容。</p>
<blockquote><p>plx@plinux-Laptop:~/busybox-1.17.1$ cat /proc/stat<br />
cpu  520529 3525 658608 3500749 210662 6650 29698 0 0<br />
cpu0 249045 1936 466387 1624486 136381 308 17051 0 0<br />
cpu1 271483 1588 192221 1876263 74281 6342 12646 0 0<br />
intr 84067574 42497789 41743 0 0 0 0 0 0 1 57928 0 0 7175 0 0 0 477092 24693 0 5 0 183 0 20 0 0 0 12455 821851 745906 10192555 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br />
ctxt 142313984<br />
btime 1281403521<br />
processes 6707<br />
procs_running 2<br />
procs_blocked 0<br />
softirq 56932805 0 20168080 9440286 238191 821787 0 10621375 4052209 13257 11577620</p></blockquote>
<p>cpuN的含义从左到右分别是：user、system、nice、idle、iowait、irq、softirq，具体含义可以看文档。<br />
在下面几行的含义是：<br />
“intr”这行给出中断的信息，第一个为自系统启动以来，发生的所有的中断的次数；然后每个数对应一个特定的中断自系统启动以来所发生的次数。<br />
“ctxt”给出了自系统启动以来CPU发生的上下文交换的次数。<br />
“btime”给出了从系统启动到现在为止的时间，单位为秒。<br />
“processes (total_forks) 自系统启动以来所创建的任务的个数目。<br />
“procs_running”：当前运行队列的任务的数目。<br />
“procs_blocked”：当前被阻塞的任务的数目。<br />
那么CPU利用率可以使用以下方法，先取两个采样点，然后计算其差值：</p>

<div class="wp_codebox"><table><tr id="p115814"><td class="code" id="p1158code14"><pre class="c" style="font-family:monospace;">cpu usage<span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span>idle2<span style="color: #339933;">-</span>idle1<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span>cpu2<span style="color: #339933;">-</span>cpu1<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #0000dd;">100</span> cpu usage<span style="color: #339933;">=</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span>user_2 <span style="color: #339933;">+</span>sys_2<span style="color: #339933;">+</span>nice_2<span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>user_1 <span style="color: #339933;">+</span> sys_1<span style="color: #339933;">+</span>nice_1<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span>total_2 <span style="color: #339933;">-</span> total_1<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #0000dd;">100</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>这是一段Bash代码采集利用率的，摘自网络：</p>

<div class="wp_codebox"><table><tr id="p115815"><td class="code" id="p1158code15"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #666666; font-style: italic;">##echo user nice system idle iowait irq softirq</span>
<span style="color: #007800;">CPULOG_1</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">stat</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">'cpu '</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $2&quot; &quot;$3&quot; &quot;$4&quot; &quot;$5&quot; &quot;$6&quot; &quot;$7&quot; &quot;$8}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">SYS_IDLE_1</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$CPULOG_1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $4}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">Total_1</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$CPULOG_1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $1+$2+$3+$4+$5+$6+$7}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">5</span>
&nbsp;
<span style="color: #007800;">CPULOG_2</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">stat</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">'cpu '</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $2&quot; &quot;$3&quot; &quot;$4&quot; &quot;$5&quot; &quot;$6&quot; &quot;$7&quot; &quot;$8}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">SYS_IDLE_2</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$CPULOG_2</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $4}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">Total_2</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$CPULOG_2</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $1+$2+$3+$4+$5+$6+$7}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> 
&nbsp;
<span style="color: #007800;">SYS_IDLE</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #007800;">$SYS_IDLE_2</span> - <span style="color: #007800;">$SYS_IDLE_1</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #007800;">Total</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #007800;">$Total_2</span> - <span style="color: #007800;">$Total_1</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">SYS_USAGE</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #007800;">$SYS_IDLE</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$Total</span><span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000;">100</span> <span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">bc</span> -l<span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #007800;">SYS_Rate</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #000000;">100</span>-<span style="color: #007800;">$SYS_USAGE</span> <span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">bc</span> -l<span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #007800;">Disp_SYS_Rate</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #ff0000;">&quot;scale=3; <span style="color: #007800;">$SYS_Rate</span>/1&quot;</span> <span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">bc</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$Disp_SYS_Rate</span><span style="color: #000000; font-weight: bold;">%</span></pre></td></tr></table></div>

<p>还有一段<acronym title="Practical Extraction and Report Language">Perl</acronym>的代码，也是摘自网络：</p>

<div class="wp_codebox"><table><tr id="p115816"><td class="code" id="p1158code16"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span>
<span style="color: #000000; font-weight: bold;">use</span> warnings<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$SLEEPTIME</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>e <span style="color: #ff0000;">&quot;/tmp/stat&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<a href="http://perldoc.perl.org/functions/unlink.html"><span style="color: #000066;">unlink</span></a> <span style="color: #ff0000;">&quot;/tmp/stat&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<a href="http://perldoc.perl.org/functions/open.html"><span style="color: #000066;">open</span></a> <span style="color: #009900;">&#40;</span>JIFF_TMP<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&amp;gt;&amp;gt;/tmp/stat&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <a href="http://perldoc.perl.org/functions/die.html"><span style="color: #000066;">die</span></a> <span style="color: #ff0000;">&quot;Can't open /proc/stat file!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<a href="http://perldoc.perl.org/functions/open.html"><span style="color: #000066;">open</span></a> <span style="color: #009900;">&#40;</span>JIFF<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;/proc/stat&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <a href="http://perldoc.perl.org/functions/die.html"><span style="color: #000066;">die</span></a> <span style="color: #ff0000;">&quot;Can't open /proc/stat file!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">@jiff_0</span><span style="color: #339933;">=;</span>
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> JIFF_TMP <span style="color: #0000ff;">$jiff_0</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">;</span>
<a href="http://perldoc.perl.org/functions/close.html"><span style="color: #000066;">close</span></a> <span style="color: #009900;">&#40;</span>JIFF<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<a href="http://perldoc.perl.org/functions/sleep.html"><span style="color: #000066;">sleep</span></a> <span style="color: #0000ff;">$SLEEPTIME</span><span style="color: #339933;">;</span>
&nbsp;
<a href="http://perldoc.perl.org/functions/open.html"><span style="color: #000066;">open</span></a> <span style="color: #009900;">&#40;</span>JIFF<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;/proc/stat&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <a href="http://perldoc.perl.org/functions/die.html"><span style="color: #000066;">die</span></a> <span style="color: #ff0000;">&quot;Can't open /proc/stat file!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>  <span style="color: #0000ff;">@jiff_1</span><span style="color: #339933;">=;</span>
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> JIFF_TMP <span style="color: #0000ff;">$jiff_1</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<a href="http://perldoc.perl.org/functions/close.html"><span style="color: #000066;">close</span></a> <span style="color: #009900;">&#40;</span>JIFF<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a href="http://perldoc.perl.org/functions/close.html"><span style="color: #000066;">close</span></a> <span style="color: #009900;">&#40;</span>JIFF_TMP<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">@USER</span><span style="color: #339933;">=</span><span style="color: #ff0000;">`awk '{print <span style="color: #000099; font-weight: bold;">\$</span>2}' &quot;/tmp/stat&quot;`</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">@NICE</span><span style="color: #339933;">=</span><span style="color: #ff0000;">`awk '{print <span style="color: #000099; font-weight: bold;">\$</span>3}' &quot;/tmp/stat&quot;`</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">@SYSTEM</span><span style="color: #339933;">=</span><span style="color: #ff0000;">`awk '{print <span style="color: #000099; font-weight: bold;">\$</span>4}' &quot;/tmp/stat&quot;`</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">@IDLE</span><span style="color: #339933;">=</span><span style="color: #ff0000;">`awk '{print <span style="color: #000099; font-weight: bold;">\$</span>5}' &quot;/tmp/stat&quot;`</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">@IOWAIT</span><span style="color: #339933;">=</span><span style="color: #ff0000;">`awk '{print <span style="color: #000099; font-weight: bold;">\$</span>6}' &quot;/tmp/stat&quot;`</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">@IRQ</span><span style="color: #339933;">=</span><span style="color: #ff0000;">`awk '{print <span style="color: #000099; font-weight: bold;">\$</span>7}' &quot;/tmp/stat&quot;`</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">@SOFTIRQ</span><span style="color: #339933;">=</span><span style="color: #ff0000;">`awk '{print <span style="color: #000099; font-weight: bold;">\$</span>8}' &quot;/tmp/stat&quot;`</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$JIFF_0</span><span style="color: #339933;">=</span><span style="color: #0000ff;">$USER</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">$NICE</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">$SYSTEM</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">$IDLE</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">$IOWAIT</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">$IRQ</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">$SOFTIRQ</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$JIFF_1</span><span style="color: #339933;">=</span><span style="color: #0000ff;">$USER</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">$NICE</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">$SYSTEM</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">$IDLE</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">$IOWAIT</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">$IRQ</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">$SOFTIRQ</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$SYS_IDLE</span><span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$IDLE</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-</span><span style="color: #0000ff;">$IDLE</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$JIFF_0</span><span style="color: #339933;">-</span><span style="color: #0000ff;">$JIFF_1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>  <span style="color: #0000ff;">$SYS_USAGE</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">100</span> <span style="color: #339933;">-</span> <span style="color: #0000ff;">$SYS_IDLE</span><span style="color: #339933;">;</span>
&nbsp;
<a href="http://perldoc.perl.org/functions/printf.html"><span style="color: #000066;">printf</span></a> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;The CPU usage is %1.2f%%<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$SYS_USAGE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p></br><br />
</br></p>
<h1>Load的计算方法</h1>
<p>跟踪busybox的代码可以知道，load是从/proc/loadavg中读取的。<br />
我本机的一次抓取内容如下：</p>
<blockquote><p>plx@plinux-Laptop:~/busybox-1.17.1$ cat /proc/loadavg<br />
0.64 0.81 0.86 3/364 6930</p></blockquote>
<p>每个值的含义依次为：<br />
lavg_1 (0.64) 1-分钟平均负载<br />
lavg_5 (0.81) 5-分钟平均负载<br />
lavg_15(0.86) 15-分钟平均负载<br />
nr_running (3) 在采样时刻，运行队列的任务的数目，与/proc/stat的procs_running表示相同意思<br />
nr_threads (364) 在采样时刻，系统中活跃的任务的个数（不包括运行已经结束的任务）<br />
last_pid(6930) 最大的pid值，包括轻量级进程，即线程。<br />
假设当前有两个CPU，则每个CPU的当前任务数为0.64/2=0.32</p>
<p>我们可以在Linux内核中找到loadavg文件的源码：</p>

<div class="wp_codebox"><table><tr id="p115817"><td class="code" id="p1158code17"><pre class="c" style="font-family:monospace;">tatic <span style="color: #993333;">int</span> loadavg_read_proc<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>page<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">**</span>start<span style="color: #339933;">,</span> off_t off<span style="color: #339933;">,</span>
                                 <span style="color: #993333;">int</span> count<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> <span style="color: #339933;">*</span>eof<span style="color: #339933;">,</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span>data<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
        <span style="color: #993333;">int</span> a<span style="color: #339933;">,</span> b<span style="color: #339933;">,</span> c<span style="color: #339933;">;</span>
        <span style="color: #993333;">int</span> len<span style="color: #339933;">;</span>
<span style="color: #339933;">#</span>
&nbsp;
        a <span style="color: #339933;">=</span> avenrun<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>FIXED_1<span style="color: #339933;">/</span><span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        b <span style="color: #339933;">=</span> avenrun<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>FIXED_1<span style="color: #339933;">/</span><span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        c <span style="color: #339933;">=</span> avenrun<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>FIXED_1<span style="color: #339933;">/</span><span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        len <span style="color: #339933;">=</span> sprintf<span style="color: #009900;">&#40;</span>page<span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;%d.%02d %d.%02d %d.%02d %ld/%d %d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>
                LOAD_INT<span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> LOAD_FRAC<span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                LOAD_INT<span style="color: #009900;">&#40;</span>b<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> LOAD_FRAC<span style="color: #009900;">&#40;</span>b<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                LOAD_INT<span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> LOAD_FRAC<span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                nr_running<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> nr_threads<span style="color: #339933;">,</span> last_pid<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> proc_calc_metrics<span style="color: #009900;">&#40;</span>page<span style="color: #339933;">,</span> start<span style="color: #339933;">,</span> off<span style="color: #339933;">,</span> count<span style="color: #339933;">,</span> eof<span style="color: #339933;">,</span> len<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>以及计算load的代码：</p>

<div class="wp_codebox"><table><tr id="p115818"><td class="code" id="p1158code18"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#define FSHIFT      11          /* nr of bits of precision */</span>
<span style="color: #339933;">#define FIXED_1     (1&lt;&lt;FSHIFT) /* 1.0 as fixed-point(定点) */</span>
<span style="color: #339933;">#define LOAD_FREQ   (5*HZ)      /* 5 sec intervals，每隔5秒计算一次平均负载值 */</span>
<span style="color: #339933;">#define CALC_LOAD(load, exp, n)     \
         load *= exp;               \
         load += n*(FIXED_1 - exp); \
         load &gt;&gt;= FSHIFT;</span>
&nbsp;
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> avenrun<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
EXPORT_SYMBOL<span style="color: #009900;">&#40;</span>avenrun<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/*
* calc_load - given tick count, update the avenrun load estimates.
* This is called while holding a write_lock on xtime_lock.
*/</span>
<span style="color: #993333;">static</span> <span style="color: #000000; font-weight: bold;">inline</span> <span style="color: #993333;">void</span> calc_load<span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> ticks<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
        <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> active_tasks<span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* fixed-point */</span>
        <span style="color: #993333;">static</span> <span style="color: #993333;">int</span> count <span style="color: #339933;">=</span> LOAD_FREQ<span style="color: #339933;">;</span>
        count <span style="color: #339933;">-=</span> ticks<span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>count <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                count <span style="color: #339933;">+=</span> LOAD_FREQ<span style="color: #339933;">;</span>
                active_tasks <span style="color: #339933;">=</span> count_active_tasks<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                CALC_LOAD<span style="color: #009900;">&#40;</span>avenrun<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> EXP_1<span style="color: #339933;">,</span> active_tasks<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                CALC_LOAD<span style="color: #009900;">&#40;</span>avenrun<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> EXP_5<span style="color: #339933;">,</span> active_tasks<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                CALC_LOAD<span style="color: #009900;">&#40;</span>avenrun<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> EXP_15<span style="color: #339933;">,</span> active_tasks<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>看了<a href="http://bitirainy.itpub.net/post/330/6405">大师的文章</a>，理解了这些代码。<br />
所以可以明白：<strong>Linux的系统负载指运行队列的平均长度，也就是等待CPU的平均进程数。</strong> Linux的系统负载指运行队列的平均长度，也就是等待CPU的平均进程数。因为Linux内禁止浮点运算，因此系统的负载只能通过计算变化的次数这一修正值来计算。Linux内核定义一个长度为3的双字数组avenrun，双字的低11位用于存放负载的小数部分，高21位用于存放整数部分。当进程所耗的 CPU时间片数超过CPU在5秒内能够提供的时间片数时，内核计算上述的三个负载。负载初始化为0，假设最近1、5、15分钟内的平均负载分别为 load1、load5和load15，那么下一个计算时刻到来时，内核通过下面的算式计算负载：<br />
    load1 -= load1 -* exp(-5 / 60) -+ n * (1 &#8211; exp(-5 / 60 ))<br />
    load5 -= load5 -* exp(-5 / 300) + n * (1 &#8211; exp(-5 / 300))<br />
    load15 = load15 * exp(-5 / 900) + n * (1 &#8211; exp(-5 / 900))<br />
    其中，exp(x)为e的x次幂，n为当前运行队列的长度。Linux内核认为进程的生存时间服从参数为1的指数分布，指数分布的概率密度为：以内核计算负载load1为例，设相邻两个计算时刻之间系统活动的进程集合为S0。从1分钟前到当前计算时刻这段时间里面活动的load1个进程，设他们的集合是 S1，内核认为的概率密度是:λe-λx，而在当前时刻活动的n个进程，设他们的集合是Sn内核认为的概率密度是1-λe-λx。其中x = 5 / 60，因为相邻两个计算时刻之间进程所耗的CPU时间为5秒，而考虑的时间段是1分钟(60秒)。那么可以求出最近1分钟系统运行队列的长度：<br />
    <strong>load1 = |S1| -* λe-λx + |Sn| * (1-λe-λx) = load1 * λe-λx + n * (1-λe-λx)</strong><br />
其中λ = 1， x = 5 / 60， |S1|和|Sn|是集合元素的个数，这就是Linux内核源文件shed.c的函数calc_load()计算负载的数学依据。<br />
</br><br />
所以“Load值=CPU核数”，这是最理想的状态，没有任何竞争，一个任务分配一个核。<br />
由于数据是每隔5秒钟检查一次活跃的进程数，然后根据这个数值算出来的。<strong>如果这个数除以CPU的核数，结果高于5的时候就表明系统在超负荷运转了。</strong></p><h2  class="related_post_title">类似的文章</h2><ul class="related_post"><li>2009年10月21日 -- <a href="http://www.penglixun.com/tech/system/commond_watch_linux_system_resources.html" title="[转]Linux中查看系统资源占用情况的命令">[转]Linux中查看系统资源占用情况的命令</a> (0)</li><li>2012年01月23日 -- <a href="http://www.penglixun.com/tech/database/case_about_innodb_faster_than_oracle.html" title="一个InnoDB性能超过Oracle的调优Case">一个InnoDB性能超过Oracle的调优Case</a> (1)</li><li>2010年08月27日 -- <a href="http://www.penglixun.com/tech/system/linux_cache_discovery.html" title="Linux Cache 机制探究">Linux Cache 机制探究</a> (1)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/tech/system/how_to_calc_load_cpu.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>ZFS挂载时directory is not empty问题</title>
		<link>http://www.penglixun.com/tech/system/zfs_cannot_mount.html</link>
		<comments>http://www.penglixun.com/tech/system/zfs_cannot_mount.html#comments</comments>
		<pubDate>Wed, 21 Jul 2010 16:10:40 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[操作系统]]></category>
		<category><![CDATA[Solaris]]></category>
		<category><![CDATA[ZFS]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/?p=1153</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明网址: http://www.penglixun.com/tech/system/zfs_cannot_mount.html 今天重启一台数据库主机（Solaris系统）... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br>网址: http://www.penglixun.com/tech/system/zfs_cannot_mount.html </p>
<p></span>今天重启一台数据库主机（Solaris系统），结果在重启时报出了错误：</p>
<blockquote><p>cannot mount &#8216;/export/home/alt&#8217;: directory is not empty</p></blockquote>
<p>SA折腾许久不能解决，查看ZFS Administration Guide，发现一条这样的描述：</p>
<blockquote><p>By default, ZFS does not allow mounting on top of a non-empty directory. To force a mount on top of a non-empty directory, the -O option must be used.</p></blockquote>
<p>原来是默认不允许挂载在一个非空目录的顶部，文档也给出了方案，-O参数。</p>
<blockquote><p>zfs mount -O data/mysqldata</p></blockquote>
<p>这样就可以强制挂载上去了。</p>
<p>不过据说mount -F zfs data/mysqldata这样旧的方式挂载也是OK的。</p>
<p>有时候，很多答案都在文档里了，只是我们不Care。</p><h2  class="related_post_title">类似的文章</h2><ul class="related_post"><li>2010年05月21日 -- <a href="http://www.penglixun.com/tech/database/solaris_double_master_change_disk.html" title="Solaris双Master结构主机更换磁盘方案">Solaris双Master结构主机更换磁盘方案</a> (0)</li><li>2010年05月21日 -- <a href="http://www.penglixun.com/tech/system/solaris_crontab_not_run_slove.html" title="Solaris下crontab不执行的问题">Solaris下crontab不执行的问题</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/tech/system/zfs_cannot_mount.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Solaris下crontab不执行的问题</title>
		<link>http://www.penglixun.com/tech/system/solaris_crontab_not_run_slove.html</link>
		<comments>http://www.penglixun.com/tech/system/solaris_crontab_not_run_slove.html#comments</comments>
		<pubDate>Thu, 20 May 2010 16:33:16 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[操作系统]]></category>
		<category><![CDATA[crontab]]></category>
		<category><![CDATA[Solaris]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/?p=1117</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明网址: http://www.penglixun.com/tech/system/solaris_crontab_not_run_slove.html 今天在Solaris服务器上发现cront... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br>网址: http://www.penglixun.com/tech/system/solaris_crontab_not_run_slove.html </p>
<p></span>今天在Solaris服务器上发现crontab脚本都没有执行，很诧异。<br />
Google之发现，Solaris对于没有密码、没有被启用、密码失效的用户是不执行crontab的。<br />
查看/var/cron/log，果然发现很多bad user(mysql)。<br />
由于新装的机器，明天还要操作，所以密码还没来得及设置，于是就bad user了。<br />
passwd设置密码后，看到日志里一些人物已经有pid了。<br />
以后服务器装系统不应图方便，装完就立刻设置密码～</p><h2  class="related_post_title">类似的文章</h2><ul class="related_post"><li>2010年07月22日 -- <a href="http://www.penglixun.com/tech/system/zfs_cannot_mount.html" title="ZFS挂载时directory is not empty问题">ZFS挂载时directory is not empty问题</a> (1)</li><li>2010年05月21日 -- <a href="http://www.penglixun.com/tech/database/solaris_double_master_change_disk.html" title="Solaris双Master结构主机更换磁盘方案">Solaris双Master结构主机更换磁盘方案</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/tech/system/solaris_crontab_not_run_slove.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Xfce下ZendStudio的报错处理</title>
		<link>http://www.penglixun.com/tech/system/xfce_zendstudio_error.html</link>
		<comments>http://www.penglixun.com/tech/system/xfce_zendstudio_error.html#comments</comments>
		<pubDate>Fri, 09 Apr 2010 12:23:01 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[操作系统]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[JAVA]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Zned]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/?p=1097</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明网址: http://www.penglixun.com/tech/system/xfce_zendstudio_error.html 为了轻量，我的Gentoo Linux用的Xfce桌... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br>网址: http://www.penglixun.com/tech/system/xfce_zendstudio_error.html </p>
<p></span>为了轻量，我的Gentoo Linux用的Xfce桌面系统，一切都还不错，今天装ZendStudio遇到了些问题，记下。</p>
<p>安装的时候都很正常，解压下载的压缩包得到.bin文件，然后安装，也没有错，但是一启动就挂了。<br />
查看了/home/plx/Zend/workspace/DefaultWorkspace7/.metadata/.log 发现如下异常：</p>

<div class="wp_codebox"><table><tr id="p109720"><td class="code" id="p1097code20"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">!</span>MESSAGE Application error
<span style="color: #339933;">!</span>STACK <span style="color: #cc66cc;">1</span>
org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">swt</span>.<span style="color: #006633;">SWTError</span><span style="color: #339933;">:</span> XPCOM error <span style="color: #339933;">-</span><span style="color: #cc66cc;">2147467262</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">swt</span>.<span style="color: #006633;">browser</span>.<span style="color: #006633;">Mozilla</span>.<span style="color: #006633;">error</span><span style="color: #009900;">&#40;</span>Mozilla.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">1688</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">swt</span>.<span style="color: #006633;">browser</span>.<span style="color: #006633;">Mozilla</span>.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>Mozilla.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">1911</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">swt</span>.<span style="color: #006633;">browser</span>.<span style="color: #006633;">Browser</span>.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>Browser.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">750</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">intro</span>.<span style="color: #006633;">impl</span>.<span style="color: #006633;">presentations</span>.<span style="color: #006633;">BrowserIntroPartImplementation</span>.<span style="color: #006633;">generateContentForPage</span><span style="color: #009900;">&#40;</span>BrowserIntroPartImplementation.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">363</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">intro</span>.<span style="color: #006633;">impl</span>.<span style="color: #006633;">presentations</span>.<span style="color: #006633;">BrowserIntroPartImplementation</span>.<span style="color: #006633;">dynamicStandbyStateChanged</span><span style="color: #009900;">&#40;</span>BrowserIntroPartImplementation.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">577</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">intro</span>.<span style="color: #006633;">impl</span>.<span style="color: #006633;">presentations</span>.<span style="color: #006633;">BrowserIntroPartImplementation</span>.<span style="color: #006633;">doStandbyStateChanged</span><span style="color: #009900;">&#40;</span>BrowserIntroPartImplementation.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">784</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">intro</span>.<span style="color: #006633;">impl</span>.<span style="color: #006633;">model</span>.<span style="color: #006633;">AbstractIntroPartImplementation</span>.<span style="color: #006633;">standbyStateChanged</span><span style="color: #009900;">&#40;</span>AbstractIntroPartImplementation.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">249</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">intro</span>.<span style="color: #006633;">impl</span>.<span style="color: #006633;">model</span>.<span style="color: #006633;">IntroPartPresentation</span>.<span style="color: #006633;">standbyStateChanged</span><span style="color: #009900;">&#40;</span>IntroPartPresentation.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">443</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">intro</span>.<span style="color: #006633;">config</span>.<span style="color: #006633;">CustomizableIntroPart</span>.<span style="color: #006633;">standbyStateChanged</span><span style="color: #009900;">&#40;</span>CustomizableIntroPart.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">266</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">ViewIntroAdapterPart</span>$<span style="color: #cc66cc;">2</span>.<span style="color: #006633;">run</span><span style="color: #009900;">&#40;</span>ViewIntroAdapterPart.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">74</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">swt</span>.<span style="color: #006633;">custom</span>.<span style="color: #006633;">BusyIndicator</span>.<span style="color: #006633;">showWhile</span><span style="color: #009900;">&#40;</span>BusyIndicator.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">70</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">ViewIntroAdapterPart</span>.<span style="color: #006633;">setStandby</span><span style="color: #009900;">&#40;</span>ViewIntroAdapterPart.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">70</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">ViewIntroAdapterPart</span>$<span style="color: #cc66cc;">1</span>.<span style="color: #006633;">propertyChanged</span><span style="color: #009900;">&#40;</span>ViewIntroAdapterPart.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">55</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">WorkbenchPartReference</span>.<span style="color: #006633;">fireInternalPropertyChange</span><span style="color: #009900;">&#40;</span>WorkbenchPartReference.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">375</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">WorkbenchPartReference</span>.<span style="color: #006633;">fireZoomChange</span><span style="color: #009900;">&#40;</span>WorkbenchPartReference.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">540</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">PartPane</span>.<span style="color: #006633;">setZoomed</span><span style="color: #009900;">&#40;</span>PartPane.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">356</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">PartStack</span>.<span style="color: #006633;">setZoomed</span><span style="color: #009900;">&#40;</span>PartStack.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">1526</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">PartSashContainer</span>.<span style="color: #006633;">zoomIn</span><span style="color: #009900;">&#40;</span>PartSashContainer.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">884</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">PartSashContainer</span>.<span style="color: #006633;">childRequestZoomIn</span><span style="color: #009900;">&#40;</span>PartSashContainer.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">905</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">LayoutPart</span>.<span style="color: #006633;">requestZoomIn</span><span style="color: #009900;">&#40;</span>LayoutPart.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">354</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">PartStack</span>.<span style="color: #006633;">setState</span><span style="color: #009900;">&#40;</span>PartStack.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">1501</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">WorkbenchPage</span>.<span style="color: #006633;">setState</span><span style="color: #009900;">&#40;</span>WorkbenchPage.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">3872</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">WorkbenchPage</span>.<span style="color: #006633;">toggleZoom</span><span style="color: #009900;">&#40;</span>WorkbenchPage.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">3944</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">WorkbenchIntroManager</span>.<span style="color: #006633;">setIntroStandby</span><span style="color: #009900;">&#40;</span>WorkbenchIntroManager.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">201</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">WorkbenchIntroManager</span>.<span style="color: #006633;">showIntro</span><span style="color: #009900;">&#40;</span>WorkbenchIntroManager.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">136</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">application</span>.<span style="color: #006633;">WorkbenchWindowAdvisor</span>.<span style="color: #006633;">openIntro</span><span style="color: #009900;">&#40;</span>WorkbenchWindowAdvisor.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">173</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">ide</span>.<span style="color: #006633;">application</span>.<span style="color: #006633;">IDEWorkbenchWindowAdvisor</span>.<span style="color: #006633;">openIntro</span><span style="color: #009900;">&#40;</span>IDEWorkbenchWindowAdvisor.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">458</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">WorkbenchWindow</span>.<span style="color: #006633;">open</span><span style="color: #009900;">&#40;</span>WorkbenchWindow.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">777</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">Workbench</span>$<span style="color: #cc66cc;">22</span>.<span style="color: #006633;">runWithException</span><span style="color: #009900;">&#40;</span>Workbench.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">1041</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">StartupThreading</span>$StartupRunnable.<span style="color: #006633;">run</span><span style="color: #009900;">&#40;</span>StartupThreading.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">31</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">swt</span>.<span style="color: #006633;">widgets</span>.<span style="color: #006633;">RunnableLock</span>.<span style="color: #006633;">run</span><span style="color: #009900;">&#40;</span>RunnableLock.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">35</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">swt</span>.<span style="color: #006633;">widgets</span>.<span style="color: #006633;">Synchronizer</span>.<span style="color: #006633;">runAsyncMessages</span><span style="color: #009900;">&#40;</span>Synchronizer.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">133</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">swt</span>.<span style="color: #006633;">widgets</span>.<span style="color: #006633;">Display</span>.<span style="color: #006633;">runAsyncMessages</span><span style="color: #009900;">&#40;</span>Display.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">3378</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">swt</span>.<span style="color: #006633;">widgets</span>.<span style="color: #006633;">Display</span>.<span style="color: #006633;">readAndDispatch</span><span style="color: #009900;">&#40;</span>Display.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">3036</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">application</span>.<span style="color: #006633;">WorkbenchAdvisor</span>.<span style="color: #006633;">openWindows</span><span style="color: #009900;">&#40;</span>WorkbenchAdvisor.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">803</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">Workbench</span>$<span style="color: #cc66cc;">27</span>.<span style="color: #006633;">runWithException</span><span style="color: #009900;">&#40;</span>Workbench.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">1361</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">StartupThreading</span>$StartupRunnable.<span style="color: #006633;">run</span><span style="color: #009900;">&#40;</span>StartupThreading.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">31</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">swt</span>.<span style="color: #006633;">widgets</span>.<span style="color: #006633;">RunnableLock</span>.<span style="color: #006633;">run</span><span style="color: #009900;">&#40;</span>RunnableLock.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">35</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">swt</span>.<span style="color: #006633;">widgets</span>.<span style="color: #006633;">Synchronizer</span>.<span style="color: #006633;">runAsyncMessages</span><span style="color: #009900;">&#40;</span>Synchronizer.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">133</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">swt</span>.<span style="color: #006633;">widgets</span>.<span style="color: #006633;">Display</span>.<span style="color: #006633;">runAsyncMessages</span><span style="color: #009900;">&#40;</span>Display.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">3378</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">swt</span>.<span style="color: #006633;">widgets</span>.<span style="color: #006633;">Display</span>.<span style="color: #006633;">readAndDispatch</span><span style="color: #009900;">&#40;</span>Display.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">3036</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">Workbench</span>.<span style="color: #006633;">runUI</span><span style="color: #009900;">&#40;</span>Workbench.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">2293</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">Workbench</span>.<span style="color: #006633;">access</span>$<span style="color: #cc66cc;">4</span><span style="color: #009900;">&#40;</span>Workbench.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">2198</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">Workbench</span>$<span style="color: #cc66cc;">5</span>.<span style="color: #006633;">run</span><span style="color: #009900;">&#40;</span>Workbench.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">493</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">core</span>.<span style="color: #006633;">databinding</span>.<span style="color: #006633;">observable</span>.<span style="color: #006633;">Realm</span>.<span style="color: #006633;">runWithDefault</span><span style="color: #009900;">&#40;</span>Realm.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">288</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">Workbench</span>.<span style="color: #006633;">createAndRunWorkbench</span><span style="color: #009900;">&#40;</span>Workbench.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">488</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">PlatformUI</span>.<span style="color: #006633;">createAndRunWorkbench</span><span style="color: #009900;">&#40;</span>PlatformUI.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">149</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">ui</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">ide</span>.<span style="color: #006633;">application</span>.<span style="color: #006633;">IDEApplication</span>.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span>IDEApplication.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">113</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">equinox</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">app</span>.<span style="color: #006633;">EclipseAppHandle</span>.<span style="color: #006633;">run</span><span style="color: #009900;">&#40;</span>EclipseAppHandle.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">193</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">core</span>.<span style="color: #006633;">runtime</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">adaptor</span>.<span style="color: #006633;">EclipseAppLauncher</span>.<span style="color: #006633;">runApplication</span><span style="color: #009900;">&#40;</span>EclipseAppLauncher.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">110</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">core</span>.<span style="color: #006633;">runtime</span>.<span style="color: #006633;">internal</span>.<span style="color: #006633;">adaptor</span>.<span style="color: #006633;">EclipseAppLauncher</span>.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span>EclipseAppLauncher.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">79</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">core</span>.<span style="color: #006633;">runtime</span>.<span style="color: #006633;">adaptor</span>.<span style="color: #006633;">EclipseStarter</span>.<span style="color: #006633;">run</span><span style="color: #009900;">&#40;</span>EclipseStarter.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">370</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">core</span>.<span style="color: #006633;">runtime</span>.<span style="color: #006633;">adaptor</span>.<span style="color: #006633;">EclipseStarter</span>.<span style="color: #006633;">run</span><span style="color: #009900;">&#40;</span>EclipseStarter.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">179</span><span style="color: #009900;">&#41;</span>
 at sun.<span style="color: #006633;">reflect</span>.<span style="color: #006633;">NativeMethodAccessorImpl</span>.<span style="color: #006633;">invoke0</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">Native</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amethod+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Method</span></a><span style="color: #009900;">&#41;</span>
 at sun.<span style="color: #006633;">reflect</span>.<span style="color: #006633;">NativeMethodAccessorImpl</span>.<span style="color: #006633;">invoke</span><span style="color: #009900;">&#40;</span>NativeMethodAccessorImpl.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">39</span><span style="color: #009900;">&#41;</span>
 at sun.<span style="color: #006633;">reflect</span>.<span style="color: #006633;">DelegatingMethodAccessorImpl</span>.<span style="color: #006633;">invoke</span><span style="color: #009900;">&#40;</span>DelegatingMethodAccessorImpl.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">25</span><span style="color: #009900;">&#41;</span>
 at java.<span style="color: #006633;">lang</span>.<span style="color: #006633;">reflect</span>.<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amethod+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Method</span></a>.<span style="color: #006633;">invoke</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amethod+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Method</span></a>.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">597</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">equinox</span>.<span style="color: #006633;">launcher</span>.<span style="color: #006633;">Main</span>.<span style="color: #006633;">invokeFramework</span><span style="color: #009900;">&#40;</span>Main.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">549</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">equinox</span>.<span style="color: #006633;">launcher</span>.<span style="color: #006633;">Main</span>.<span style="color: #006633;">basicRun</span><span style="color: #009900;">&#40;</span>Main.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">504</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">equinox</span>.<span style="color: #006633;">launcher</span>.<span style="color: #006633;">Main</span>.<span style="color: #006633;">run</span><span style="color: #009900;">&#40;</span>Main.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">1236</span><span style="color: #009900;">&#41;</span>
 at org.<span style="color: #006633;">eclipse</span>.<span style="color: #006633;">equinox</span>.<span style="color: #006633;">launcher</span>.<span style="color: #006633;">Main</span>.<span style="color: #006633;">main</span><span style="color: #009900;">&#40;</span>Main.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">1212</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>我以为是我没装JRE，但是安装目录下有JRE，Zend应该是调用自带的。<br />
Google之，有人说删除xulrunner，我这依赖xulrunner的软件太多，不可能删。</p>
<p>发现有人说是少了个参数，<br />
-Dorg.eclipse.swt.browser.XULRunnerPath=<br />
这个java系统参数应该指定一个目录，但是这里可以任意写或者空着。<br />
在添加该行后，重新启动ZendStudio，然后就可以把该行删除，以后再启动都不会报错了。<br />
同理，因为ZendStudio基于Eclipse，所以Eclipse也适用。</p><h2  class="related_post_title">类似的文章</h2><ul class="related_post"><li>2010年01月18日 -- <a href="http://www.penglixun.com/tech/system/linux_compile_php_error.html" title="Linux下编译PHP的几种错误">Linux下编译PHP的几种错误</a> (1)</li><li>2009年10月14日 -- <a href="http://www.penglixun.com/tech/program/orm_or_rom.html" title="ORM or ROM？">ORM or ROM？</a> (0)</li><li>2009年07月15日 -- <a href="http://www.penglixun.com/tech/system/nginx_php_fastcgi_better_apache.html" title="Nginx 0.7.x + PHP 5.2.10（FastCGI）搭建胜过Apache十倍的Web服务器">Nginx 0.7.x + PHP 5.2.10（FastCGI）搭建胜过Apache十倍的Web服务器</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/tech/system/xfce_zendstudio_error.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NTP同步配置</title>
		<link>http://www.penglixun.com/tech/system/ntp_synchronization_configure.html</link>
		<comments>http://www.penglixun.com/tech/system/ntp_synchronization_configure.html#comments</comments>
		<pubDate>Mon, 15 Mar 2010 09:00:18 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[操作系统]]></category>
		<category><![CDATA[NTP]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/?p=1063</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明网址: http://www.penglixun.com/tech/system/ntp_synchronization_configure.html 周末遇到一个问题，数据库主... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br>网址: http://www.penglixun.com/tech/system/ntp_synchronization_configure.html </p>
<p></span>周末遇到一个问题，数据库主机不断地报：NTP WARNING: Offset XXX secs。<br />
肯定就是NTP同步时间出问题了。<br />
首先简单介绍一下NTP：“NTP协议全称网络时间协议（Network Time Procotol）。它的目的是在国际互联网上传递统一、标准的时间。具体的实现方案是在网络上指定若干时钟源网站，为用户提供授时服务，并且这些网站间应该能够相互比对，提高准确度。”<br />
我们内网也是有NTP服务器的，为什么同步会出现这么大的Offset？<br />
登陆机器查看情况，首先看ntpstat</p>
<blockquote><p>synchronised to<span style="color: #ff0000;"> local net</span> at stratum 11<br />
time correct to within 11 ms<br />
polling server every 1024 s</p></blockquote>
<p>很奇怪，为什么是local net？<br />
查看配置文件/etc/ntp.conf，没有什么异常。<br />
对比了其他服务器，发现server的配置不一样，怀疑可能是这台机器设置的server不可用，ping了一下，果然不通，确定了是内网NTP服务器设置的问题。<br />
把其他服务器上配置的三个地址拷贝过来，/etc/init.d/ntpd restart，竟然出现了fail！</p>
<blockquote><p>
Shutting down ntpd:                         [  OK  ]<br />
ntpd: Synchronizing with time server:  [FAILED]<br />
Starting ntpd:                                 [  OK  ]
</p></blockquote>
<p>为什么Fail，已经修改过server地址了，并且其他服务器也是这个server就能同步。<br />
再检查/etc/ntp/目录下的文件，发现一个step-tickers文件，里面写的是原先错误的server ip，于是修改之再次重启/etc/init.d/ntpd restart，<br />
这次正常了</p>
<blockquote><p>
Shutting down ntpd:                         [  OK  ]<br />
ntpd: Synchronizing with time server:  [  OK  ]<br />
Starting ntpd:                                 [  OK  ]
</p></blockquote>
<p>过一会再看ntpstst，也正常了。</p>
<blockquote><p>synchronised to NTP server (X.X.X.X) at stratum 3<br />
    time correct to within 11 ms<br />
    polling server every 64 s</p></blockquote><h2  class="related_post_title">随机显示文章</h2><ul class="related_post"><li>2009年05月24日 -- <a href="http://www.penglixun.com/tech/system/tuning_redhat_enterprise_linux_in_ibm_system_x_server.html" title="RedHat Enterprise Linux在IBM System x服务器上的调优">RedHat Enterprise Linux在IBM System x服务器上的调优</a> (0)</li><li>2010年05月25日 -- <a href="http://www.penglixun.com/life/diary/quality_of_life.html" title="我的生活品质">我的生活品质</a> (7)</li><li>2010年03月29日 -- <a href="http://www.penglixun.com/tech/pm/project_management_controllability.html" title="项目管理的可控性讨论">项目管理的可控性讨论</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/tech/system/ntp_synchronization_configure.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CPU负载的分析</title>
		<link>http://www.penglixun.com/tech/system/cpu_load_analyse.html</link>
		<comments>http://www.penglixun.com/tech/system/cpu_load_analyse.html#comments</comments>
		<pubDate>Wed, 03 Mar 2010 12:21:14 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[操作系统]]></category>
		<category><![CDATA[Context Switch]]></category>
		<category><![CDATA[CPU Load]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/?p=1000</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明网址: http://www.penglixun.com/tech/system/cpu_load_analyse.html 最近对我的本本（4核8线程）用top命令... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br>网址: http://www.penglixun.com/tech/system/cpu_load_analyse.html </p>
<p></span>最近对我的本本（4核8线程）用top命令看系统状况出现了CPU利用率超过200%的情况，非常诧异，查了下相关资料，把这个问题弄清楚了。<br />
首先来分析下CPU Load</p>
<blockquote><p>load average: 0.09, 0.05, 0.01</p></blockquote>
<p>分别是1分钟、5分钟、15分钟的平均Load。<br />
Load这个东西怎么理解呢，就像一条马路，有N个车道，如果N个进程进入车道，那么正好一人一个，再多一辆车就占不到车道，要等有一个车空出车道。<br />
在CPU中可以理解为CPU可以并行处理的任务数，那么就是“CPU个数 * 核数”，如果CPU Load = CPU个数 * 核数 那么就是说CPU正好满负载，再多一点，可能就要出问题了，有任务不能被及时分配处理器，那么保证性能的话，最好是小于CPU个数 * 核数 *0.7。</p>
<blockquote><p>查看CPU核数可以通过：grep &#8216;model name&#8217; /proc/cpuinfo</p></blockquote>
<p>那么以哪个平均值为准呢？如果1分钟平均出现大于CPU个数 * 核数的情况，还不用担心，如果5分钟平均也是，那就要警惕了，15分钟平均也是这样，就要分析哪里出问题了，防范于未然<br />
CPU利用率超过100%的问题，也是差不多，top命令应该是把每个核的CPU占用率加起来，算一个和，于是多核情况下会出现超过100%。</p>
<p>另外Context Switch Rate也是个非常值得注意的值，因为线程间切换的代价也是非常高的。</p>
<blockquote><p>引用一个公式：Context Switch Rate = Interrupt Rate + TPS* N</p></blockquote>
<p>对于一个多线程的程序，我觉得准备一个控制线程来调度任务是非常必要的，免得线程过于高并发，导致资源的争用和线程切换带来性能问题，最好控制并发的线程数基本等于CPU的总核数，减少这个N，获得更好的处理器性能。</p>
<p>参考了如下几篇文章：<br />
<a href="http://blog.csdn.net/marising/archive/2010/01/12/5182771.aspx">压力测试衡量CPU的三个指标：CPU Utilization、Load Average和Context Switch Rate</a><br />
<a href="http://www.blogjava.net/cenwenchu/archive/2008/06/30/211712.html">理解Load Average做好压力测试</a><br />
<a href="http://www.gracecode.com/archives/2973/">理解 Linux 的处理器负载均值</a><br />
<a href="http://blog.csdn.net/marising/archive/2010/01/13/5186643.aspx">高性能服务器架构</a></p>
<p>PS. 最近博客写得少，都要长草了。顺便赞一下阿里的食堂，比我们学校食堂四年不变菜饭还贵好多了。</p><h2  class="related_post_title">随机显示文章</h2><ul class="related_post"><li>2010年04月9日 -- <a href="http://www.penglixun.com/tech/system/xfce_zendstudio_error.html" title="Xfce下ZendStudio的报错处理">Xfce下ZendStudio的报错处理</a> (0)</li><li>2010年04月4日 -- <a href="http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-04-04.html" title="每周推特 2010-04-04">每周推特 2010-04-04</a> (0)</li><li>2010年03月29日 -- <a href="http://www.penglixun.com/tech/pm/project_management_controllability.html" title="项目管理的可控性讨论">项目管理的可控性讨论</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/tech/system/cpu_load_analyse.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>为什么采用源码编译配置服务器</title>
		<link>http://www.penglixun.com/tech/system/why_use_src_conf_server.html</link>
		<comments>http://www.penglixun.com/tech/system/why_use_src_conf_server.html#comments</comments>
		<pubDate>Mon, 18 Jan 2010 05:32:41 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[操作系统]]></category>
		<category><![CDATA[源码]]></category>
		<category><![CDATA[编译]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/?p=894</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明网址: http://www.penglixun.com/tech/system/why_use_src_conf_server.html 为什么我喜欢采用源码编译来配置... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br>网址: http://www.penglixun.com/tech/system/why_use_src_conf_server.html </p>
<p></span>为什么我喜欢采用源码编译来配置服务器，张宴老师给出了很好的解释：</p>
<p><strong>“</strong> 之所以编译安装，而不采用RPM包安装，有以下几个方面的原因：<br />
1、编译安装的自由度很大，需要哪些功能模块，就编译哪些功能模块，用不到的可以不安装，需要哪些参数，就加上哪些差数，能够节省系统资源，充分发挥性能优势；<br />
2、一些自行开发的模块，或对程序源码作出的修改，必须通过编译安装才能实现；<br />
3、编译安装的程序配置起来很方便；<br />
4、我编译安装都是用SecureCRT等<acronym title="Secure Shell">SSH</acronym>客户端软件连上服务器，直接往里面一次粘贴多行安装语句，然后干别的事，所花的时间也不长。<br />
5、我编译安装软件的每一行步骤和整个流程，都会写入文档，交接起来很方便。<strong> ”</strong></p><h2  class="related_post_title">类似的文章</h2><ul class="related_post"><li>2010年01月18日 -- <a href="http://www.penglixun.com/tech/system/linux_compile_php_error.html" title="Linux下编译PHP的几种错误">Linux下编译PHP的几种错误</a> (1)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/tech/system/why_use_src_conf_server.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux下编译PHP的几种错误</title>
		<link>http://www.penglixun.com/tech/system/linux_compile_php_error.html</link>
		<comments>http://www.penglixun.com/tech/system/linux_compile_php_error.html#comments</comments>
		<pubDate>Mon, 18 Jan 2010 05:03:56 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[操作系统]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[编译]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/?p=890</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明网址: http://www.penglixun.com/tech/system/linux_compile_php_error.html Forcing buildconf buildconf: checking install... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br>网址: http://www.penglixun.com/tech/system/linux_compile_php_error.html </p>
<p></span>Forcing buildconf<br />
buildconf: checking installation…<br />
buildconf: autoconf version 2.65 (ok)<br />
buildconf: Your version of autoconf likely contains buggy cache code.<br />
Running vcsclean for you.<br />
To avoid this, install autoconf-2.13.<br />
Can’t figure out your VCS, not cleaning.<br />
rebuilding configure<br />
configure.in:492: warning: AC_CACHE_VAL(have_broken_glibc_fopen_append, …): suspicious cache-id, must contain _cv_ to be cached<br />
autoconf/general.m4:2013: AC_CACHE_VAL is expanded from…<br />
aclocal.m4:1736: PHP_BROKEN_GLIBC_FOPEN_APPEND is expanded from…<br />
ext/mbstring/config.m4:356: warning: AC_CACHE_VAL(cv_php_mbstring_stdarg, …): suspicious cache-id, must contain _cv_ to be cached<br />
autoconf/general.m4:2026: AC_CACHE_CHECK is expanded from…<br />
ext/mbstring/config.m4:205: PHP_MBSTRING_SETUP_MBREGEX is expanded from…<br />
ext/pdo_dblib/config.m4:71: warning: AC_CACHE_VAL(pdo_inc_path, …): suspicious cache-id, must contain _cv_ to be cached<br />
aclocal.m4:2754: PHP_CHECK_PDO_INCLUDES is expanded from…<br />
ext/pdo_firebird/config.m4:48: warning: AC_CACHE_VAL(pdo_inc_path, …): suspicious cache-id, must contain _cv_ to be cached<br />
ext/pdo_mysql/config.m4:160: warning: AC_CACHE_VAL(pdo_inc_path, …): suspicious cache-id, must contain _cv_ to be cached<br />
ext/pdo_oci/config.m4:211: warning: AC_CACHE_VAL(pdo_inc_path, …): suspicious cache-id, must contain _cv_ to be cached<br />
ext/pdo_odbc/config.m4:59: warning: AC_CACHE_VAL(pdo_inc_path, …): suspicious cache-id, must contain _cv_ to be cached<br />
ext/pdo_pgsql/config.m4:121: warning: AC_CACHE_VAL(pdo_inc_path, …): suspicious cache-id, must contain _cv_ to be cached<br />
ext/pdo_sqlite/config.m4:31: warning: AC_CACHE_VAL(pdo_inc_path, …): suspicious cache-id, must contain _cv_ to be cached<br />
ext/sqlite/config.m4:50: warning: AC_CACHE_VAL(pdo_inc_path, …): suspicious cache-id, must contain _cv_ to be cached<br />
ext/standard/config.m4:235: warning: AC_CACHE_VAL(php_can_support_proc_open, …): suspicious cache-id, must contain _cv_ to be cached<span id="more-890"></span><br />
configure.in:1347: warning: AC_CACHE_VAL(lt_prog_compiler_static_works, …): suspicious cache-id, must contain _cv_ to be cached<br />
aclocal.m4:3585: AC_LIBTOOL_LINKER_OPTION is expanded from…<br />
aclocal.m4:5597: _LT_AC_LANG_C_CONFIG is expanded from…<br />
aclocal.m4:5492: AC_LIBTOOL_LANG_C_CONFIG is expanded from…<br />
aclocal.m4:3109: AC_LIBTOOL_SETUP is expanded from…<br />
aclocal.m4:2967: _AC_PROG_LIBTOOL is expanded from…<br />
aclocal.m4:2947: AC_PROG_LIBTOOL is expanded from…<br />
configure.in:1347: warning: AC_CACHE_VAL(lt_prog_compiler_pic_works, …): suspicious cache-id, must contain _cv_ to be cached<br />
aclocal.m4:3548: AC_LIBTOOL_COMPILER_OPTION is expanded from…<br />
aclocal.m4:8133: AC_LIBTOOL_PROG_COMPILER_PIC is expanded from…<br />
configure.in:1347: warning: AC_CACHE_VAL(lt_prog_compiler_pic_works_CXX, …): suspicious cache-id, must contain _cv_ to be cached<br />
aclocal.m4:6549: _LT_AC_LANG_CXX_CONFIG is expanded from…<br />
aclocal.m4:5605: AC_LIBTOOL_LANG_CXX_CONFIG is expanded from…<br />
aclocal.m4:4737: _LT_AC_TAGCONFIG is expanded from…<br />
rebuilding main/php_config.h.in<br />
autoheader: WARNING: Using auxiliary files such as `acconfig.h’, `config.h.bot’<br />
autoheader: WARNING: and `config.h.top’, to define templates for `config.h.in’<br />
autoheader: WARNING: is deprecated and discouraged.<br />
autoheader:<br />
autoheader: WARNING: Using the third argument of `AC_DEFINE’ and<br />
autoheader: WARNING: `AC_DEFINE_UNQUOTED’ allows one to define a template without<br />
autoheader: WARNING: `acconfig.h’:<br />
autoheader:<br />
autoheader: WARNING:   AC_DEFINE([NEED_FUNC_MAIN], 1,<br />
autoheader:             [Define if a function `main' is needed.])<br />
autoheader:<br />
autoheader: WARNING: More sophisticated templates can also be produced, see the<br />
autoheader: WARNING: documentation.<br />
configure.in:492: warning: AC_CACHE_VAL(have_broken_glibc_fopen_append, …): suspicious cache-id, must contain _cv_ to be cached<br />
autoconf/general.m4:2013: AC_CACHE_VAL is expanded from…<br />
aclocal.m4:1736: PHP_BROKEN_GLIBC_FOPEN_APPEND is expanded from…<br />
ext/mbstring/config.m4:356: warning: AC_CACHE_VAL(cv_php_mbstring_stdarg, …): suspicious cache-id, must contain _cv_ to be cached<br />
autoconf/general.m4:2026: AC_CACHE_CHECK is expanded from…<br />
ext/mbstring/config.m4:205: PHP_MBSTRING_SETUP_MBREGEX is expanded from…<br />
ext/pdo_dblib/config.m4:71: warning: AC_CACHE_VAL(pdo_inc_path, …): suspicious cache-id, must contain _cv_ to be cached<br />
aclocal.m4:2754: PHP_CHECK_PDO_INCLUDES is expanded from…<br />
ext/pdo_firebird/config.m4:48: warning: AC_CACHE_VAL(pdo_inc_path, …): suspicious cache-id, must contain _cv_ to be cached<br />
ext/pdo_mysql/config.m4:160: warning: AC_CACHE_VAL(pdo_inc_path, …): suspicious cache-id, must contain _cv_ to be cached<br />
ext/pdo_oci/config.m4:211: warning: AC_CACHE_VAL(pdo_inc_path, …): suspicious cache-id, must contain _cv_ to be cached<br />
ext/pdo_odbc/config.m4:59: warning: AC_CACHE_VAL(pdo_inc_path, …): suspicious cache-id, must contain _cv_ to be cached<br />
ext/pdo_pgsql/config.m4:121: warning: AC_CACHE_VAL(pdo_inc_path, …): suspicious cache-id, must contain _cv_ to be cached<br />
ext/pdo_sqlite/config.m4:31: warning: AC_CACHE_VAL(pdo_inc_path, …): suspicious cache-id, must contain _cv_ to be cached<br />
ext/sqlite/config.m4:50: warning: AC_CACHE_VAL(pdo_inc_path, …): suspicious cache-id, must contain _cv_ to be cached<br />
ext/standard/config.m4:235: warning: AC_CACHE_VAL(php_can_support_proc_open, …): suspicious cache-id, must contain _cv_ to be cached<br />
configure.in:1347: warning: AC_CACHE_VAL(lt_prog_compiler_static_works, …): suspicious cache-id, must contain _cv_ to be cached<br />
aclocal.m4:3585: AC_LIBTOOL_LINKER_OPTION is expanded from…<br />
aclocal.m4:5597: _LT_AC_LANG_C_CONFIG is expanded from…<br />
aclocal.m4:5492: AC_LIBTOOL_LANG_C_CONFIG is expanded from…<br />
aclocal.m4:3109: AC_LIBTOOL_SETUP is expanded from…<br />
aclocal.m4:2967: _AC_PROG_LIBTOOL is expanded from…<br />
aclocal.m4:2947: AC_PROG_LIBTOOL is expanded from…<br />
configure.in:1347: warning: AC_CACHE_VAL(lt_prog_compiler_pic_works, …): suspicious cache-id, must contain _cv_ to be cached<br />
aclocal.m4:3548: AC_LIBTOOL_COMPILER_OPTION is expanded from…<br />
aclocal.m4:8133: AC_LIBTOOL_PROG_COMPILER_PIC is expanded from…<br />
configure.in:1347: warning: AC_CACHE_VAL(lt_prog_compiler_pic_works_CXX, …): suspicious cache-id, must contain _cv_ to be cached<br />
aclocal.m4:6549: _LT_AC_LANG_CXX_CONFIG is expanded from…<br />
aclocal.m4:5605: AC_LIBTOOL_LANG_CXX_CONFIG is expanded from…<br />
aclocal.m4:4737: _LT_AC_TAGCONFIG is expanded from…</p>
<p>貌似因为autoconf版本太高。</p>
<p>在debian下执行<br />
aptitude install autoconf2.13<br />
export PHP_AUTOCONF=/usr/bin/autoconf2.13<br />
export PHP_AUTOHEADER=/usr/bin/autoheader2.13<br />
然后再重新autoconf就行了。</p>
<p>64位下编译最好加上在 configure 时加参数 –with-libdir=lib64 指定使用64位库。</p><h2  class="related_post_title">类似的文章</h2><ul class="related_post"><li>2009年07月9日 -- <a href="http://www.penglixun.com/tech/program/add_database_module_for_php.html" title="为PHP添加数据库模块">为PHP添加数据库模块</a> (0)</li><li>2012年01月23日 -- <a href="http://www.penglixun.com/tech/database/case_about_innodb_faster_than_oracle.html" title="一个InnoDB性能超过Oracle的调优Case">一个InnoDB性能超过Oracle的调优Case</a> (1)</li><li>2010年08月27日 -- <a href="http://www.penglixun.com/tech/system/linux_cache_discovery.html" title="Linux Cache 机制探究">Linux Cache 机制探究</a> (1)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/tech/system/linux_compile_php_error.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>LAMP架构下的安全注意要点</title>
		<link>http://www.penglixun.com/tech/system/lamp_security.html</link>
		<comments>http://www.penglixun.com/tech/system/lamp_security.html#comments</comments>
		<pubDate>Sat, 09 Jan 2010 16:24:45 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[操作系统]]></category>
		<category><![CDATA[LAMP]]></category>
		<category><![CDATA[安全]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/?p=880</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明网址: http://www.penglixun.com/tech/system/lamp_security.html 我对安全方面也不是了解很多，最近遇到... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br>网址: http://www.penglixun.com/tech/system/lamp_security.html </p>
<p></span>我对安全方面也不是了解很多，最近遇到了安全方面的问题，查了一些资料，亲自试了试，选出一些比较重要的记录一下。</p>
<p>安全方面即将加入阿里云的<a title="刘博洋" href="http://twitter.com/Natural__Light">@Natural__Light</a>大牛给我演示过不少入侵的方法，算“资深”了，从在中学开始入侵学校网络，咱们大学里的那些破网站，<a title="刘博洋" href="http://twitter.com/Natural__Light">@Natural__Light</a>大牛玩一样进后台。</p>
<ol>
<li>如果要考虑安全问题，就必须有一个假设：<span style="color: #ff0000;">一切用户输入的内容都是不安全的，一切参数的传递都是不安全的</span>。入侵者可能利用每一个我们假设是安全的地方。</li>
<li>Linux方面
<ul>
<li>限制用户账号，开发和运维分开。</li>
<li><acronym title="Secure Shell">SSH</acronym>登陆必须限制主机来源，切忌允许全部<acronym title="Internet Protocol">IP</acronym>登陆，最好port也要修改。</li>
<li>使用iptables限制端口出入和<acronym title="Internet Protocol">IP</acronym>，内部系统只能允许内部<acronym title="Internet Protocol">IP</acronym>。</li>
<li>注意为不同的用户甚至不同的功能区分不同的账号和用户组。</li>
<li>为关键文件和目录一定要设置好权限，千万不能777，配合用户和分组保证只有需要的人有需要的权限，尤其是/etc下的。<span id="more-880"></span></li>
</ul>
</li>
<li>Apache方面
<ul>
<li>使用专门的账号和用户组来启动Apache。</li>
<li>不同功能和站点的配置文件最好拆分为不同的文件。</li>
<li>设置ServerSignature Off和ServerTokens ProductOnly，防止服务器广播敏感信息和<acronym title="HyperText Transfer Protocol">HTTP</acronym>头透露关键信息。</li>
<li>禁止浏览目录。</li>
<li>只监听指定的<acronym title="Internet Protocol">IP</acronym>和端口。</li>
<li>必要时可以修改代码伪装服务器版本信息。</li>
<li>为每个目录建立.htaccss文件保护。</li>
<li>只允许特定常用的User-Agent访问。</li>
<li>利用iptables或Nginx做反向代理，过滤DDOS攻击。</li>
</ul>
</li>
<li>MySQL方面
<ul>
<li>必须设置MySQL目录的权限，限制访问。</li>
<li>必须使用一个独立的用户和用户组，没有Shell，也不能运行其他程序。</li>
<li>必须删除无用户名账户，必须修改root账户密码，并且要限制主机来源。</li>
<li>必须删除test库，这个库任何人都可以建表，危险。</li>
<li>为每个功能单独建账号，使用不同的密码，限制主机来源，只给需要的权限。</li>
<li>细化权限粒度，不要给任何账户不必要的权限。</li>
</ul>
</li>
<li><acronym title="Pre-Hypertext Processing">PHP</acronym>方面
<ul>
<li>一定要分析任何用户输入或者传递的参数，过滤其中的危险字符。</li>
<li>使用系统自带的过滤函数一定要了解其机制，避免对方利用单/多字符集的方法绕过。</li>
<li>在前端限制特殊字符被输入，接到输入后还需要再次进行过滤。</li>
<li>系统的错误信息必须被屏蔽或者关闭，错误可以跳转。</li>
<li>禁止采用root账户连接数据库。</li>
<li>用专门的账户运行<acronym title="Pre-Hypertext Processing">PHP</acronym>。</li>
</ul>
</li>
</ol>
<p>总的来说最重要的就是：<span style="color: #ff0000;">以最低粒度控制权限，过滤任何用户可以修改的进入系统的内容</span>。</p><h2  class="related_post_title">类似的文章</h2><ul class="related_post"><li>2009年10月13日 -- <a href="http://www.penglixun.com/life/diary/recommend_one_powerful_person.html" title="推荐一位牛人">推荐一位牛人</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/tech/system/lamp_security.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux下压缩/解压缩命令</title>
		<link>http://www.penglixun.com/tech/system/linux_compress_uncompress.html</link>
		<comments>http://www.penglixun.com/tech/system/linux_compress_uncompress.html#comments</comments>
		<pubDate>Thu, 31 Dec 2009 07:37:05 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[操作系统]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[压缩]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/?p=869</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明网址: http://www.penglixun.com/tech/system/linux_compress_uncompress.html .tar 解包： tar xvf FileName.tar 打包... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br>网址: http://www.penglixun.com/tech/system/linux_compress_uncompress.html </p>
<p></span>.tar<br />
解包： tar xvf FileName.tar<br />
打包：tar cvf FileName.tar DirName<br />
（注：tar是打包，不是压缩，适合将很多小文件备份）<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
.gz<br />
解压1：gunzip FileName.gz<br />
解压2：gzip -d FileName.gz<br />
压缩：gzip FileName<br />
.tar.gz<br />
解压：tar zxvf FileName.tar.gz<br />
压缩：tar zcvf FileName.tar.gz DirName<br />
（一般常用的就是这个了）</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
<span id="more-869"></span> .bz2<br />
解压1：bzip2 -d FileName.bz2<br />
解压2：bunzip2 FileName.bz2<br />
压缩： bzip2 -z FileName<br />
.tar.bz2<br />
解压：tar jxvf FileName.tar.bz2<br />
压缩：tar jcvf FileName.tar.bz2 DirName<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
.Z<br />
解压：uncompress FileName.Z<br />
压缩：compress FileName<br />
.tar.Z<br />
解压：tar Zxvf FileName.tar.Z<br />
压缩：tar Zcvf FileName.tar.Z DirName<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
.tgz<br />
解压：tar zxvf FileName.tgz<br />
.tar.tgz<br />
解压：tar zxvf FileName.tar.tgz<br />
压缩：tar zcvf FileName.tar.tgz FileName<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
.zip<br />
解压：unzip FileName.zip<br />
压缩：zip FileName.zip DirName<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
.rar<br />
解压：rar a FileName.rar<br />
压缩：rar e FileName.rar<br />
（需要下一个rar程序）<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
.rpm<br />
解包：rpm2cpio FileName.rpm | cpio -div<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p><h2  class="related_post_title">类似的文章</h2><ul class="related_post"><li>2012年01月23日 -- <a href="http://www.penglixun.com/tech/database/case_about_innodb_faster_than_oracle.html" title="一个InnoDB性能超过Oracle的调优Case">一个InnoDB性能超过Oracle的调优Case</a> (1)</li><li>2010年08月27日 -- <a href="http://www.penglixun.com/tech/system/linux_cache_discovery.html" title="Linux Cache 机制探究">Linux Cache 机制探究</a> (1)</li><li>2010年08月10日 -- <a href="http://www.penglixun.com/tech/system/how_to_calc_load_cpu.html" title="Load和CPU利用率是如何算出来的">Load和CPU利用率是如何算出来的</a> (5)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/tech/system/linux_compress_uncompress.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>gFTP目录乱码问题</title>
		<link>http://www.penglixun.com/tech/system/gftp_dir_garbled.html</link>
		<comments>http://www.penglixun.com/tech/system/gftp_dir_garbled.html#comments</comments>
		<pubDate>Sat, 19 Dec 2009 17:12:16 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[操作系统]]></category>
		<category><![CDATA[gFTP]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/?p=846</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明网址: http://www.penglixun.com/tech/system/gftp_dir_garbled.html 看MySQL的文档有些累了，想下载个电影... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br>网址: http://www.penglixun.com/tech/system/gftp_dir_garbled.html </p>
<p></span>看MySQL的文档有些累了，想下载个电影看看，遂上学校<acronym title="File Transfer Protocol">FTP</acronym>。<br />
看了看Linux下<acronym title="File Transfer Protocol">FTP</acronym>客户端的比较，最终选了gFTP，虽然ftp命令也能下，毕竟电脑是拿来用的不是来装B的，能省事的还是省事点。<br />
结果登录上学校的<acronym title="File Transfer Protocol">FTP</acronym>，gFTP中目录全都不显示，遂Google之。<br />
有的人说改/usr/bin/gftp脚本，加入export LANG=zh_CN.GBK，并且用locale-gen zh_CN.GBK，不过经我实测是不行的。在日志里看获取的目录是可以正常显示，但是界面里还是不行，有的人说是gtk1和gtk2的问题之类的，我觉得应该是扯淡。<br />
然后又看了些解决方案，说locale-gen zh_CN，光GBK没用，然后改.gftp/gftprc，在remote_charset加入gbk,gb2312,utf8等字符集，并且把export LANG改为了zh_CN，实验之，一切OK。<br />
整理步骤就是：<br />
locale-gen zh_CN （我不确定locale-gen zh_CN.GBK是否也必要）<br />
在/usr/bin/gftp中加入export LANG=zh_CN。（我不确定在.gftp/gftprc中的remote_charset加入gbk等是否必要）<br />
遇到类似情况，自己尝试吧，毕竟每个人情况可能不一样，我这里给出的是我已经解决的，我的系统是Ubuntu 9.10 64bit Gnome。</p>
<p>下载《世界大战》ing，最近被某人带的对2012，宇宙，外星人之类的东西很感兴趣，额……好像一致很感兴趣……</p><h2  class="related_post_title">类似的文章</h2><ul class="related_post"><li>2012年01月23日 -- <a href="http://www.penglixun.com/tech/database/case_about_innodb_faster_than_oracle.html" title="一个InnoDB性能超过Oracle的调优Case">一个InnoDB性能超过Oracle的调优Case</a> (1)</li><li>2010年08月27日 -- <a href="http://www.penglixun.com/tech/system/linux_cache_discovery.html" title="Linux Cache 机制探究">Linux Cache 机制探究</a> (1)</li><li>2010年08月10日 -- <a href="http://www.penglixun.com/tech/system/how_to_calc_load_cpu.html" title="Load和CPU利用率是如何算出来的">Load和CPU利用率是如何算出来的</a> (5)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/tech/system/gftp_dir_garbled.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>主动请求式与被动探测式监控的比较</title>
		<link>http://www.penglixun.com/tech/system/active_request_and_passive_detection_monitoring_compare.html</link>
		<comments>http://www.penglixun.com/tech/system/active_request_and_passive_detection_monitoring_compare.html#comments</comments>
		<pubDate>Thu, 17 Dec 2009 15:32:44 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[操作系统]]></category>
		<category><![CDATA[SNMP]]></category>
		<category><![CDATA[监控]]></category>
		<category><![CDATA[监控宝]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/?p=742</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明网址: http://www.penglixun.com/tech/system/active_request_and_passive_detection_monitoring_compare.html 前些天与... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br>网址: http://www.penglixun.com/tech/system/active_request_and_passive_detection_monitoring_compare.html </p>
<p></span>前些天与监控宝的同志谈起监控的两种模式，比较有意思，记录下来。</p>
<p>我一直比较赞同的是主动请求式的监控模式，主要原因是被动探测会给监控结点带来很大的压力，就Cacti而言，用Spine轮询，共35个设备，每分钟轮询一次，能吃掉我35%的CPU。<br />
相比之下，通过客户机主动发送请求给监控机的Ganglia，占用资源就非常小。一台监控机估计挂200台客户机监控不是问题。<br />
区别就在于，主动请求式是客户机把自己的监控信息主动发送给监控机，监控机只要接收这些信息处理即可。<br />
被动探测式是监控机把监控请求发送到客户机，客户机接到请求把需要的监控信息返回给监控结点。<br />
所以，被动探测式会给监控机带来很大的压力，因为它要不断的发请求去获取信息。<br />
<span id="more-742"></span></p>
<p>但是监控宝的同志做了个很好的比方，让我想法有了些变化。<br />
监控机好比警察，客户机好比犯人。<br />
不能因为警察忙，就不管犯人，让犯人主动报告自己的情况。<br />
如果犯人突然没信息了，警察就不知道犯人是死了还是跑了。<br />
并且如果警察调走了，犯人不知道，这一群犯人就不知道向谁报告了。<br />
但是经常也不能老去一直问犯人的情况，那样他的工作效率就太低了。<br />
所以二者各有好处。</p>
<p>首先，警察很忙的时候，让犯人主动报告自己的情况，他记着就行。<br />
但是，一旦犯人在规定的时间没报告，警察就要主动去联系了，看看犯人到底是死了还是跑了。</p>
<p>还原到监控中，就是主动与被动两种方式结合起来。<br />
一般情况下，让客户机比较高频地自己报告情况情况给监控机，同时，监控机间隔比较长的像客户机主动发送请求，检查客户机是否存活。<br />
同时，一旦监控机在规定的时间内没收到客户机的信息，就要像客户机发请求去轮询，确认客户机的状态。</p>
<p>主动和被动在合适的时候都有合理的用处，像手机就是主动向基站报告自己加入，雷达又是向被监控区域发送探测信号。<br />
任何方法都有其存在的理由，没有最好没有最坏，只有最合适！</p><h2  class="related_post_title">类似的文章</h2><ul class="related_post"><li>2010年09月12日 -- <a href="http://www.penglixun.com/tech/jiankongbao.html" title="中小站点的监控利器——监控宝">中小站点的监控利器——监控宝</a> (1)</li><li>2010年01月26日 -- <a href="http://www.penglixun.com/tech/program/mysql_realtime_status_moniter_mystat.html" title="自己写的MySQL实时监控脚本&#8211;mystat">自己写的MySQL实时监控脚本&#8211;mystat</a> (0)</li><li>2009年12月13日 -- <a href="http://www.penglixun.com/tech/system/open_snmpd_in_debian.html" title="Debian下开启snmpd">Debian下开启snmpd</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/tech/system/active_request_and_passive_detection_monitoring_compare.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[转] memcached完全剖析</title>
		<link>http://www.penglixun.com/tech/system/memcached_complete_analyze.html</link>
		<comments>http://www.penglixun.com/tech/system/memcached_complete_analyze.html#comments</comments>
		<pubDate>Tue, 15 Dec 2009 12:59:45 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[操作系统]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Memcached]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/?p=649</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明网址: http://www.penglixun.com/tech/system/memcached_complete_analyze.html 版权声明：可以任意转载，但转... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br>网址: http://www.penglixun.com/tech/system/memcached_complete_analyze.html </p>
<p></span><strong>版权声明：可以任意转载，但转载时必须标明原作者charlee、原始链接<a href="http://tech.idv2.com/2008/08/17/memcached-pdf/">http://tech.idv2.com/2008/08/17/memcached-pdf/</a>以及本声明。</strong></p>
<p>作者已经做成<acronym title="Portable Document Format">PDF</acronym>版，我提供一个下载副本，上面的链接里也有，下面列出目录，有兴趣的可以下载。</p>
<p>下载地址：Note: There is a file embedded within this post, please visit this post to download the file.</p>
<p><span id="more-649"></span><br />
第1 章 memcached的基础&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;..5<br />
1.1 memcached是什么？&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;5<br />
1.2 memcached的特征&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.6<br />
协议简单&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;6<br />
基于libevent的事件处理&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.6<br />
内置内存存储方式&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;6<br />
memcached不互相通信的分布式&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;6<br />
1.3 安装memcached&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.7<br />
memcached的安装&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;7<br />
memcached的启动&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;8<br />
1.4 用客户端连接&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;8<br />
1.5 使用Cache::Memcached&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.9<br />
使用Cache::Memcached连接memcached&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;..9<br />
保存数据&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.10<br />
获取数据&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.10<br />
删除数据&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.10<br />
增一和减一操作&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;..10<br />
1.6 总结&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.11</p>
<p>第2章 理解memcached的内存存储&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.12<br />
2.1 Slab Allocation机制：整理内存以便重复使用&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.12<br />
Slab Allocation的主要术语&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;..13<br />
2.2 在Slab中缓存记录的原理&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.13<br />
2.3 Slab Allocator的缺点&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.13<br />
2.4 使用Growth Factor进行调优&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;14<br />
2.5 查看memcached的内部状态&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;15<br />
2.6 查看slabs的使用状况&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;..16<br />
2.7 总结&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.17</p>
<p>第3 章 memcached的删除机制和发展方向&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;..18<br />
3.1 memcached在数据删除方面有效利用资源&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.18<br />
数据不会真正从memcached中消失&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;..18<br />
Lazy Expiration&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;18<br />
3.2 LRU：从缓存中有效删除数据的原理&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;18<br />
3.3 memcached的最新发展方向&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.18<br />
关于二进制协议&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;..19<br />
二进制协议的格式&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.19<br />
HEADER中引人注目的地方&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;..20<br />
3.4 外部引擎支持&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;20<br />
外部引擎支持的必要性&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;..20<br />
简单<acronym title="Application Programming Interface">API</acronym>设计的成功的关键&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;21<br />
重新审视现在的体系&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;21<br />
3.5 总结&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;22</p>
<p>第4 章 memcached的分布式算法&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;23<br />
4.1 memcached的分布式&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.23<br />
memcached的分布式是什么意思？&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;23<br />
4.2 Cache::Memcached的分布式方法&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.25<br />
根据余数计算分散&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.25<br />
根据余数计算分散的缺点&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.26<br />
4.3 Consistent Hashing&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;..27<br />
Consistent Hashing的简单说明&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;..27<br />
支持Consistent Hashing的函数库&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;29<br />
4.4 总结&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;29</p>
<p>第5 章 memcached的应用和兼容程序&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.30<br />
5.1 mixi案例研究&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.30<br />
服务器配置和数量&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.30<br />
memcached进程&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;..31<br />
memcached使用方法和客户端&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;..31<br />
5.2 memcached应用经验&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.32<br />
通过daemontools启动&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.33<br />
监视&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;33<br />
memcached的性能&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.33<br />
5.3 兼容应用程序&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;35<br />
Tokyo Tyrant案例&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;35</p><h2  class="related_post_title">类似的文章</h2><ul class="related_post"><li>2009年11月17日 -- <a href="http://www.penglixun.com/tech/system/configure_all_function_cacti.html" title="配置全功能Cacti">配置全功能Cacti</a> (0)</li><li>2012年01月23日 -- <a href="http://www.penglixun.com/tech/database/case_about_innodb_faster_than_oracle.html" title="一个InnoDB性能超过Oracle的调优Case">一个InnoDB性能超过Oracle的调优Case</a> (1)</li><li>2010年08月27日 -- <a href="http://www.penglixun.com/tech/system/linux_cache_discovery.html" title="Linux Cache 机制探究">Linux Cache 机制探究</a> (1)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/tech/system/memcached_complete_analyze.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Buffer与Cache</title>
		<link>http://www.penglixun.com/tech/system/buffer_and_cache_diff.html</link>
		<comments>http://www.penglixun.com/tech/system/buffer_and_cache_diff.html#comments</comments>
		<pubDate>Mon, 14 Dec 2009 09:17:54 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[操作系统]]></category>
		<category><![CDATA[Buffer]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/?p=638</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明网址: http://www.penglixun.com/tech/system/buffer_and_cache_diff.html 今天Twitter上关于Buffer和Cache讨论得... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br>网址: http://www.penglixun.com/tech/system/buffer_and_cache_diff.html </p>
<p></span>今天Twitter上关于Buffer和Cache讨论得蛮火的，被各种说话一搅和，有点乱了，就干脆整理一下。<br />
首先从翻译上，Buffer应该翻译为“缓冲”，Cache应该翻译为“缓存”，两个完全不是一个东西。<br />
在硬件这一层看，Buffer应该为内存，Cache为CPU集成的告诉缓存。<br />
Buffer为了让不同速度的设备能够同步，建立的一个缓冲区域，写进Buffer的数据是为了从中拿出写入其他设备。<br />
Cache是为了提高读取速度，将经常或马上需要的数据预读到缓存中，写进Cache的数据是为了其他设备从中去读取。<br />
从软件这一层来说，Buffer是块设备的缓冲，Cache是文件系统的缓存。以Linux为例，<br />
Buffer(Buffer Cache)以块形式缓冲了块设备的操作，定时或手动的同步到硬盘，它是为了缓冲写操作然后一次性将很多改动写入硬盘，避免频繁写硬盘，提高写入效率。<br />
Cache(Page Cache)以页面形式缓存了文件系统的文件，给需要使用的程序读取，它是为了给读操作提供缓冲，避免频繁读硬盘，提高读取效率。<br />
总而言之，Buffer里面的东西是为了写到别处去，Cache里面的东西是为了给别处读。<br />
我的理解就是这样，欢迎大牛拍砖～</p><h2  class="related_post_title">类似的文章</h2><ul class="related_post"><li>2010年08月27日 -- <a href="http://www.penglixun.com/tech/system/linux_cache_discovery.html" title="Linux Cache 机制探究">Linux Cache 机制探究</a> (1)</li><li>2010年06月22日 -- <a href="http://www.penglixun.com/tech/database/database_algorithm_and_data_structure_cache_buffer_lock.html" title="数据库算法与数据结构——Cache&#038;Buffer&#038;Lock">数据库算法与数据结构——Cache&#038;Buffer&#038;Lock</a> (1)</li><li>2009年10月29日 -- <a href="http://www.penglixun.com/tech/system/the_diffrents_of_page_cache_and_buffer_cache.html" title="Page Cache和Buffer Cache的区别">Page Cache和Buffer Cache的区别</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/tech/system/buffer_and_cache_diff.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Debian下开启snmpd</title>
		<link>http://www.penglixun.com/tech/system/open_snmpd_in_debian.html</link>
		<comments>http://www.penglixun.com/tech/system/open_snmpd_in_debian.html#comments</comments>
		<pubDate>Sun, 13 Dec 2009 14:47:29 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[操作系统]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[SNMP]]></category>
		<category><![CDATA[snmpd]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/?p=629</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明网址: http://www.penglixun.com/tech/system/open_snmpd_in_debian.html 今天想在监控宝搞下我的网站的监控... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br>网址: http://www.penglixun.com/tech/system/open_snmpd_in_debian.html </p>
<p></span>今天想在监控宝搞下我的网站的监控，结果SNMP怎么都获取不到信息，遂Google之。<br />
原来是Debian默认把snmpd设置为只能本地访问，于是改动之。</p>
<p>修改 /etc/default/snmpd。让snmpd监听所有的网卡（默认只监听回环地址127.0.0.1，这种状况下只能本机访问snmp信息）</p>
<p># snmpd options (use syslog, close stdin/out/err).<br />
#SNMPDOPTS=&#8217;-Lsd -Lf /dev/null -u snmp -I -smux -p /var/run/snmpd.pid 127.0.0.1&#8242;<br />
SNMPDOPTS=&#8217;-Lsd -Lf /dev/null -u snmp -I -smux -p /var/run/snmpd.pid&#8217;</p><h2  class="related_post_title">类似的文章</h2><ul class="related_post"><li>2009年12月17日 -- <a href="http://www.penglixun.com/tech/system/active_request_and_passive_detection_monitoring_compare.html" title="主动请求式与被动探测式监控的比较">主动请求式与被动探测式监控的比较</a> (0)</li><li>2009年12月13日 -- <a href="http://www.penglixun.com/tech/system/debian_aptitude_usage.html" title="aptitude命令的使用">aptitude命令的使用</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/tech/system/open_snmpd_in_debian.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>aptitude命令的使用</title>
		<link>http://www.penglixun.com/tech/system/debian_aptitude_usage.html</link>
		<comments>http://www.penglixun.com/tech/system/debian_aptitude_usage.html#comments</comments>
		<pubDate>Sun, 13 Dec 2009 10:54:42 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[操作系统]]></category>
		<category><![CDATA[apt-get]]></category>
		<category><![CDATA[aptitude]]></category>
		<category><![CDATA[Debian]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/?p=602</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明网址: http://www.penglixun.com/tech/system/debian_aptitude_usage.html 因为VPS用的Debian 5.0 64bit系统，在查... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br>网址: http://www.penglixun.com/tech/system/debian_aptitude_usage.html </p>
<p></span>因为VPS用的Debian 5.0 64bit系统，在查资料的时候发现不少人都推荐一个aptitude命令来代替apt-get，试用了一下删除依赖包的时候aptitude要比apt-get好，虽然apt-get也有autoremove选项，不过还是决定使用aptitude来管理包。不过发现aptitude和apt-get不能混用，要不然互相都不知道对方做了什么。</p>
<p>aptitude 与 apt-get 一样，是 Debian 及其衍生系统中功能极其强大的包管理工具。与 apt-get 不同的是，aptitude 在处理依赖问题上更佳一些。举例来说，aptitude 在删除一个包时，会同时删除本身所依赖的包。这样，系统中不会残留无用的包，整个系统更为干净。</p>
<table border="0">
<tbody>
<tr>
<td>命令</td>
<td>作用</td>
</tr>
<tr>
<td>aptitude update</td>
<td>更新可用的包列表</td>
</tr>
<tr>
<td>aptitude upgrade</td>
<td>升级可用的包</td>
</tr>
<tr>
<td>aptitude dist-upgrade</td>
<td>将系统升级到新的发行版</td>
</tr>
<tr>
<td>aptitude install pkgname</td>
<td>安装包</td>
</tr>
<tr>
<td>aptitude remove pkgname</td>
<td>删除包</td>
</tr>
<tr>
<td>aptitude purge pkgname</td>
<td>删除包及其配置文件</td>
</tr>
<tr>
<td>aptitude search string</td>
<td>搜索包</td>
</tr>
<tr>
<td>aptitude show pkgname</td>
<td>显示包的详细信息</td>
</tr>
<tr>
<td>aptitude clean</td>
<td>删除下载的包文件</td>
</tr>
<tr>
<td>aptitude autoclean</td>
<td>仅删除过期的包文件</td>
</tr>
</tbody>
</table><h2  class="related_post_title">类似的文章</h2><ul class="related_post"><li>2009年12月13日 -- <a href="http://www.penglixun.com/tech/system/open_snmpd_in_debian.html" title="Debian下开启snmpd">Debian下开启snmpd</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/tech/system/debian_aptitude_usage.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nginx的502错误</title>
		<link>http://www.penglixun.com/tech/system/fix_nginx_502_bad_gateway.html</link>
		<comments>http://www.penglixun.com/tech/system/fix_nginx_502_bad_gateway.html#comments</comments>
		<pubDate>Mon, 07 Dec 2009 16:45:49 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[操作系统]]></category>
		<category><![CDATA[502]]></category>
		<category><![CDATA[Nginx]]></category>

		<guid isPermaLink="false">http://blog.penglixun.com/?p=569</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明网址: http://www.penglixun.com/tech/system/fix_nginx_502_bad_gateway.html 重启服务器后发现Nginx在我的WordP... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br>网址: http://www.penglixun.com/tech/system/fix_nginx_502_bad_gateway.html </p>
<p></span>重启服务器后发现Nginx在我的WordPress报502 Bad Gateway错误。<br />
查了好久，以为是nginx.conf或者php-fpm.conf的错，突然想起来，好像哪里看到说php.ini中memory_limit设低了会出错，<br />
修改了php.ini的memory_limit为64M，重启nginx，发现真好了~<br />
原来是<acronym title="Pre-Hypertext Processing">PHP</acronym>的内存不足了。<br />
360M内存的服务器，扛这点应用应该OK~</p><h2  class="related_post_title">类似的文章</h2><ul class="related_post"><li>2009年07月15日 -- <a href="http://www.penglixun.com/tech/system/nginx_php_fastcgi_better_apache.html" title="Nginx 0.7.x + PHP 5.2.10（FastCGI）搭建胜过Apache十倍的Web服务器">Nginx 0.7.x + PHP 5.2.10（FastCGI）搭建胜过Apache十倍的Web服务器</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/tech/system/fix_nginx_502_bad_gateway.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>配置全功能Cacti</title>
		<link>http://www.penglixun.com/tech/system/configure_all_function_cacti.html</link>
		<comments>http://www.penglixun.com/tech/system/configure_all_function_cacti.html#comments</comments>
		<pubDate>Tue, 17 Nov 2009 08:48:43 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[操作系统]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Cacti]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Memcached]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Nigix]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/PLX/Blog/?p=535</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明网址: http://www.penglixun.com/tech/system/configure_all_function_cacti.html 今天终于配置好了Cacti，加入... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br>网址: http://www.penglixun.com/tech/system/configure_all_function_cacti.html </p>
<p></span>今天终于配置好了Cacti，加入了MySQL/Linux/Apache/Memcached/Nigix模板。<br />
主要遇到的一个问题是修改轮询时间，默认5分钟，我想改成1分钟。<br />
要修改的地方是/etc/cron.d/cacti，改成1分钟间隔，*/<span style="color: #ff0000;">1 </span>* * * * root php /var/www/cacti/poller.php &amp;&gt;/dev/null<br />
然后最好先设置好轮询间隔再导入模板，这样可以在导入的时候把模板的间隔也改掉，否则要手动去改。<br />
修改了轮询时间需要重建轮询索引，最好还要关闭所有的设备再启动，怕有轮询器还没关闭。</p>
<p>过程很多地方有了：<br />
1062错误的解决方法：</p>
<p>http://yadayadayada.nl/archives/2009/04/000779-tuning_cacti_with_the_spine_poller_the_solution.html</p>
<p>http://yadayadayada.nl/archives/2008/11/000750-tuning_cacti_with_the_spine_poller_mysql_error_1062_.html</p>
<p>采用<acronym title="Secure Shell">SSH</acronym>方式监控：http://code.google.com/p/mysql-cacti-templates/wiki/SSHBasedTemplates<br />
MySQL模板安装方法：http://xok.la/2009/05/cacti_mysql_monitor.html<br />
Cacti源代码安装方法：http://www.askwan.com/post/48/<br />
Cacti中文版安装方法：http://hi.baidu.com/%C2%ED%B3%A4%D5%F72008/blog/item/566cbb440ac6742fcefca347.html</p><h2  class="related_post_title">类似的文章</h2><ul class="related_post"><li>2012年01月23日 -- <a href="http://www.penglixun.com/tech/database/case_about_innodb_faster_than_oracle.html" title="一个InnoDB性能超过Oracle的调优Case">一个InnoDB性能超过Oracle的调优Case</a> (1)</li><li>2009年12月15日 -- <a href="http://www.penglixun.com/tech/system/memcached_complete_analyze.html" title="[转] memcached完全剖析">[转] memcached完全剖析</a> (0)</li><li>2009年10月25日 -- <a href="http://www.penglixun.com/tech/database/mysql_gui_tool_in_linux.html" title="MySQL GUI Tool在Linux下运行">MySQL GUI Tool在Linux下运行</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/tech/system/configure_all_function_cacti.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>安装Sysbench</title>
		<link>http://www.penglixun.com/tech/system/install_sysbench.html</link>
		<comments>http://www.penglixun.com/tech/system/install_sysbench.html#comments</comments>
		<pubDate>Mon, 09 Nov 2009 04:57:30 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[操作系统]]></category>
		<category><![CDATA[sysbench]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/PLX/Blog/?p=524</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明网址: http://www.penglixun.com/tech/system/install_sysbench.html 在NinGoo大牛博客上看到了这个性能测试... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br>网址: http://www.penglixun.com/tech/system/install_sysbench.html </p>
<p></span>在NinGoo大牛博客上看到了这个性能测试工具，就拿下来试试，不过编译的时候遇到了些问题。</p>
<p>出现类似下面的错误</p>
<p><span style="font-size: medium;"><br />
<span style="color: #ff4500;"><br />
../libtool: line 2412: Xsysbench: command not found<br />
../libtool: line 2547: X-lmysqlclient_r: command not found<br />
../libtool: line 2547: X-lz: command not found<br />
../libtool: line 2547: X-lcrypt: command not found<br />
</span><br />
</span></p>
<p>经查只要执行./autogen.sh再进行configure就行了。</p>
<p>当出现：<br />
<span style="font-size: medium;"><br />
<span style="color: #ff4500;"><br />
FATAL: unable to connect to MySQL server, aborting&#8230;<br />
FATAL: error 1049: Unknown database &#8216;test&#8217;<br />
FATAL: failed to connect to database server!<br />
</span><br />
</span></p>
<p>只需要指定&#8211;mysql-db=test（一个已存在的数据库）就可以了。</p>
<p>参考文章：</p>
<p>http://www.ningoo.net/html/2009/performance_test_tool_sysbench.html</p>
<p>http://cqfish.blog.51cto.com/622299/159604</p><h2  class="related_post_title">随机显示文章</h2><ul class="related_post"><li>2011年01月6日 -- <a href="http://www.penglixun.com/tech/database/icc_static_compile_percona.html" title="ICC静态编译Percona">ICC静态编译Percona</a> (9)</li><li>2010年03月7日 -- <a href="http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-03-07.html" title="每周推特 2010-03-07">每周推特 2010-03-07</a> (0)</li><li>2009年10月13日 -- <a href="http://www.penglixun.com/tech/database/libpthread_problem_in_install_rac.html" title="装RAC中libpthread.so.0的问题">装RAC中libpthread.so.0的问题</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/tech/system/install_sysbench.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

