ÖÐÎÄ
µ±Ç°Î»Ö㺠¹úÍâÖ÷»ú²âÆÀ ? ×ÊÔ´×ÊѶ ? ÕýÎÄ

Ubuntu LinxuÉèÖü°É¾³ýSWAPÐéÄâÄÚ´æÏêϸ½Ì³Ì

Ubuntu LinxuÉèÖü°É¾³ýSWAPÐéÄâÄÚ´æÏêϸ½Ì³Ì

ÉèÖÃSWAP

ʹÓÃfree -mÃüÁî²é¿´µ±Ç°ÏµÍ³SwapÉèÖÃÇé¿ö£»

root@SunPma ~ # free -m      // ²é¿´µ±Ç°SwapÉèÖÃÇé¿ö£¨¿ÉÒÔ¿´µ½µ±Ç°ÏµÍ³²¢Ã»ÓÐÐéÄâÄڴ棩
              total        used        free      shared  buff/cache   available
Mem:            981          73         807           0          99         787
Swap:             0           0           0

root@SunPma ~ # mkdir /swap   // ´´½¨SwapÎļþ¼Ð

root@SunPma ~ # cd /swap      // ½øÈëSwapÎļþ¼Ð

root@SunPma ~/swap # dd if=/dev/zero of=swapfile bs=1M count=2048  // ´´½¨Ò»¸ö2GµÄÄÚ´æÅäÖÃÎļþ
2048+0 records in
2048+0 records out
2147483648 bytes (2.1 GB, 2.0 GiB) copied, 2.13948 s, 1.0 GB/s

root@SunPma ~/swap # chmod 0600 swapfile    // ÉèÖÃΪ600ȨÏÞ

root@SunPma ~/swap # mkswap swapfile        // ½«ÅäÖÃÎļþת»»³ÉSwapÎļþ
Setting up swapspace version 1, size = 2 GiB (2147479552 bytes)
no label, UUID=7a6f9b23-6de5-444d-bf08-0c67bc309317

root@SunPma ~/swap # swapon swapfile       // ¼¤»îSwapÎļþ

root@SunPma ~/swap # free -m               // Ôٴβ鿴SwapÇé¿ö£¬È·¶¨ÊÇ·ñÉèÖóɹ¦
              total        used        free      shared  buff/cache   available
Mem:            981          74          67           0         839         761
Swap:          2047           0        2047

×¢Ò⣺ÉèÖÃÍê³ÉºóµÄÐéÄâÄÚ´æ»áÔÚÖØÐÂÆô¶¯ºóʧЧ£»

Èç¹ûÐèÒªÓÀ¾ÃÉúЧ£¬¿ÉÒÔÐÞ¸Ä/etc/fstabÎļþ£¬ÔÚ×îºóÌí¼ÓÈçÏ´úÂ룺

// ±à¼­`/etc/fstab`Îļþ
vi /etc/fstab

// ÔÚ×îºóÌí¼ÓÒÔÏ´úÂë
/swap/swapfile swap swap defaults 0 0
vim-etc-fstab

ɾ³ýSWAP

ʹÓÃfree -mÃüÁî²é¿´ÏµÍ³SwapÉèÖÃÇé¿ö£»

root@SunPma ~ # free -m             // ²é¿´µ±Ç°SwapÉèÖÃÇé¿ö£¨µ±Ç°ÏµÍ³ÉèÖÃÓÐ1162MBµÄÐéÄâÄڴ棩
              total        used        free      shared  buff/cache   available
Mem:            981         270         240           6         470         564
Swap:          1162          29        1133

root@SunPma ~ # cat /proc/swaps     // ²é¿´Swap¹ÒÔØλÖ㨵±Ç°ÏµÍ³ÉèÖÃÔÚ¸ùĿ¼ÏÂ/swapfile£©
Filename                                Type            Size    Used    Priority
/swapfile                               file            1190340 29952   -2

root@SunPma ~ # swapoff /swapfile   // Í£Ö¹Swap½»»»·ÖÇø£¨×¢Òâ·ÖÇøλÖã©

root@SunPma ~ # rm /swapfile        // ɾ³ýSwap·ÖÇøÎļþ

root@SunPma ~ # vi /etc/fstab       // ɾ³ý¿ªÆôÆô¶¯ÏîÄ¿
δ¾­ÔÊÐí²»µÃתÔØ£º¹úÍâÖ÷»ú²âÆÀ ? Ubuntu LinxuÉèÖü°É¾³ýSWAPÐéÄâÄÚ´æÏêϸ½Ì³Ì

Ïà¹ØÎÄÕÂ

http://www.vxiaotou.com