LoginSignup
2
3

More than 5 years have passed since last update.

Azure VM(Linux)でスワップファイルを使用する

Posted at

Azure VMのLinuxは、デフォルトではスワップファイルが設定されていません。
CentOSとUbuntuで設定方法が若干違ったので、設定方法を残しておきます。

環境

  • CentOS-based 7.5
  • Ubuntu Server 18.04 LTS

事前確認

  • まずはVMデプロイ直後の状態を表示します。Swapが0Byteになってます。
$ free -m
              total        used        free      shared  buff/cache   available
Mem:           1918         140        1607           8         170        1561
Swap:             0           0           0

設定

  • waagent.confを開きます。
$ sudo vi /etc/waagent.conf
  • 以下のように編集します。
ResourceDisk.EnableSwap=y
ResourceDisk.SwapSizeMB=[スワップサイズ]
  • Ubuntuの場合は上記に加えて以下の設定をします。
ResourceDisk.Format=y
  • OSを再起動します。
$ sudo shutdown -r now

結果確認

  • Swapサイズが増えてたらOKです。
free -m
              total        used        free      shared  buff/cache   available
Mem:           1918         139        1634           8         144        1576
Swap:          2047           0        2047
2
3
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
2
3