你怎么添加交换到一个EC2实例? [英] How do you add swap to an EC2 instance?

查看:174
本文介绍了你怎么添加交换到一个EC2实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在运行的EC2实例,微型和我一直在寻找的情况下偶尔会耗尽内存。

I'm currently running an ec2 micro instance and i've been finding that the instance occasionally runs out of memory.

除了使用较大的实例大小,还有什么可以做?

Other than using a larger instance size, what else can be done?

推荐答案

有关此问题的一个解决方法是增加交换页面的空间实例。

A fix for this problem is to add swap or paging space to the instance.

分页的工作原理是在硬盘上创建一个区域,并使用它的额外的内存,这种内存比普通内存要慢很多然而,这是更加的可用。

Paging works by creating an area on your hard drive and using it for extra memory, this memory is much slower than normal memory however this is much more of it available.

要这种额外的空间添加到您的比如你键入:

To add this extra space to your instance you type:

sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
sudo /sbin/mkswap /var/swap.1
sudo /sbin/swapon /var/swap.1

如果你需要超过1024,然后更改到更高的东西。

If you need more than 1024 then change that to something higher.

要重新启动后启用它在默认情况下,该行添加到/ etc / fstab中:

To enable it by default after reboot, add this line to /etc/fstab:

/var/swap.1 swap swap defaults 0 0

这篇关于你怎么添加交换到一个EC2实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆