{"id":291,"date":"2016-03-29T15:59:18","date_gmt":"2016-03-29T07:59:18","guid":{"rendered":"http:\/\/blog.droidking.com\/?p=291"},"modified":"2016-05-16T15:51:30","modified_gmt":"2016-05-16T07:51:30","slug":"%e4%b8%baubuntu-linux%e5%88%9b%e5%bb%baswap%e5%88%86%e5%8c%ba","status":"publish","type":"post","link":"http:\/\/droidking.com\/?p=291","title":{"rendered":"\u4e3aUbuntu Linux\u521b\u5efaSwap\u5206\u533a"},"content":{"rendered":"<p>\u524d\u4e0d\u4e45\u5728Amazon\u8d2d\u4e70\u4e86\u4e00\u53f0EC2\u670d\u52a1\u5668\u8fd0\u884cWordPress\uff0c\u914d\u7f6e\u4e3a\u53cc\u6838CPU\uff0c\u5185\u5b581G\u3002\u8fd0\u884c\u4e86\u4e00\u6bb5\u65f6\u95f4\u540e\uff0c\u53d1\u73b0mysql\u7ecf\u5e38\u5d29\u6e83\u3002\u68c0\u67e5mysql\u7684error.log\u53d1\u73b0\uff0c\u5d29\u6e83\u524d\u6700\u540e\u4e00\u6761\u65e5\u5fd7\u662f\uff1a<\/p>\n<pre>160328 16:50:26 InnoDB: Completed initialization of buffer pool\r\n160328 16:50:26 InnoDB: Fatal error: cannot allocate memory for the buffer pool\r\n160328 16:50:26 [ERROR] Plugin 'InnoDB' init function returned error.\r\n160328 16:50:26 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.\r\n160328 16:50:26 [ERROR] Unknown\/unsupported storage engine: InnoDB\r\n160328 16:50:26 [ERROR] Aborting<\/pre>\n<p class=\"p1\">\u56e0\u4e3a\u7f51\u7ad9\u8bbf\u95ee\u91cf\u6bd4\u8f83\u5927\uff0c\u63a8\u6d4b\u53ef\u80fd\u662f\u7cfb\u7edf\u5185\u5b58\u4e0d\u8db3\u5bfc\u81f4\u7684\u3002\u4f7f\u7528\u4e0b\u9762\u7684\u547d\u4ee4\u67e5\u770b\u4e86\u4e00\u4e0b\uff0c\u53d1\u73b0apache\u5df2\u7ecf\u4f7f\u7528\u4e8660%\u591a\u7684\u5185\u5b58\uff08\u603b\u5185\u5b58\u4e3a1G\uff09\u3002<\/p>\n<pre class=\"p1\"><span class=\"s1\">$ ps -ylC apache2 | awk '{x += $8;y += 1} END {print \"Total (MB): \"x\/1024; print \"Average (MB): \"x\/((y-1)*1024)}'\r\n\r\n<\/span><span class=\"s1\">Total (MB): 622.996\r\n<\/span><span class=\"s1\">Average (MB): 14.8332<\/span><\/pre>\n<p>apache\u3001mysql\u90fd\u662f\u5403\u5185\u5b58\u7684\u5927\u6237\uff0c1G\u5c4b\u91cc\u5185\u5b58\u663e\u7136\u4e0d\u591f\u7528\u4e86\u3002\u4f7f\u7528swapon\u67e5\u770b\u4ea4\u6362\u6587\u4ef6\u72b6\u6001\uff1a<\/p>\n<pre class=\"code-pre \"><code>$ sudo swapon -s\r\n\r\n<\/code><code>Filename                Type        Size    Used    Priority<\/code><\/pre>\n<p>OMG\uff0c\u7adf\u7136\u6ca1\u6709\u3002\u3002\u3002\u90a3\u5c31\u521b\u5efa\u4e00\u4e2a\u3002<\/p>\n<p>\u5148\u521b\u5efa\u4e00\u4e2a4G\u7684\u6587\u4ef6\uff1a<\/p>\n<pre>$ sudo dd if=\/dev\/zero of=\/swapfile bs=1M count=4000\r\n4000+0 records in\r\n4000+0 records out\r\n4194304000 bytes (4.2 GB) copied, 5.12 s, 1203 MB\/s<\/pre>\n<p>\u7136\u540e\u628a\u5b83\u8f6c\u53d8\u4e3aswap\u6587\u4ef6\uff1a<!--more--><\/p>\n<pre>$ sudo mkswap \/swapfile\r\nSetting upswapfile version 1, size = 4095996 KiB no label, UUID=069d83cf-2b91-420e-a2dc-4f7a58a4f520<\/pre>\n<p>\u6fc0\u6d3bswap\u6587\u4ef6\uff1a<\/p>\n<pre>$ sudo swapon \/swapfile<\/pre>\n<p>\u786e\u8ba4\u6fc0\u6d3b\u6210\u529f\uff1a<\/p>\n<pre>$ cat \/proc\/swaps\r\nFilename Type Size Used Priority\r\n\/swapfile file 4095996 0 -1<\/pre>\n<p>\u6253\u5f00\/etc\/fstab\uff0c\u5728\u7ed3\u5c3e\u52a0\u4e0a\u4e0b\u9762\u8fd9\u4e00\u884c\uff0c\u786e\u4fdd\u7cfb\u7edf\u91cd\u542f\u540e\u4f1a\u81ea\u52a8\u6fc0\u6d3bswap\uff1a<\/p>\n<pre>$ sudo vi \/etc\/fstab\r\n\/swapfile none swap defaults 0 0<\/pre>\n<p>OK\uff0c\u5927\u529f\u544a\u6210\u3002<\/p>\n<p class=\"bawpvc-ajax-counter\" data-id=\"291\">\u9605\u8bfb\uff1a147<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u4e0d\u4e45\u5728Amazon\u8d2d\u4e70\u4e86\u4e00\u53f0EC2\u670d\u52a1\u5668\u8fd0\u884cWordPress\uff0c\u914d\u7f6e\u4e3a\u53cc\u6838CPU\uff0c\u5185\u5b581G\u3002\u8fd0\u884c\u4e86\u4e00\u6bb5\u65f6\u95f4\u540e &hellip; <a href=\"http:\/\/droidking.com\/?p=291\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u4e3aUbuntu Linux\u521b\u5efaSwap\u5206\u533a<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,24,5],"tags":[],"class_list":["post-291","post","type-post","status-publish","format-standard","hentry","category-linux","category-wordpress","category-5"],"_links":{"self":[{"href":"http:\/\/droidking.com\/index.php?rest_route=\/wp\/v2\/posts\/291","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/droidking.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/droidking.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/droidking.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/droidking.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=291"}],"version-history":[{"count":4,"href":"http:\/\/droidking.com\/index.php?rest_route=\/wp\/v2\/posts\/291\/revisions"}],"predecessor-version":[{"id":311,"href":"http:\/\/droidking.com\/index.php?rest_route=\/wp\/v2\/posts\/291\/revisions\/311"}],"wp:attachment":[{"href":"http:\/\/droidking.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=291"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/droidking.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=291"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/droidking.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}