swap分区的作用
swap 分区,即交换分区,window平台上称为虚拟内存。在物理内存不够用时,操作系统会从物理内存中把部分暂时不被使用的数据转移到交换分区,从而为当前运行的程序留出足够的物理内存。
查看当前swap分区的状态
[root@node1 ~]# free -h
total used free shared buff/cache available
Mem: 1.8G 981M 80M 12M 733M 650M
Swap: 2.0G 0B 2.0G
临时关闭swap
[root@node1 ~]# swapoff -a
[root@node1 ~]# free -h
total used free shared buff/cache available
Mem: 1.8G 978M 83M 12M 733M 652M
Swap: 0B 0B 0B
启用swap
[root@node1 ~]# free -h
total used free shared buff/cache available
Mem: 1.8G 978M 83M 12M 733M 652M
Swap: 0B 0B 0B
[root@node1 ~]# swapon -a
[root@node1 ~]# free -h
total used free shared buff/cache available
Mem: 1.8G 979M 81M 12M 733M 651M
Swap: 2.0G 0B 2.0G
永久关闭swap
[root@node1 ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Sun Nov 8 16:22:47 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=be846e91-b013-4dd5-b8ae-72f88aacd204 /boot xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
注释加载swap分区的那行记录
# /dev/mapper/centos-swap swap swap defaults 0 0
重启机器
[root@node1 ~]# reboot