今天用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虚拟内存,问题解决。
[[email protected] var]# mkdir /var/temp
[[email protected] 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
[[email protected] 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
[[email protected] var]# swapon /var/temp/swap
[[email protected] 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