LoginSignup
0
0

More than 3 years have passed since last update.

Centos7でswapファイルを作成する

Last updated at Posted at 2020-01-08

はじめに

AWS のCentOS7ではswap領域が確保されていないため、手動でswap領域を作成する

swapファイルの作成

ddコマンドを使って100MBの空ファイルを作成する

# ionice -c3 dd if=/dev/zero of=/100MB.img bs=1M count=100 oflag=direct

100MBの空ファイルを使用してして、I/O負荷を少なく8GBのswapファイルを作成する

# for i in $(seq 1 82); do ionice -c3 cat /100MB.img >> /swapfile; sleep 5; done

実行属性を付加します。

# chmod 600 /swapfile

swap領域を作成します。

# mkswap /swapfile

swap領域を有効にします。

# swapon /swapfile

スワップ領域が有効であることを確認する。

# free -m
# swapon -s

OS再起動時のswapファイルマウント設定

OS再起動時にスワップ領域が有効になるように、/etc/fstabに下記を追加します。

# for swap
/swapfile                                 swap                    swap    defaults        0 0

OSがswapを極力使わない設定

/usr/lib/tuned/virtual-guest/tuned.confのvm.swappinessを1に変更する

#vm.swappiness = 30
vm.swappiness = 1

設定を反映させる

# systemctl restart tuned

設定を反映された事を確認する

# sysctl vm.swappiness

/etc/sysctl.confにvm.swappiness = 1を追記する

vm.swappiness = 1

設定反映

# sysctl -p

設定確認

# sysctl -a | grep swappiness
0
0
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
0
0