{"id":496,"date":"2015-01-28T13:24:17","date_gmt":"2015-01-28T05:24:17","guid":{"rendered":"http:\/\/www.datarelab.com\/blog\/?p=496"},"modified":"2015-01-28T13:24:17","modified_gmt":"2015-01-28T05:24:17","slug":"linux%e7%b3%bb%e7%bb%9f%e6%b7%bb%e5%8a%a0swap%e8%99%9a%e6%8b%9f%e5%86%85%e5%ad%98%e4%b8%8e%e5%88%a0%e9%99%a4%e9%85%8d%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/www.datarelab.com\/blog\/Technical_literature\/496.html","title":{"rendered":"Linux\u7cfb\u7edf\u6dfb\u52a0swap\u865a\u62df\u5185\u5b58\u4e0e\u5220\u9664\u914d\u7f6e"},"content":{"rendered":"<p><strong>1.swap\u6982\u8ff0<\/strong><br \/>\nSwap\u5206\u533a\uff0c\u5373\u4ea4\u6362\u533a\uff0cSwap\u7a7a\u95f4\u7684\u4f5c\u7528\u53ef\u7b80\u5355\u63cf\u8ff0\u4e3a\uff1a\u5f53\u7cfb\u7edf\u7684\u7269\u7406\u5185\u5b58\u4e0d\u591f\u7528\u7684\u65f6\u5019\uff0c\u5c31\u9700\u8981\u5c06\u7269\u7406\u5185\u5b58\u4e2d\u7684\u4e00\u90e8\u5206\u7a7a\u95f4\u91ca\u653e\u51fa\u6765\uff0c\u4ee5\u4f9b\u5f53\u524d\u8fd0\u884c\u7684\u7a0b\u5e8f\u4f7f\u7528\u3002\u90a3\u4e9b\u88ab\u91ca\u653e\u7684\u7a7a\u95f4\u53ef\u80fd\u6765\u81ea\u4e00\u4e9b\u5f88\u957f\u65f6\u95f4\u6ca1\u6709\u4ec0\u4e48\u64cd\u4f5c\u7684\u7a0b\u5e8f\uff0c\u8fd9\u4e9b\u88ab\u91ca\u653e\u7684\u7a7a\u95f4\u88ab\u4e34\u65f6\u4fdd\u5b58\u5230Swap\u7a7a\u95f4\u4e2d\uff0c\u7b49\u5230\u90a3\u4e9b\u7a0b\u5e8f\u8981\u8fd0\u884c\u65f6\uff0c\u518d\u4eceSwap\u4e2d\u6062\u590d\u4fdd\u5b58\u7684\u6570\u636e\u5230\u5185\u5b58\u4e2d\u3002\u8fd9\u6837\uff0c\u7cfb\u7edf\u603b\u662f\u5728\u7269\u7406\u5185\u5b58\u4e0d\u591f\u65f6\uff0c\u624d\u8fdb\u884cSwap\u4ea4\u6362\u3002 \u5176\u5b9e\uff0cSwap\u7684\u8c03\u6574\u5bf9Linux\u670d\u52a1\u5668\uff0c\u7279\u522b\u662fWeb\u670d\u52a1\u5668\u7684\u6027\u80fd\u81f3\u5173\u91cd\u8981\u3002\u901a\u8fc7\u8c03\u6574Swap\uff0c\u6709\u65f6\u53ef\u4ee5\u8d8a\u8fc7\u7cfb\u7edf\u6027\u80fd\u74f6\u9888\uff0c\u8282\u7701\u7cfb\u7edf\u5347\u7ea7\u8d39\u7528\u3002<\/p>\n<p><strong>2.\u521b\u5efaswap<\/strong><br \/>\n\u7531\u4e8e\u5728\u5b89\u88c5Centos 6.0 \u64cd\u4f5c\u7cfb\u7edf\u65f6\u5019\u5fd8\u8bb0\u521b\u5efa\u521b\u5efaswap\u5206\u533a\uff0c\u5bfc\u81f4\u4f7f\u7528zabbix\u5bf9\u8be5\u670d\u52a1\u5668\u76d1\u63a7\u65f6\u51fa\u73b0\u62a5\u8b66\u3002\u8fd9\u65f6\u624d\u53d1\u73b0\uff0c\u6ca1\u6709\u521b\u5efaswap\u5206\u533a\u3002\u6240\u4ee5\u9700\u8981\u521b\u5efa\u4e00\u4e2aswap\u5206\u533a\uff0c\u64cd\u4f5c\u5982\u4e0b\uff1a<\/p>\n<p>\u9996\u5148\uff0c\u7528\u62e5\u6709ROOT\u6743\u9650\u7684\u7528\u6237\u901a\u8fc7SSH\u8fdc\u7a0b\u767b\u5165\u6216\u8005\u672c\u5730\u7ec8\u7aef\u767b\u5165\u5230\u7cfb\u7edf\uff0c\u8fdb\u884c\u521b\u5efaswap\u5206\u533a<\/p>\n<p>dd if=\/dev\/zero of=\/swap\/swap bs=1024 count=1024000<\/p>\n<p>if \/\/\u8f93\u5165<br \/>\nof \/\/\u8f93\u51fa<br \/>\nbs \/\/\u5757\u513f\u5927\u5c0f<br \/>\ncount \/\/\u603b\u5927\u5c0f<br \/>\n\u521b\u5efaLinux\u4ea4\u6362\u6587\u4ef6<br \/>\nmkswap \/swap\/swap<br \/>\n\u7acb\u5373\u6fc0\u6d3b\/swap\/swap\u4ea4\u6362\u6587\u4ef6<br \/>\nswapon \/swap\/swap<br \/>\n\u67e5\u770b\u662f\u5426\u751f\u6548<br \/>\n[root@webserver ~]# free -m<br \/>\ntotal used free shared buffers cached<br \/>\nMem: 2007 140 1867 0 8 35<br \/>\n-\/+ buffers\/cache: 96 1911<br \/>\nSwap: 972 0 972<br \/>\n\u901a\u8fc7\u4ee5\u4e0a\u8f93\u51fa\u4fe1\u606f\u53ef\u4ee5\u770b\u51fa\uff0c\u5df2\u7ecf\u6210\u529f\u521b\u5efaswap\u5206\u533a\u3002<br \/>\n\u8bbe\u7f6e\u6210\u6c38\u4e45\u751f\u6548<br \/>\n\u867d\u7136\u73b0\u5728\u5df2\u7ecf\u751f\u6548\uff0c\u4f46\u662f\u7b49\u4e0b\u6b21\u670d\u52a1\u5668\u91cd\u542f\u4e4b\u540e\u3002\u8be5swap\u865a\u62df\u78c1\u76d8\u4f1a\u5931\u6548\uff0c\u4e3a\u4fdd\u8bc1\u6c38\u4e45\u751f\u6548\uff0c\u9700\u8981\u5728\/etc\/fstab\u6587\u4ef6\u6dfb\u52a0\u5982\u4e0b\u6307\u4ee4\u96c6\uff1a<br \/>\necho \"\/swap\/swap swap swap defaults 0 0\" &gt;&gt; \/etc\/fstab<br \/>\n\u73b0\u5728\u4e3a\u6b62\uff0cswap\u5206\u533a\u5df2\u7ecf\u5b8c\u6210\u521b\u5efa\u3002<\/p>\n<p><strong>3.\u5220\u9664swap\u5206\u533a<\/strong><\/p>\n<p>\u6709\u65f6\u53ef\u80fd\u4f1a\u9700\u8981\u5220\u9664swap\u5206\u533a\uff0c\u8be5\u5982\u4f55\u6b63\u786e\u8fdb\u884c\u5220\u9664\u5206\u533a\u54ea?<\/p>\n<p>\u9996\u5148\u505c\u6b62swap\u5206\u533a<br \/>\nswapoff \/swap\/swap<br \/>\n\u5220\u9664swap\u5206\u533a\u6587\u4ef6<br \/>\nrm -rf \/swap\/swap<br \/>\n\u5220\u9664\"\/etc\/swap\"\u6307\u5b9a\u6587\u4ef6<br \/>\n\u8fd9\u6837\u5c31\u53ef\u4ee5\u624b\u5de5\u6dfb\u52a0\u548c\u5220\u9664swap\u5206\u533a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.swap\u6982\u8ff0 Swap\u5206\u533a\uff0c\u5373\u4ea4\u6362\u533a\uff0cSwap\u7a7a\u95f4\u7684\u4f5c\u7528\u53ef\u7b80\u5355\u63cf\u8ff0\u4e3a\uff1a\u5f53\u7cfb\u7edf\u7684\u7269\u7406\u5185\u5b58\u4e0d\u591f\u7528\u7684\u65f6\u5019\uff0c\u5c31\u9700\u8981 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[14],"class_list":["post-496","post","type-post","status-publish","format-standard","hentry","category-Technical_literature","tag-linux"],"views":1225,"_links":{"self":[{"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/posts\/496","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/comments?post=496"}],"version-history":[{"count":0,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/posts\/496\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/media?parent=496"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/categories?post=496"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/tags?post=496"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}