交换分区管理
一、查看当前的交换分区
[[email protected] ~]# free -m
total used free shared buffers cached
Mem: 1841 519 1322 16 0 213
-/+ buffers/cache: 304 1536
Swap: 0 0 0
[[email protected] ~]# swapon -s
二、增加交换分区
可以是分区,LVM,File
===分区===
1. 准备分区
[[email protected] ~]# fdisk /dev/vdb (t转换分区的ID 82)
[[email protected] ~]# partprobe /dev/vdb
[[email protected] ~]# 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.初始化
[[email protected] ~]# mkswap /dev/vdb1
3.挂载
[[email protected] ~]# blkid /dev/vdb1
/dev/vdb1: UUID="ea5b1c77-e540-463c-9644-0d75450f8b4c" TYPE="swap"
[[email protected] ~]# vim /etc/fstab
UUID="ea5b1c77-e540-463c-9644-0d75450f8b4c" swap swap default 0 0
[[email protected] ~]# swapon -a (读取/etc/fstab)
[[email protected] ~]# swapon -s
Filename Type Size Used Priority
/dev/vdb1 partition 524284 0 -1
===File===
[[email protected] ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/vda1 xfs 10G 3.3G 6.8G 33% /
[[email protected] ~]# dd if=/dev/zero of=/swap2.img bs=1M count=512
或者
[[email protected] ~]# dd </dev/zero >/swap2.img bs=1M count=512
[[email protected] ~]# mkswap /swap2.img
[[email protected] ~]# vim /etc/fstab
/swap2.img swap swap default 0 0
[[email protected] ~]# swapon -a
swapon: /swap2.img: insecure permissions 0644, 0600 suggested.
[[email protected] ~]# chmod 600 /swap2.img
[[email protected] ~]# swapon -a
[[email protected] ~]# swapon -s
Filename Type Size Used Priority
/dev/vdb1 partition 524284 0 -1
/swap2.img file 524284 0 -2
三、对交换分调优
多个交换分区分布在不同的磁盘
挂载时,使用相同的优先级
[[email protected] ~]# vim /etc/fstab
UUID="ea5b1c77-e540-463c-9644-0d75450f8b4c" swap swap default,pri=1 0 0
UUID="ea5b1c77-e540-465c-9644-0d75457f8b45" swap swap default,pri=1 0 0
[[email protected] ~]# swapoff -a
[[email protected] ~]# swapon -s
[[email protected] ~]# swapon -a
[[email protected] ~]# swapon -s
Filename Type Size Used Priority
/dev/sdb1 partition 524284 0 1
/dev/sdc1 partition 524284 0 1