如何将交换添加到 EC2 实例? [英] How do you add swap to an EC2 instance?

查看:22
本文介绍了如何将交换添加到 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?

推荐答案

解决此问题的方法是向实例添加swap(即paging)空间.

A fix for this problem is to add swap (i.e. 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 much more of it is 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 chmod 600 /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天全站免登陆