3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

NTTPCのVPS「Indigo」でスワップの設定

Last updated at Posted at 2020-06-25

はじめに

NTT PCコミュニケーションズのVPSサービス「Indigo」を使い始めたのですが、一番ミニマムなプランで契約している貧乏性な性格のため、メモリが心もとなくなってきました。。

$ free -m
              total        used        free      shared  buff/cache   available
Mem:            985         649          76           3         260         191

デフォルトではスワップが無効になっているので、スワップを有効にしてみたいと思います。

前提条件

以下の環境で検証しています。

  • NTT PC コミュニケーションズ「Indigo」上の、KVM Instance 1 CPU 1 GB - Ubuntu 18.04

設定

スワップファイルの作成

ddで2GBのスワップファイルを作成し、パーミッションを変更します。

# dd if=/dev/zero of=/swapfile bs=1M count=2048
# chmod 600 /swapfile

スワップに設定

# mkswap /swapfile

/etc/fstabの設定

起動時にスワップが有効になるように/etc/fstabに設定します。

# vi /etc/fstab
LABEL=cloudimg-rootfs   /        ext4   defaults        0 0
LABEL=UEFI      /boot/efi       vfat    defaults        0 0
# add here
/swapfile       swap    swap    defaults        0 0

スワップを有効

再起動するか、以下のコマンドでスワップを有効にします。

# swapon -a

-a/etc/fstabの内容にしたがってスワップを有効にします。

確認

ちゃんとスワップが有効になっているか確認します。大丈夫ですね。

$ free -m
              total        used        free      shared  buff/cache   available
Mem:            985         647          70           3         267         192
Swap:          2047           6        2041

おわりに

スワップなんて使わなくて良いなら使いたくないですが、リソースが限られている場合は有効な手段です。
私と同じく貧乏性な方はご参考に。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?