centos7 - 禁用swap

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

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yangke004

你的鼓励是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值