linux 服务器如何设置虚拟内存swap以及virtual memory exhausted: Cannot allocate memory 解决办法 – 21运维
通知: .-...

linux 服务器如何设置虚拟内存swap以及virtual memory exhausted: Cannot allocate memory 解决办法

linux 21运维 8612浏览 0评论

今天用saltstack 部署ng+fastcgi 的时候,编译php报错提示: virtual memory exhausted: Cannot allocate memory 具体信息如下:

stderr:
   configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
    virtual memory exhausted: Cannot allocate memory

基本可以确定是内存不够。由于这个测试机内存只有512M,于是想到了设置swap来缓冲解决,设置swap步骤如下,我这里设置了1G虚拟内存,问题解决。

[root@aliserver var]# mkdir /var/temp
[root@aliserver var]# dd if=/dev/zero of=/var/temp/swap bs=1024 count=1024000  
1024000+0 records in
1024000+0 records out
1048576000 bytes (1.0 GB) copied, 23.1628 s, 45.3 MB/s
[root@aliserver var]# mkswap /var/temp/swap 
mkswap: /var/temp/swap: warning: don't erase bootbits sectors
        on whole disk. Use -f to force.
Setting up swapspace version 1, size = 1023996 KiB
no label, UUID=a9ed2b26-f5dd-4f7e-8c8c-0a930e5e477b
[root@aliserver var]# swapon /var/temp/swap 
[root@aliserver var]# free -m
             total       used       free     shared    buffers     cached
Mem:           488        479          9          0          1        385
-/+ buffers/cache:         92        396
Swap:          999          0        999

当然,使用完以后可以考虑取消swap,免得影响性能。可以使用命令:
swapoff /var/temp/swap
取消挂载。

如果需要一直存在swap,请写入分区表,否则系统重启以后swap将取消挂载。写入分区表内容:
/var/temp/swap  swap swap defaults 0 0

转载请注明:21运维 » linux 服务器如何设置虚拟内存swap以及virtual memory exhausted: Cannot allocate memory 解决办法

发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址