virtual memory exhausted: Cannot allocate memory

时间:2022-08-25 09:05:31

问题描述:

购买的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