LoginSignup
0
0

More than 1 year has passed since last update.

WebArena Indigo 環境設定7)Swapの設定

Last updated at Posted at 2022-04-27

WebArena Indigo 環境設定6)/tmpフォルダのファイルの削除処理の変更
https://qiita.com/naga_kt/items/c18089ebecb6e26374f4
の続き。

 デフォルトではSwapが全く設定されていなかった。

$ free -h
              total        used        free      shared  buff/cache   available
Mem:           991M         83M        766M         18M        142M        747M
Swap:            0B          0B          0B
$ swapon -s

 容量を確認したところ余裕があった。

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        20G  5.4G   15G  27% /
devtmpfs        474M     0  474M   0% /dev
tmpfs           496M     0  496M   0% /dev/shm
tmpfs           496M   13M  484M   3% /run
tmpfs           496M     0  496M   0% /sys/fs/cgroup
tmpfs           100M     0  100M   0% /run/user/1001

 4GのSwapを設定することにした。

Swap領域に割り当てるファイルの作成(CentOS7/RockyLinux8)

 以下のコマンドでSwap領域に割り当てるファイル/swapfileを作成した。

$ sudo dd if=/dev/zero of=/swapfile bs=4M count=1024
1024+0 records in
1024+0 records out
4294967296 bytes (4.3 GB) copied, 39.3812 s, 109 MB/s

Swap領域に割り当てるファイルの作成(Ubuntu20.04LTS)

 Ubuntuでは以下のように行う。

$ sudo fallocate -l 4G /swapfile

パーミッションの変更

 パーミッションを変更してrootのみが参照できるファイルにする。

$ ls -lh /swapfile
-rw-r--r-- 1 root root 4.0G Apr 26 14:55 /swapfile
$ sudo chmod 600 /swapfile
$ ls -lh /swapfile
-rw------- 1 root root 4.0G Apr 26 14:55 /swapfile

Swap領域の割り当て

$ sudo mkswap /swapfile
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=………

Swapの有効化

$ sudo swapon /swapfile

Swap領域の状態確認

 以下のようにして4GのSwapが割り当てられていることが確認できる。

$ swapon -s
Filename                                Type    Size    Used    Priority
/swapfile                               file    4194300 0       -1
$ free -h
              total        used        free      shared  buff/cache   available
Mem:           991M         79M         73M         18M        838M        721M
Swap:          4.0G          0B        4.0G

Swap設定の永続化(CentOS7/RockyLinux8)

 OS再起動時もSwap設定を行なうようにするために/etc/fstabを編集して下記一行を追記する。バックアップは取っておくようにする。

/swapfile     swap    swap    defaults        0       0

Swap設定の永続化(Ubuntu20.04LTS)

 Ubuntuでは/etc/fstabは以下の一行を追記する。

/swapfile     none    swap    sw      0       0

WebArena Indigo 環境設定8) httpdの設定
https://qiita.com/naga_kt/items/47e9dd08272c1ff552a1
に続く


参考記事

CentOS
Linux Swap設定方法(CentOS 7)
https://oji-cloud.net/2019/07/01/post-2242/

Ubuntu
Ubuntu 20.04にスワップ領域を追加する方法
https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-20-04-ja

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