virtual memory exhausted: Cannot allocate memory


問題描述:

購買的Linux服務器,Linux服務器的內存為512MB。

在編譯PHP的時候會提示:virtual memory exhausted: Cannot allocate memory,編譯失敗。

 

解決方法:

發生該問題的原因是服務器的內存不夠,從而導致編譯失敗。

而購買的Linux服務器,未給你分配虛擬內存,所以可以通過自行增加虛擬內存的方法予以解決

[root@iZ25p0h5gthZ ~]#  free -m  
             total       used       free     shared    buffers     cached
Mem:           994        707        287          0         11         57
-/+ buffers/cache:        638        356 
Swap:            0          0          0 

 第二步

[root@iZ25p0h5gthZ ~]#  mkdir /usr/img/             
[root@iZ25p0h5gthZ ~]# rm -rf /usr/img/swap
[root@iZ25p0h5gthZ ~]#  dd if=/dev/zero of=/usr/img/swap bs=1024 count=2048000           


2048000+0 records in
2048000+0 records out
2097152000 bytes (2.1 GB) copied, 48.7514 s, 43.0 MB/s

 第三步

[root@iZ25p0h5gthZ ~]#  mkswap /usr/img/swap            
mkswap: /usr/img/swap: warning: don't erase bootbits sectors
        on whole disk. Use -f to force.
Setting up swapspace version 1, size = 2047996 KiB
no label, UUID=9982f566-9e44-4495-be0b-51d309873112
[root@iZ25p0h5gthZ ~]# swapon /usr/img/swap 
[root@iZ25p0h5gthZ ~]# free -m
             total       used       free     shared    buffers     cached
Mem:           994        924         70          0          1        269
-/+ buffers/cache:        653        340 
Swap:         1999          0       1999

 使用完畢后可以關掉swap

[root@iZ25p0h5gthZ img]# swapoff swap  
[root@iZ25p0h5gthZ img]# rm -f /usr/img/swap 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM