Can
Be Better

virtual memory exhausted: Cannot allocate memory

问题描述:

购买的Linux服务器,Linux服务器的内存为512MB。

在编译PHP的时候会提示:virtual memory exhausted: Cannot allocate memory,编译失败。

 

解决方法:

发生该问题的原因是服务器的内存不够,从而导致编译失败。

而购买的Linux服务器,未给你分配虚拟内存,所以可以通过自行增加虚拟内存的方法予以解决

1
2
3
4
5
[[email protected] ~]#  free -m 
             total       used       free     shared    buffers     cached
Mem:           994        707        287          0         11         57
-/+ buffers/cache:        638        356
Swap:            0          0          0

第二步

1
2
3
4
5
6
7
8
[[email protected] ~]#  mkdir /usr/img/            
[[email protected] ~]# rm -rf /usr/img/swap
[[email protected] ~]#  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

第三步

1
2
3
4
5
6
7
8
9
10
11
[[email protected] ~]#  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
[[email protected] ~]# swapon /usr/img/swap
[[email protected] ~]# free -m
             total       used       free     shared    buffers     cached
Mem:           994        924         70          0          1        269
-/+ buffers/cache:        653        340
Swap:         1999          0       1999

使用完毕后可以关掉swap

1
2
[[email protected] img]# swapoff swap 
[[email protected] img]# rm -f /usr/img/swap

 

赞(0) 打赏
不开启评论,如有问题疑问请发邮件。[email protected]最长的路 » virtual memory exhausted: Cannot allocate memory
分享到: 更多 (0)