CentOS 7添加Swap空间
[root@localhost ~]# free -lm
total used free shared buff/cache available
Mem: 7821 6282 1152 14 386 1213
Low: 7821 6668 1152
High: 0 0 0
Swap: 0 0 0
free 命令看到,swap空间是 0 0 0
df -Th查看系统磁盘空间
[root@localhost ~]# df -Th
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/vda1 ext3 50G 19G 28G 40% /
devtmpfs devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs tmpfs 3.9G 48K 3.9G 1% /dev/shm
tmpfs tmpfs 3.9G 14M 3.9G 1% /run
系统盘还有28G可用空间
新建一个Swap文件
[root@localhost ~]# dd if=/dev/zero of=/boot/swap bs=1024 count=8192000
记录了8192000+0 的读入
记录了8192000+0 的写出
8388608000字节(8.4 GB)已复制,91.1635 秒,92.0 MB/秒
swapon 开启swap交换空间的使用
[root@localhost ~]# swapon /boot/swap
swapon: /boot/swap:不安全的权限 0644,建议使用 0600。
swapon: /boot/swap:读交换区头失败: 无效的参数
可惜报错了,跟进报错,改一下swap文件的权限
[root@localhost ~]# chmod 0600 /boot/swap
[root@localhost ~]#
[root@localhost ~]# swapon /boot/swap
swapon: /boot/swap:读交换区头失败: 无效的参数
还是不行,原来是忘记格式化了
格式化一下
[root@localhost ~]# mkswap /boot/swap
正在设置交换空间版本 1,大小 = 8191996 KiB
无标签,UUID=04ca40ad-ce34-4e87-8d34-987ea8a502e1
[root@localhost ~]#
[root@localhost ~]# swapon /boot/swap
再看,OK了
[root@localhost ~]# free -m
total used free shared buff/cache available
Mem: 7821 6300 134 14 1385 1181
Swap: 7999 0 7999
[root@localhost ~]#