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

今天用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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值