{"id":134,"date":"2019-04-30T11:43:07","date_gmt":"2019-04-30T03:43:07","guid":{"rendered":"https:\/\/cloudbool.com\/archive\/?p=134"},"modified":"2019-04-30T11:43:07","modified_gmt":"2019-04-30T03:43:07","slug":"linux-swap","status":"publish","type":"post","link":"https:\/\/cloudbool.com\/archive\/linux-swap.html","title":{"rendered":"Linux\u7cfb\u7edf\u589e\u52a0\u6216\u8c03\u6574swap"},"content":{"rendered":"<p>\u624b\u4e0a\u6709\u53f0\u5c0f\u5185\u5b58VPS\uff0c\u5229\u7528\u63a7\u5236\u9762\u677f\u91cd\u88c5\u7cfb\u7edf\u4e4b\u540e\uff0c\u7cfb\u7edf\u6a21\u677f\u9ed8\u8ba4\u53ea\u7ed9\u4e8664MB\u7684swap\u7a7a\u95f4\uff0c\u5bf9\u4e8e\u9700\u8981\u8dd1PHP\u53caMySQL\u8fd9\u6837\u7684\u7ec4\u5408\u518d\u52a0\u4e0aWordPress\u8fd9\u79cd\u5185\u5b58\u5927\u6237\u6765\u8bf4\u6839\u672c\u4e0d\u591f\u7528\uff0c\u7a0d\u5fae\u6709\u51e0\u4e2a\u8bbf\u95ee\u91cfswap\u5c31\u7206\u4e86\uff0c\u4e8e\u662f\u60f3\u4e86\u60f3\u529e\u6cd5\u8c03\u6574\u4e86\u4e0bswap\u7684\u5927\u5c0f\u3002<br \/>\n<!--more--><br \/>\n\u6211\u662f\u5728Debian9\u7cfb\u7edf\u4e0a\u8fdb\u884c\u6d4b\u8bd5\u7684\uff0c\u4f46\u662f\u7406\u8bba\u4e0a\u6765\u8bf4\uff0cDebian\u3001Ubuntu\u3001CentOS\u7b49Linux\u7cfb\u7edf\u53d1\u884c\u7248\u90fd\u662f\u901a\u7528\u7684\u3002<\/p>\n<h2>\u5f00\u59cb\u4e4b\u524d<\/h2>\n<p>\u5728\u5f00\u59cb\u589e\u52a0\u6216\u4fee\u6539swap\u4e4b\u524d\uff0c\u6211\u4eec\u5148\u67e5\u770b\u7cfb\u7edf\u73b0\u6709\u7684swap\uff1a<\/p>\n<pre><code>root@cloudbool:~# swapon --show\nNAME  TYPE SIZE  USED PRIO\n\/swap file 64M 11.7M   -1\n<\/code><\/pre>\n<p>\u53ef\u4ee5\u770b\u51fa\uff0c\u5f53\u524d\u662f\u4ee5\u6587\u4ef6\u5f62\u5f0f\u542f\u7528swap\u7684\uff0c\u4e14swap\u7a7a\u95f4\u5927\u5c0f\u662f64M\uff0c\u786e\u5b9e\u6709\u70b9\u5c0f\uff0c\u5982\u679c\u662f\u4ee5\u5206\u533a\u5f62\u5f0f\u542f\u7528swap\u7684\uff0c\u8f93\u51fa\u5982\u4e0b\uff1a<\/p>\n<pre><code>[root@CentOS7 ~]# swapon -show\nFilename                                Type            Size    Used    Priority\n\/dev\/dm-1                               partition       3932156 0       -2\n<\/code><\/pre>\n<p>\u67e5\u770b\u73b0\u6709swap\u4f7f\u7528\u60c5\u51b5\uff1a<\/p>\n<blockquote><p>\n  free -m\n<\/p><\/blockquote>\n<p>\u5176\u4e2d<strong>Swap<\/strong>\u6240\u5728\u884c\u5c31\u662fswap\u7684\u4fe1\u606f\uff0c\u53ef\u4ee5\u770b\u5230\u5177\u4f53\u7684swap\u7a7a\u95f4\u5927\u5c0f\u53ca\u5df2\u4f7f\u7528\u60c5\u51b5\u3002<br \/>\n\u56e0\u4e3a\u5982\u679c\u662f\u5206\u533a\u5f62\u5f0f\u7684swap\uff0c\u8c03\u6574\u5927\u5c0f\u9700\u8981\u5206\u533a\uff0c\u672c\u6587\u4ee5swap\u6587\u4ef6\u5f62\u5f0f\u8fdb\u884c\u8c03\u6574\u64cd\u4f5c\u3002<br \/>\n\u65e2\u7136\u662f\u8c03\u6574\uff0c\u54ea\u64cd\u4f5c\u601d\u8def\u80af\u5b9a\u662f\u5148\u5220\u9664\u73b0\u6709\u7684\uff0c\u518d\u6309\u7167\u9700\u6c42\u589e\u52a0swap\u4ea4\u6362\u7a7a\u95f4\u4e86\u3002<\/p>\n<h2>Linux\u7cfb\u7edf\u5173\u95edswap<\/h2>\n<p>\u56e0\u4e3a\u7cfb\u7edf\u6a21\u677f\u81ea\u5e26\u4e8664MB\u7684swap\u5185\u5b58\uff0c\u5728\u8c03\u6574\u5927\u5c0f\u524d\u9700\u8981\u5148\u5c06\u73b0\u6709\u7684swap\u5173\u95ed\uff0c\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n<blockquote><p>\n  swapoff \/swap\n<\/p><\/blockquote>\n<p>\u6267\u884c\u4e4b\u540e\uff0c\u539fswap\u4e0a\u7684\u5185\u5bb9\u5e94\u8be5\u662f\u8f6c\u79fb\u5230\u5185\u5b58\u4e0a\u4e86\uff0c\u53ef\u4ee5\u770b\u5230swap\u7a7a\u95f4\u4e3a\u96f6\uff0c\u4e14\u5185\u5b58\u4f7f\u7528\u6709\u6240\u589e\u52a0\u3002<\/p>\n<h2>Linux\u542f\u7528swap<\/h2>\n<p>\u5982\u679c\u7cfb\u7edf\u539f\u6709swap\u6587\u4ef6\uff0c\u6700\u597d\u662f\u5148\u5220\u9664\u539f\u6709\u7684\uff0c\u6bd4\u5982\u8bf4\u4e0a\u9762\u5173\u95ed\u7684\u54ea\u4e2a\uff1a<\/p>\n<blockquote><p>\n  rm \/swap\n<\/p><\/blockquote>\n<p>\u63a5\u7740\u521b\u5efa\u4e00\u4e2a\u7a7a\u6587\u4ef6\u7528\u4e8e\u521b\u5efaswap\u7a7a\u95f4\uff0c\u76f8\u5173\u547d\u4ee4\uff1a<\/p>\n<pre><code>root@cloudbool:~# dd if=\/dev\/zero of=\/swap bs=512k count=512\n512+0 records in\n512+0 records out\n268435456 bytes (268 MB, 256 MiB) copied, 0.929591 s, 289 MB\/s\n<\/code><\/pre>\n<p>\u4e0a\u9762\u547d\u4ee4\u662f\u5728<strong>\/<\/strong>\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3aswap\u7684\u4ee5\u7a7a\u767d\u586b\u5145\u7684\u6587\u4ef6\uff0c\u5757\u5927\u5c0f\u662f512K\uff0c\u6570\u91cf\u4e3a512\uff0c\u6240\u4ee5\u603b\u5927\u5c0f\u4e3a256MB\uff0c\u5982\u679c\u9700\u6c42\u8ddf\u6211\u4e0d\u4e00\u6837\u7684\uff0c\u53ef\u4ee5\u66f4\u6539\u76f8\u5e94\u7684\u53c2\u6570\u3002<br \/>\n\u5c06\u6587\u4ef6\u521b\u5efa\u6210swap\u6587\u4ef6\uff1a<\/p>\n<pre><code>root@cloudbool:~# mkswap \/swap  \/\/\u521b\u5efaswap\nroot@cloudbool:~# chmod 0600 \/swap  \/\/\u66f4\u6539\u6743\u9650\nroot@cloudbool:~# swapon \/swap \/\/\u542f\u7528swap\n<\/code><\/pre>\n<p>\u5982\u679c\u4e0a\u9762\u51e0\u4e2a\u547d\u4ee4\u6267\u884c\u5b8c\u6ca1\u95ee\u9898\u7684\u8bdd\uff0c\u53ef\u4ee5\u901a\u8fc7\u5982\u4e0b\u547d\u4ee4\u8fdb\u884c\u67e5\u770bswap\u7684\u60c5\u51b5\uff1a<\/p>\n<pre><code>root@cloudbool:~# free -m\n              total        used        free      shared  buff\/cache   available\nMem:            256         144          10          36         101          66\nSwap:           255          22         233\n<\/code><\/pre>\n<p>\u53ef\u4ee5\u770b\u51faswap\u5df2\u7ecf\u521b\u5efa\u6210\u529f\u4e14\u5728\u4f7f\u7528\u4e86\u3002<\/p>\n<h2>\u66f4\u6539\/etc\/fstab\u6587\u4ef6<\/h2>\n<p>\u5982\u679c\u662f\u65b0\u521b\u5efa\u7684swap\u7a7a\u95f4\uff0c\u4e0a\u9762\u53ea\u662f\u4e34\u65f6\u542f\u7528\uff0c\u8981\u6c38\u4e45\u542f\u7528swap\u8fd8\u9700\u8981\u4fee\u6539<strong>\/etc\/fstab<\/strong>\u6587\u4ef6\u4ee5\u5b9e\u73b0\u5f00\u673a\u52a0\u8f7dswap\uff0c\u7f16\u8f91<strong>\/etc\/fstab<\/strong>\uff0c\u5e76\u589e\u52a0\u4e00\u884c\uff1a<\/p>\n<pre><code>vi \/etc\/fstab\n\/swap none swap sw 0 0\n<\/code><\/pre>\n<h2>swap\u7a7a\u95f4\u5927\u5c0f\u591a\u5c11\u5408\u9002<\/h2>\n<p>\u5173\u4e8eswap\u662f\u4e0d\u662f\u6709\u5fc5\u8981\u4ee5\u53ca\u5230\u5e95\u591a\u5927\u5408\u9002\uff0c\u4e00\u76f4\u4ee5\u6765\u7f51\u4e0a\u4f17\u8bf4\u7eb7\u7ead\uff0c\u4e5f\u6ca1\u89c1\u6709\u4e2a\u7edf\u4e00\u7684\u8bf4\u6cd5\uff0c\u5c31\u6211\u4e2a\u4eba\u5b9e\u9645\u4f7f\u7528\u60c5\u51b5\u800c\u8a00\uff0c\u6211\u89c9\u5f97\u8fd8\u662f\u6709\u5fc5\u8981\u7684\uff0c\u6709\u7684\u65f6\u5019\u5185\u5b58\u4e0d\u591f\u7528\u6216\u8005\u592a\u591a\u5185\u5bb9\u9700\u8981\u7f13\u5b58\u53ef\u80fd\u5c31\u8981\u7528\u7684\u4e0aswap\u4e86\u3002<br \/>\n\u81f3\u4e8eswap\u5927\u5c0f\u591a\u5c11\uff0c\u6211\u4e00\u76f4\u662f\u8bbe\u7f6e\u6210\u8ddf\u5185\u5b58\u5927\u5c0f\u4e00\u6837\uff0cswap\u4e5f\u5c31\u662f\u5185\u5b58\u7684\u4ea4\u6362\uff0c\u8bbe\u7f6e\u592a\u5927\u4e5f\u6ca1\u591a\u5927\u610f\u4e49\uff0c\u771f\u7684\u5185\u5b58\u4e0d\u8db3\u8fd8\u662f\u5347\u7ea7\u7269\u7406\u5185\u5b58\u66f4\u5408\u9002\uff0c\u5982\u679c\u78c1\u76d8\u6027\u80fd\u4e0d\u597d\u800c\u8bbe\u7f6eswap\u592a\u5927\u66f4\u662f\u5f71\u54cd\u7a0b\u5e8f\u6027\u80fd\uff0c\u6240\u4ee5\u6211\u4e2a\u4eba\u89c9\u5f97swap\u5927\u5c0f\u548c\u5185\u5b58\u5927\u5c0f\u4e00\u81f4\u662f\u6bd4\u8f83\u5408\u9002\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u624b\u4e0a\u6709\u53f0\u5c0f\u5185\u5b58VPS\uff0c\u5229\u7528\u63a7\u5236\u9762\u677f\u91cd\u88c5\u7cfb\u7edf\u4e4b\u540e\uff0c\u7cfb\u7edf\u6a21\u677f\u9ed8\u8ba4\u53ea\u7ed9\u4e8664MB\u7684swap\u7a7a\u95f4\uff0c\u5bf9\u4e8e\u9700\u8981\u8dd1PHP\u53caM &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"https:\/\/cloudbool.com\/archive\/linux-swap.html\"> <span class=\"screen-reader-text\">Linux\u7cfb\u7edf\u589e\u52a0\u6216\u8c03\u6574swap<\/span> \u67e5\u770b\u5168\u6587 &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"footnotes":""},"categories":[138],"tags":[17,27,63],"class_list":["post-134","post","type-post","status-publish","format-standard","hentry","category-share","tag-centos","tag-debian","tag-linux"],"_links":{"self":[{"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/posts\/134","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/comments?post=134"}],"version-history":[{"count":0,"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/posts\/134\/revisions"}],"wp:attachment":[{"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/media?parent=134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/categories?post=134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/tags?post=134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}