0 序言
最近刚买1台CENTOS7.9
的云服务器,但swap区为空,这着实有丢丢浪费内存了。
1 查看swap区的情况
- 方式1
# free -m
total used free shared buff/cache available
Mem: 3645 2345 211 0 1089 1062
Swap: 999 0 999
- 方式2 : 查看文件和分区的详细情况
[root@xxx ~]# swapon -s
Filename Type Size Used Priority
/home/swap file 1023996 0 -2
2 配置swap区的操作步骤
注意:
OPENVZ架构
的VPS
是不支持手动添加交换分区的
- Step1 使用
dd
命令创建一个swap交换文件
建立一个/home/swap的分区文件,大小为1G(块的大小: 1024 byte)
# dd if=/dev/zero of=/home/swap bs=1024 count=1024000
1024000+0 records in
1024000+0 records out
1048576000 bytes (1.0 GB) copied, 5.42465 s, 193 MB/s
- Step2 制作
swap
格式文件
# mkswap /home/swap
Setting up swapspace version 1, size = 1023996 KiB
no label, UUID=2aa807e6-08b7-4000-9eb8-ada90fb1f0e0
- Step3 再用swapon命令把这个文件分区挂载swap分区
用free -m 命令看一下,发现已经有交换分区了 ; 但是重启系统后,swap分区又变成0了
# /sbin/swapon /home/swap
swapon: /home/swap: insecure permissions 0644, 0600 suggested.
- Step4 为防止重启后swap分区变成0,要修改
/etc/fstab
文件
# vi /etc/fstab
在文件末尾(最后一行)加上: | 这样就算重启系统,swap分区还是有值
/home/swap swap swap default 0 0
free -h
X 参考文献
- CENTOS7 CENTOS Linux Swapcentos7 centos linux swap centos7 centos swap centos7 centos vmware linux centos7 centos mysql8 linux centos7 centos failed linux centos7 centos linux nginx linux-systemd-x centos7 mariadb systemd centos7 centos linux pam centos7 centos linux node virtualbox centos7 centos linux