{"id":391,"date":"2018-02-07T21:05:10","date_gmt":"2018-02-07T13:05:10","guid":{"rendered":"https:\/\/www.zhuyanbin.com\/?p=391"},"modified":"2020-04-07T00:56:02","modified_gmt":"2020-04-06T16:56:02","slug":"digitalocean%e4%b8%bb%e6%9c%ba%e5%a2%9e%e5%8a%a0swap%e5%88%86%e5%8c%ba","status":"publish","type":"post","link":"https:\/\/www.yanbin888.com\/?p=391","title":{"rendered":"DigitalOcean\u4e3b\u673a\u589e\u52a0Swap\u5206\u533a"},"content":{"rendered":"<p>\u5728cmake mysql\u6e90\u7801\u7684\u65f6\u5019\u51fa\u73b0\u4e0b\u9762\u7684\u9519\u8bef\uff1a<\/p>\n<div class=\"highlighter-rouge\">\n<div class=\"highlight\">\n<pre class=\"highlight\"><code>\n[ 46%] Building CXX object sql\/CMakeFiles\/sql.dir\/geometry_rtree.cc.o\nc++: internal compiler error: Killed (program cc1plus)\nPlease submit a full bug report,\nwith preprocessed source if appropriate.\nSee &lt;http:\/\/bugzilla.redhat.com\/bugzilla&gt; for instructions.\nmake[2]: *** [sql\/CMakeFiles\/sql.dir\/geometry_rtree.cc.o] Error 4\nmake[1]: *** [sql\/CMakeFiles\/sql.dir\/all] Error 2\nmake: *** [all] Error 2 \u3000\u3000\n<\/code><\/pre>\n<p>\u901a\u8fc7\u67e5\u627e\uff0c[\u53ef\u80fd\u662f\u56e0\u4e3a\u5185\u5b58\u4e0d\u591f\u7684\u539f\u56e0](https:\/\/bitcointalk.org\/index.php?topic=304389.0)\uff0c\u4f7f\u7528`free -h`\u67e5\u770b\u4e86\u4e0b\uff0c\u53d1\u73b0DO\u7684\u4e3b\u673a\u8fdeSwap\u5206\u533a\u90fd\u6ca1\u6709\uff0cSwap\u5206\u533a\u662f\u5f53\u7269\u7406\u5185\u5b58\u4e0d\u591f\u7528\u7684\u65f6\u5019\uff0c\u628a\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\u5206\u533a\u4e2d\uff0c\u7b49\u5230\u90a3\u4e9b\u7a0b\u5e8f\u8981\u8fd0\u884c\u65f6\uff0c\u518d\u4eceSwap\u5206\u533a\u4e2d\u6062\u590d\u4fdd\u5b58\u7684\u6570\u636e\u5230\u7269\u7406\u5185\u5b58\u4e2d\u3002Swap\u7684\u8c03\u6574\u5bf9Linux\u670d\u52a1\u5668\uff0c\u7279\u522b\u662fWeb\u670d\u52a1\u5668\u7684\u6027\u80fd\u81f3\u5173\u91cd\u8981\uff0c\u901a\u8fc7\u8c03\u6574Swap\uff0c\u6709\u65f6\u53ef\u4ee5\u8d8a\u8fc7\u7cfb\u7edf\u6027\u80fd\u74f6\u9888\uff0c\u8282\u7701\u7cfb\u7edf\u5347\u7ea7\u7684\u8d39\u7528\u3002 \u3000\u3000SWAP\u5206\u533a\u8bbe\u7f6e\u591a\u5927\u662f\u6211\u4eec\u9700\u8981\u5173\u5fc3\u7684\u95ee\u9898\uff0c\u5173\u4e8e\u8bbe\u7f6e\u7684\u89c4\u5219\u53ef\u4ee5\u53c2\u8003\u4e0b\u9762\uff0c\u5b9e\u9645\u60c5\u51b5\u53ef\u4ee5\u6839\u636e\u4e1a\u52a1\u9700\u6c42\u8fdb\u884c\u8c03\u6574\uff0c\u9009\u62e9\u5408\u9002\u7684Swap\u5206\u533a\u5927\u5c0f\uff1a<\/p>\n<p>4G\u4ee5\u5185\u7684\u7269\u7406\u5185\u5b58\uff0cSWAP \u8bbe\u7f6e\u4e3a\u5185\u5b58\u76842\u500d\u3002<br \/>\n4-8G\u7684\u7269\u7406\u5185\u5b58\uff0cSWAP \u7b49\u4e8e\u5185\u5b58\u5927\u5c0f\u3002<br \/>\n8-64G \u7684\u7269\u7406\u5185\u5b58\uff0cSWAP \u8bbe\u7f6e\u4e3a8G\u3002<br \/>\n64-256G\u7269\u7406\u5185\u5b58\uff0cSWAP \u8bbe\u7f6e\u4e3a16G\u3002 \u3000\u3000\u63a5\u4e0b\u6765\u6211\u4eec\u770b\u4e0b\u5982\u4f55\u8bbe\u7f6eSwap\u5206\u533a\u3002 ## \u68c0\u67e5\u662f\u5426\u5b58\u5728Swap\u5206\u533a \u3000\u3000\u8f93\u5165`swapon -s`\uff0c\u5982\u679c\u6ca1\u6709\u4efb\u4f55\u7684\u4fe1\u606f\u663e\u793a\uff0c\u4e5f\u5c31\u662f\u8fd8\u6ca1\u6709\u5212\u5206Swap\u5206\u533a\u3002 ## \u68c0\u67e5\u6587\u4ef6\u7cfb\u7edf \u3000\u3000\u5982\u679c\u6ca1\u6709\u521b\u5efaSwap\u5206\u533a\uff0c\u518d\u770b\u4e0b\u786c\u76d8\u8fd8\u5269\u4e0b\u591a\u5c11\u7a7a\u95f4\u53ef\u4ee5\u4f7f\u7528\uff0c\u4f7f\u7528`df`\u547d\u4ee4\u67e5\u770b\u3002\u56e0\u4e3a\u6211\u5148\u521b\u5efa\u4e861G\u7684Swap\u5206\u533a\uff0c\u8fd8\u662f\u62a5\u9519\uff0c\u4e8e\u662f\u6211\u9009\u62e9\u521b\u5efa\u4e00\u4e2a2GB\u5927\u5c0f\u7684Swap\u5206\u533a\u3002 ## \u521b\u5efaSwap\u5206\u533a\u6587\u4ef6 \u3000\u3000\u521b\u5efaswap\u6587\u4ef6\u3002<\/p>\n<pre class=\"highlight\"><code>dd if=\/dev\/zero of=\/swapfile bs=2048 count=1M <\/code><\/pre>\n<p>\u8be5\u547d\u4ee4\u5c06\u521b\u5efa\u4e00\u4e2a\u5927\u5c0f\u4e3a2GB\uff0c\u6587\u4ef6\u540d\u4e3aswapfile\u7684Swap\u5206\u533a\u6587\u4ef6\uff0c`of=\/swapfile`\u53c2\u6570\u6307\u5b9a\u4e86\u6587\u4ef6\u7684\u521b\u5efa\u4f4d\u7f6e\u548c\u6587\u4ef6\u540d\uff1b`bs=2048`\u6307\u5b9a\u4e86\u6587\u4ef6\u7684\u5927\u5c0f\uff0c`count=1M`\u4ee3\u8868\u5355\u4f4d\u3002 ## \u683c\u5f0f\u5316swap\u5206\u533a<\/p>\n<pre class=\"highlight\"><code>\nmkswap \/swapfile\n<\/code><\/pre>\n<\/div>\n<\/div>\n<h2 id=\"\u6fc0\u6d3bswap\u5206\u533a\">\u6fc0\u6d3bswap\u5206\u533a<\/h2>\n<div class=\"highlighter-rouge\">\n<div class=\"highlight\">\n<pre class=\"highlight\"><code>swapon \/swapfile\n<\/code><\/pre>\n<\/div>\n<\/div>\n<h2 id=\"\u67e5\u8be2swap\u5206\u533a\">\u67e5\u8be2swap\u5206\u533a<\/h2>\n<div class=\"highlighter-rouge\">\n<div class=\"highlight\">\n<pre class=\"highlight\"><code>swapon -s <\/code><\/pre>\n<p>\u4f60\u4f1a\u53d1\u73b0\u5728\u91cd\u542f\u4e4b\u540eSwap\u5206\u533a\u5c31\u6ca1\u4e86\uff0c\u90a3\u662f\u56e0\u4e3a\u4e0a\u9762\u7684\u8bbe\u7f6e\u662f\u4e00\u6b21\u6027\u7684\uff0c\u60f3\u8981\u4e00\u76f4\u542f\u52a8Swap\u5206\u533a\uff0c\u53ef\u4ee5\u7f16\u8f91fstab\u6587\u4ef6\u3002<\/p>\n<p>nano \/etc\/fstab \u3000\u3000\u5728\u6700\u540e\u4e00\u884c\u6dfb\u52a0\u4e0a\u4e0b\u9762\u4e00\u6761\uff1a<\/p>\n<pre class=\"highlight\"><code>\n\/swapfile     swap     swap     defaults     0  0 \u3000\u3000\n<\/code><\/pre>\n<p>\u6dfb\u52a0\u6210\u529f\u540e\u7ed9swap\u8d4b\u4e88\u76f8\u5173\u6743\u9650\uff1a<\/p>\n<p>chown root:root \/swapfile<br \/>\nchmod 0600 \/swapfile ## \u914d\u7f6eswappiness \u3000\u3000\u5b9e\u9645\u4e0a\uff0c\u5e76\u4e0d\u662f\u7b49\u6240\u6709\u7684\u7269\u7406\u5185\u5b58\u90fd\u6d88\u8017\u5b8c\u6bd5\u4e4b\u540e\uff0c\u624d\u53bb\u4f7f\u7528swap\u7684\u7a7a\u95f4\uff0c\u4ec0\u4e48\u65f6\u5019\u4f7f\u7528\u662f\u7531swappiness \u53c2\u6570\u503c\u63a7\u5236\u3002<\/p>\n<p>cat \/proc\/sys\/vm\/swappiness \u3000\u3000\u9ed8\u8ba4\u503c\u662f60\uff0cswappiness=0 \u7684\u65f6\u5019\u8868\u793a\u6700\u5927\u9650\u5ea6\u4f7f\u7528\u7269\u7406\u5185\u5b58\uff0c\u7136\u540e\u624d\u662fSwap\u7a7a\u95f4;swappiness\uff1d100 \u7684\u65f6\u5019\u8868\u793a\u79ef\u6781\u7684\u4f7f\u7528Swap\u5206\u533a\uff0c\u5e76\u4e14\u628a\u5185\u5b58\u4e0a\u7684\u6570\u636e\u53ca\u65f6\u7684\u642c\u8fd0\u5230swap\u7a7a\u95f4\u91cc\u9762\u3002 ### \u4e34\u65f6\u6027\u4fee\u6539<\/p>\n<p>sysctl vm.swappiness=10<br \/>\ncat \/proc\/sys\/vm\/swappiness \u3000\u3000\u8fd9\u91cc\u6211\u4eec\u7684\u4fee\u6539\u5df2\u7ecf\u751f\u6548\uff0c\u4f46\u662f\u5982\u679c\u6211\u4eec\u91cd\u542f\u4e86\u7cfb\u7edf\uff0c\u53c8\u4f1a\u53d8\u621060\u3002 ### \u6c38\u4e45\u4fee\u6539 \u3000\u3000\u5728`\/etc\/sysctl.conf`\u6587\u4ef6\u91cc\u6dfb\u52a0\u5982\u4e0b\u53c2\u6570\uff1a`vm.swappiness=10`\uff0c\u4fdd\u5b58\u91cd\u542f\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<\/div>\n<\/div>\n<p><a href=\"http:\/\/jeremybai.github.io\/blog\/2015\/08\/01\/centos-creat-swap\">http:\/\/jeremybai.github.io\/blog\/2015\/08\/01\/centos-creat-swap<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728cmake mysql\u6e90\u7801\u7684\u65f6\u5019\u51fa\u73b0\u4e0b\u9762\u7684\u9519\u8bef\uff1a [ 46%] Building CXX object sq <span class=\"ellipsis\">&hellip;<\/span> <span class=\"more-link-wrap\"><a href=\"https:\/\/www.yanbin888.com\/?p=391\" class=\"more-link\"><span>Read More &rarr;<\/span><\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[23],"class_list":["post-391","post","type-post","status-publish","format-standard","hentry","category-linux","tag-linux"],"_links":{"self":[{"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/posts\/391","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=391"}],"version-history":[{"count":2,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/posts\/391\/revisions"}],"predecessor-version":[{"id":393,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/posts\/391\/revisions\/393"}],"wp:attachment":[{"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=391"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=391"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=391"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}