LoginSignup
0
0

More than 1 year has passed since last update.

RockyLinux8 vps環境設定5) Swapの設定

Last updated at Posted at 2022-09-17

RockyLinux8 vps環境設定4) 時間設定の変更
https://qiita.com/naga_kt/items/5b175dd606b459e92ebd
の続き。WebArena Indigo(RockyLinux8.4)及びKagoya(RockyLinux8.5)での環境設定について述べる。

 デフォルトでは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領域に割り当てるファイルの作成

 以下のコマンドで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

パーミッションの変更

 パーミッションを変更して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設定の永続化

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

/swapfile     swap    swap    defaults        0       0

RockyLinux8 vps環境設定6) httpdの設定
https://qiita.com/naga_kt/items/cd58bb4cd4001a2fb553
に続く


参考記事

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

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