LoginSignup
3
1

More than 5 years have passed since last update.

EC2にスワップを設定する

Posted at

内容

AWSのEC2インスタンスは起動時点でスワップ領域が設定されていないため、手動で設定する必要がある。

手順

SSHでEC2インスタンスにログインする

当然ながらインスタンスへのログインが必要
ssh -i [pemファイル(xxx.pem)] ubuntu@[IPアドレス or ドメイン]

スワップを作成する


# 管理者権限になる
sudo su -

# スワップ用フォルダの作成
mkdir /var/swap

# 2Gのスワップ用のファイル作成
dd if=/dev/zero of=/var/swap/swap0 bs=1M count=2048

# パーミッションの設定
chmod 600 /var/swap/swap0

# スワップ割り当て
mkswap /var/swap/swap0
swapon /var/swap/swap0

# 起動時に自動でスワップが割り当てられるように設定
echo '/var/swap/swap0 swap swap defaults 0 0' >> /etc/fstab

反映されたか確認

topコマンドなので確認できる

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1