云计算学习路线教程大纲课件:交换分区管理 Swap

云计算学习路线教程大纲课件:交换分区管理 Swap

====================================================================================

作用: ‘提升‘ 内存的容量,防止OOM(Out Of Memory)

一、查看当前的交换分区

[[email?protected] ~]# free -m

total used free shared buff/cache available

Mem: 489 140 145 4 202 304

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 /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 defaults,pri=1 0 0

UUID="ea5b1c77-e540-465c-9644-0d75457f8b45" swap swap defaults,pri=1 0 0

[[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

猜你喜欢

转载自blog.51cto.com/14529670/2438966