在DigitalOcean 的 VPS中用yum update時出現了以下錯誤:
" ... cannot allocate memory ..."
VPS雖然只有512M,但仍未用完。但是沒有SWAP。
Google 後發現,原來真是RAM不足,可能是在安裝過程中某個套件需要更多的RAM吧!不想升VPS計劃,因該主機工作簡單,沒必要用更多RAM的計劃。那只好加SWAP了,反正用的是SSD,速度已不錯的。
以下是在centos7.1中做一個2GB swap的步驟:
1. 生成一個2GB檔案,用來做SWAP
$ dd if=/dev/zero of=/swapfile bs=1024 count=2M
2. 轉"swapfile"為SWAP格式
$ mkswap /swapfile
開啟SWAP
$ swapon /swapfile
查看情況
$ top
KiB Mem : 501144 total, 47088 free, 318512 used, 135544 buff/cache
KiB Swap: 2097148 total, 2006484 free, 90664 used. 63632 avail Mem
3. 修改 fstab, 使reboot後可自行加載swap
$ vi /etc/fstab
加入以下一行
/swapfile swap swap defaults 0 0
完成!
Ref:
https://www.centos.org/docs/5/html/5.2/Deployment_Guide/s2-swap-creating-file.html
沒有留言:
發佈留言