LoginSignup
0
0

More than 5 years have passed since last update.

docker-machine で作ったEC2上のホストにスワップを作成

Last updated at Posted at 2017-09-22

この記事はだめらしいです
未検証ですが
https://dev.classmethod.jp/cloud/aws/al2-swapfile-fallocate-ng/

以下残骸

$ docker-machine ssh hoge

ログイン後下記のコマンド

$ sudo systemctl enable rc-local
$ sudo vi /etc/rc.local

起動時に毎回swap をマウント

下記のスクリプトの移植版
Amazon EC2(Linux)のswap領域ベストプラクティス

#!/bin/bash
SWAPFILENAME=/swap.img
MEMSIZE=`cat /proc/meminfo | grep MemTotal | awk '{print $2}'`

if [ $MEMSIZE -lt 2097152 ]; then
  let SIZE=$MEMSIZE*2
elif [ $MEMSIZE -lt 8388608 ]; then
  let SIZE=$MEMSIZE
elif [ $MEMSIZE -lt 67108864 ]; then
  let SIZE=$MEMSIZE/2
else
  let SIZE=4194304
fi

fallocate -l ${SIZE}k $SWAPFILENAME && chmod 600 $SWAPFILENAME && mkswap $SWAPFILENAME && swapon $SWAPFILENAME

最後reboot して終わり

$ sudo reboot
0
0
1

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
0
0