温馨提示×

Centos swap怎么查看

小樊
42
2026-08-29 13:13:35
栏目: 智能运维

CentOS 系统上,查看 swap(交换分区)常用以下几种方法:


一、最常用:查看 swap 总量和使用情况

free -h

示例输出:

              total        used        free      shared  buff/cache   available
Mem:           3.7G        1.1G        800M        200M        1.8G        2.0G
Swap:          2.0G          0B        2.0G

✅ 可以看到 swap 总大小、已用、剩余


二、查看 swap 挂载情况

swapon -s

cat /proc/swaps

示例:

Filename                                Type            Size    Used    Priority
/dev/sda2                               partition       2097148 0       -2

可以看到:

  • swap 是 分区 还是 文件
  • 所在设备
  • 使用量

三、查看 swap 是否启用

lsblk

blkid

如果是 swap 分区,通常会显示:

TYPE="swap"

四、查看内存 & swap 实时使用

top

htop

top 中:

MiB Swap: 2048.0 total, 2048.0 free

五、查看 swap 配置文件

cat /etc/fstab | grep swap

示例:

/dev/sda2 swap swap defaults 0 0

六、常见问题排查

1️⃣ 没有 swap

free -h

如果 swap 为 0,说明未配置。

2️⃣ swap 未启用

swapon -a

总结(最常用几条)

free -h
swapon -s
cat /proc/swaps

如果你需要 CentOS 7 / 8 / Stream新增 / 删除 swap,我也可以一步步帮你操作。

0