SSH和-bash:fork:无法分配内存VPS Ubuntu [英] SSH and -bash: fork: Cannot allocate memory VPS Ubuntu
问题描述
我在Ubuntu 12.04 VPS,Nginx + Unicorn上托管我的Rails应用程序,部署后一切都很好,但是几个小时后,当我切换到VPS时收到此消息
I am hosting my Rails app on Ubuntu 12.04 VPS, Nginx + Unicorn, after deployment everything is fine, but few hours later, when I ssh to the VPS I get this message
-bash: fork: Cannot allocate memory
-bash: wait_for: No record of process 4201
-bash: wait_for: No record of process 4201
如果我运行任何命令,它将返回
If I run any command, it would just return
-bash: fork: Cannot allocate memory.
推荐答案
似乎您的内存不足.许多VPS服务器都设置为没有交换,因此当内存不足时,它将以看似随机的方式杀死一切.
Seems you have run out of memory. Many VPS servers are setup with no swap, so when you run out of memory, it will kill things off in a seemingly random manner.
最简单的解决方法是为VPS配置更多的内存,这可能会花费更多的钱.第二种最好的方法(除了运行更少的东西和内存来优化所有正在运行的东西)是添加交换分区或交换文件.
The easiest way to fix it is to get more memory provisioned to your VPS, likely costing more money. The next best way (other than running less stuff and memory optimizing everything running) would be to add a swap partition or swap file.
对于1GB交换文件(作为根用户):
For a 1GB swap file (as root):
dd if=/dev/zero of=/swapfile bs=1M count=1024
mkswap /swapfile
swapon /swapfile
请确保也将其添加到/etc/fstab中
Be sure to add it to /etc/fstab too as:
/swapfile none swap defaults 0 0
这将使它在重新启动后重新出现.
That will make it come back after reboot.
这篇关于SSH和-bash:fork:无法分配内存VPS Ubuntu的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!