Amazon Linux Cannot allocate memory
今天在编译HHVM的时候 Virtual memory exhausted: Cannot allocate memory,而这我重新启动Nginx的时候,也提示内容错误。后来一查发现是Memory不够的原因,创建instance的时候没选好?。
以及Nginx启动出错
2014/09/21 12:11:04 [alert] 1656#0: mmap(MAP_ANON|MAP_SHARED, 1048576000) failed (12: Cannot allocate memory)
2014/09/21 12:11:09 [alert] 1690#0: mmap(MAP_ANON|MAP_SHARED, 1048576000) failed (12: Cannot allocate memory)
2014/09/21 12:11:33 [alert] 1739#0: mmap(MAP_ANON|MAP_SHARED, 1048576000) failed (12: Cannot allocate memory)
2014/09/21 12:14:19 [alert] 1878#0: mmap(MAP_ANON|MAP_SHARED, 1048576000) failed (12: Cannot allocate memory)
大致分三步进行
1.创建swapfile文件
下面的代码是创建一个1G的swapfile,如果想要512,将bs将为1024
sudo dd if=/dev/zero of=/swapfile bs=2048 count=524288
.
524288+0 records in
524288+0 records out
1073741824 bytes (1.1 GB) copied, 16.3176 s, 65.8 MB/s
查看是否创建成功
ls -lh /swapfile
.
-rw-r--r-- 1 root root 1.0G Sep 22 13:22 /swapfile
2.设置交换区
sudo mkswap /swapfile
.
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=14c49315-c69b-4269-a2fe-4716e81ece9e
3.启动系统交换区
sudo swapon /swapfile
4.添加到分区表中(可选)
vim /etc/fstab
.
/dev/xvda2 /mnt auto defaults,nobootwait,comment=cloudconfig 0 2
/swapfile swap swap defaults 0 0
围观我的Github Idea墙, 也许,你会遇到心仪的项目