Cloud computing tutorial learning course syllabus courseware: swap management Swap
====================================================================================
Action: 'lift' of memory, preventing OOM (Out Of Memory)
First, view the current swap
[root@server0 ~]# free -m
total used free shared buff/cache available
Mem: 489 140 145 4 202 304
Swap: 0 0 0
[Root @ server0 ~] # swapon -s
Second, increase the swap partition
It can be a primary partition, LVM, File
=== === Partition
- Partitioning
[Root @ server0 ~] # fdisk / dev / vdb (t converting partition ID 82)
[root@server0 ~]# partprobe /dev/vdb
[root@server0 ~]# ll /dev/vdb*
brw-rw----. 1 root disk 253, 16 12月 6 10:18 /dev/vdb
brw-rw----. 1 root disk 253, 17 12月 6 10:18 /dev/vdb1
2. Initialize
[root@server0 ~]# mkswap /dev/vdb1
3. Mount
[root@server0 ~]# blkid /dev/vdb1
/dev/vdb1: UUID="ea5b1c77-e540-463c-9644-0d75450f8b4c" TYPE="swap"
[root@server0 ~]# vim /etc/fstab
UUID="ea5b1c77-e540-463c-9644-0d75450f8b4c" swap swap default 0 0
[Root @ server0 ~] # swapon -a (reading / etc / fstab)
[Root @ server0 ~] # swapon -s
Filename Type Size Used Priority
/dev/vdb1 partition 524284 0 -1
===File===
[root@server0 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/vda1 xfs 10G 3.3G 6.8G 33% /
[root@server0 ~]# dd if=/dev/zero of=/swap2.img bs=1M count=512
or
[root@server0 ~]# dd </dev/zero >/swap2.img bs=1M count=512
[root@server0 ~]# mkswap /swap2.img
[root@server0 ~]# vim /etc/fstab
/swap2.img swap swap default 0 0
[root@server0 ~]# swapon -a
swapon: /swap2.img: insecure permissions 0644, 0600 suggested.
[root@server0 ~]# chmod 600 /swap2.img
[root@server0 ~]# swapon -a
[Root @ server0 ~] # swapon -s
Filename Type Size Used Priority
/dev/vdb1 partition 524284 0 -1
/swap2.img file 524284 0 -2
Third, the exchange sub-tuning [extensions]
Multiple swap partitions are distributed in different disks
When mounted, using the same priority
[root@server0 ~]# vim /etc/fstab
UUID="ea5b1c77-e540-463c-9644-0d75450f8b4c" swap swap defaults,pri=1 0 0
UUID="ea5b1c77-e540-465c-9644-0d75457f8b45" swap swap defaults,pri=1 0 0
[root@server0 ~]# swapon -a
[Root @ server0 ~] # swapon -s
Filename Type Size Used Priority
/dev/sdb1 partition 524284 0 1
/dev/sdc1 partition 524284 0 1