阿里雲Centos伺服器添加Swap空間

來源:互聯網
上載者:User


我現在使用的是阿里雲最低配置的伺服器,1核、512MB記憶體,查看記憶體資訊Swap空間為0MB,如下:
[root@www ~]# free -m
             total       used       free     shared    buffers     cached
Mem:           494        124        370          0          7         42
-/+ buffers/cache:         74        419
Swap:            0          0          0

經過尋找資料,在阿里雲論壇有如下解決辦法:

源地址:http://bbs.aliyun.com/read/139905.html?spm=5176.7189909.0.0.bE6Z3x

1.進入目錄

cd /var/

2.擷取要增加的SWAP檔案塊(這裡以1GB為例,count = 1024 x 1024)

dd if=/dev/zero of=swapfile bs=1024 count=1048576


3.建立SWAP檔案

/sbin/mkswap swapfile

4.啟用SWAP檔案

/sbin/swapon swapfile            (此時便可通過free命令看到有swap空間了)

5.查看SWAP資訊是否正確

/sbin/swapon –s

6.添加到fstab檔案中讓系統引導時自動啟動

echo "/var/swapfile swap swap defaults 0 0" >>/etc/fstab

7.修改/etc/rc.local

cat /etc/rc.local
touch /var/lock/subsys/local
#swapoff -a

8.重啟伺服器

reboot

結果如下:

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.