{"id":227,"date":"2017-07-25T11:52:04","date_gmt":"2017-07-25T03:52:04","guid":{"rendered":"https:\/\/blog.lcsoul.cn\/?p=227"},"modified":"2017-07-25T11:52:04","modified_gmt":"2017-07-25T03:52:04","slug":"vps%e5%a2%9e%e5%8a%a0swap%e4%ba%a4%e6%8d%a2%e5%88%86%e5%8c%ba","status":"publish","type":"post","link":"https:\/\/blog.lcsoul.top\/index.php\/2017\/07\/25\/vps%e5%a2%9e%e5%8a%a0swap%e4%ba%a4%e6%8d%a2%e5%88%86%e5%8c%ba\/","title":{"rendered":"[\u8f6c\u8f7d]VPS\u589e\u52a0Swap\u4ea4\u6362\u5206\u533a"},"content":{"rendered":"<h2>\u751f\u6210\u6587\u4ef6\u5757<\/h2>\n<p>\u4ee5\u4e0b\u547d\u4ee4\u4e3a\u751f\u6210\u8bfb\/\u5199\u7f13\u51b2\u533a\u7684\u5b57\u8282\u6570\u4e3a1M\uff0cSwap\u5206\u533a\u4e3a1G\u7684\u6587\u4ef6\u5757\u3002<\/p>\n<div class=\"alert alert-info\" role=\"alert\">\ndd if=\/dev\/zero of=\/var\/swap bs=1024 count=1048576\n<\/div>\n<h2>\u8bbe\u7f6e\u4ea4\u6362\u533a<\/h2>\n<div class=\"alert alert-info\" role=\"alert\">\nmkswap \/var\/swap        #mkswap\u547d\u4ee4\u540e\u7684\u53c2\u6570\u5373\u4e3add\u547d\u4ee4\u4e2d\u7684of\u53c2\u6570\u8def\u5f84<br \/>\nchmod 0600 \/var\/swap        #\u63d0\u9ad8\u5b89\u5168\u6027\n<\/div>\n<h2>\u542f\u52a8\u4ea4\u6362\u5668<\/h2>\n<div class=\"alert alert-info\" role=\"alert\">\nswapon \/var\/swap        #swapon\u547d\u4ee4\u540e\u7684\u53c2\u6570\u5373\u4e3add\u547d\u4ee4\u4e2d\u7684of\u53c2\u6570\u8def\u5f84\n<\/div>\n<p>\u542f\u52a8\u540e\uff0c\u6267\u884c<strong>free -m<\/strong>\u547d\u4ee4\uff0c\u67e5\u770b\u662f\u5426\u6210\u529f\u589e\u52a0Swap\u4ea4\u6362\u5206\u533a\uff0c\u663e\u793aSwap\u5206\u533a\u7684\u6807\u8bc6\u53ca\u5206\u533a\u5927\u5c0f\u5219\u6210\u529f\u3002<\/p>\n<div class=\"alert alert-info\" role=\"alert\">\n[root@lcsoul ~]# free -m<br \/>\n              total        used        free      shared  buff\/cache   available<br \/>\nMem:            489         220           7          28         260         218<br \/>\nSwap:          1023           0        1023\n<\/div>\n<h2>\u8bbe\u7f6e\u5f00\u673a\u6302\u8f7d<\/h2>\n<div class=\"alert alert-info\" role=\"alert\">\necho &#8216;\/var\/swap   swap   swap   default 0 0&#8217; >> \/etc\/fstab\n<\/div>\n<p>\u6ce8\uff1a\u5982\u679c\u5728 \/etc\/rc.local \u4e2d\u6709 swapoff -a \u9700\u8981\u4fee\u6539\u4e3a swapon -a<\/p>\n<h2>\u4fee\u6539 swpapiness \u53c2\u6570<\/h2>\n<p>\u5728 Linux \u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u67e5\u770b \/proc\/sys\/vm\/swappiness \u5185\u5bb9\u7684\u503c\u6765\u786e\u5b9a\u7cfb\u7edf\u5bf9 SWAP \u5206\u533a\u7684\u4f7f\u7528\u539f\u5219\u3002\u5f53 swappiness \u5185\u5bb9\u7684\u503c\u4e3a 0 \u65f6\uff0c\u8868\u793a\u6700\u5927\u9650\u5ea6\u5730\u4f7f\u7528\u7269\u7406\u5185\u5b58\uff0c\u7269\u7406\u5185\u5b58\u4f7f\u7528\u5b8c\u6bd5\u540e\uff0c\u624d\u4f1a\u4f7f\u7528 SWAP \u5206\u533a\u3002\u5f53 swappiness \u5185\u5bb9\u7684\u503c\u4e3a 100 \u65f6\uff0c\u8868\u793a\u79ef\u6781\u5730\u4f7f\u7528 SWAP \u5206\u533a\uff0c\u5e76\u4e14\u628a\u5185\u5b58\u4e2d\u7684\u6570\u636e\u53ca\u65f6\u5730\u7f6e\u6362\u5230 SWAP \u5206\u533a\u3002<br \/>\n\u67e5\u770b\u4fee\u6539\u524d\u4e3a 0\uff0c\u9700\u8981\u5728\u7269\u7406\u5185\u5b58\u4f7f\u7528\u5b8c\u6bd5\u540e\u624d\u4f1a\u4f7f\u7528 SWAP \u5206\u533a\u3002<br \/>\n\u53ef\u4ee5\u4f7f\u7528\u4e0b\u8ff0\u65b9\u6cd5\u4e34\u65f6\u4fee\u6539\u6b64\u53c2\u6570\uff0c\u5047\u8bbe\u6211\u4eec\u914d\u7f6e\u4e3a\u7a7a\u95f2\u5185\u5b58\u5c11\u4e8e 10% \u65f6\u624d\u4f7f\u7528 SWAP \u5206\u533a\uff1a<\/p>\n<div class=\"alert alert-info\" role=\"alert\">echo 10 >\/proc\/sys\/vm\/swappiness<\/div>\n<p>\u82e5\u9700\u8981\u6c38\u4e45\u4fee\u6539\u6b64\u914d\u7f6e\uff0c\u5728\u7cfb\u7edf\u91cd\u542f\u4e4b\u540e\u4e5f\u751f\u6548\u7684\u8bdd\uff0c\u53ef\u4ee5\u4fee\u6539 \/etc\/sysctl.conf \u6587\u4ef6\uff0c\u5e76\u589e\u52a0\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<div class=\"alert alert-info\" role=\"alert\">vm.swappiness=10<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u751f\u6210\u6587\u4ef6\u5757 \u4ee5\u4e0b\u547d\u4ee4\u4e3a\u751f\u6210\u8bfb\/\u5199\u7f13\u51b2\u533a\u7684\u5b57\u8282\u6570\u4e3a1M\uff0cSwap\u5206\u533a\u4e3a1G\u7684\u6587\u4ef6\u5757\u3002 dd if=\/dev\/ze [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[82,113],"class_list":["post-227","post","type-post","status-publish","format-standard","hentry","category-vps","tag-swap","tag-113"],"_links":{"self":[{"href":"https:\/\/blog.lcsoul.top\/index.php\/wp-json\/wp\/v2\/posts\/227","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.lcsoul.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.lcsoul.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.lcsoul.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.lcsoul.top\/index.php\/wp-json\/wp\/v2\/comments?post=227"}],"version-history":[{"count":0,"href":"https:\/\/blog.lcsoul.top\/index.php\/wp-json\/wp\/v2\/posts\/227\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.lcsoul.top\/index.php\/wp-json\/wp\/v2\/media?parent=227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.lcsoul.top\/index.php\/wp-json\/wp\/v2\/categories?post=227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.lcsoul.top\/index.php\/wp-json\/wp\/v2\/tags?post=227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}