1.什么是交换分区?
Linux交换分区的作用是在系统内存不足时,充当额外的虚拟内存空间,以满足系统对内存的需求。
当系统内存不足时,操作系统将一部分内存中的数据转移到交换分区中,以释放内存空间供其他程序使用。
交换分区可以减少系统因内存不足而导致的性能问题,同时还可以提供一种冗余的备份机制,确保系统在内存不足时能够继续正常运行。
交换分区的大小一般设置为系统内存大小的1.5倍到2倍之间。
CDH报错界面如下
1.去该节点查看当前交换分区和内存使用情况
[root@cloudcdp01 ~]# free -h
Usage:
free [options]
Options:
-b, --bytes show output in bytes
-k, --kilo show output in kilobytes
-m, --mega show output in megabytes
-g, --giga show output in gigabytes
–tera show output in terabytes
–peta show output in petabytes
-h, --human show human-readable output
–si use powers of 1000 not 1024
-l, --lohi show detailed low and high memory statistics
-t, --total show total for RAM + swap
-s N, --seconds N repeat printing every N seconds
-c N, --count N repeat printing N times, then exit
-w, --wide wide output
–help display this help and exit
-V, --version output version information and exit
For more details see free(1)
用途:
free[选项]
选项:
-b, --bytes 显示输出(以字节为单位)
-k, --kilo 显示输出(以千字节为单位)
-m, --mega show 输出(以兆字节为单位)
-g, --giga 显示输出(以 GB 为单位)
–tera show 输出(以 TB 为单位)
–peta show 输出(以 PB 为单位)
-h, --human 显示人类可读输出
–si 使用 1000 的幂,而不是 1024
-l, --lohi 显示详细的内存不足和高内存统计信息
-t, --total 显示 RAM + 交换的总数
-s N, --seconds N 每 N 秒重复打印一次
-c N, --count N 重复打印 N 次,然后退出
-w, --wide 宽输出
–help 显示此帮助并退出
-V, --version 输出版本信息并退出
2.查看交换分区
[root@cloudcdp01 ~]# swapon
3.关闭交换分区
[root@cloudcdp01 ~]# swapoff /dev/dm-1
用法:
swapoff [选项] [<指定>]
选项:
-a, --all 禁用 /proc/swaps 中的所有交换区
-v, --verbose verbose mode
-h, --help 显示此帮助并退出
-V, --version 输出版本信息并退出
<指定> 参数包括:
-L <标签> 要使用设备的标签
-U 要使用设备的 UUID
LABEL=<标签> 要使用设备的标签
UUID= 要使用设备的 UUID
<设备> 要使用设备的名称
<文件> 要使用文件的名称
再去查看CDH后台
交换空间已禁用,告警消失。
4.再打开交换分区
[root@cloudcdp01 ~]# swapon -a
[root@cloudcdp01 ~]# free -h
total used free shared buff/cache available
Mem: 15G 13G 179M 38M 2.3G 2.1G
Swap: 2.0G 0B 2.0G
恢复正常