1.查看swap空间使用
[[email protected] ~]# free -m total used free shared buffers cached Mem: 1862 267 1595 1 19 103 -/+ buffers/cache: 144 1718 Swap: 2048 0 2048
2.在/usr目录中新建swap目录
[[email protected] usr]# mkdir swap [[email protected] usr]# cd swap
3.从硬盘里分出一个 2×1G 大小的空间,挂在swapfile上
[[email protected] swap]# dd if=/dev/zero of=swapfile bs=1G count=2 2+0 records in 2+0 records out 2147483648 bytes (2.1 GB) copied, 3.51207 s, 611 MB/s
4.构建swap格式于/usr/swap/swapfile 上
[[email protected]]# mkswap swapfile
5.激活swapfile ,加入到swap分区中。
[[email protected] swap]# swapon swapfile
6.将swapfile 加入到/etc/fstab 条目,开机自动挂载
[email protected] swap]# vim /etc/fstab # # /etc/fstab # Created by anaconda on Mon Jun 27 09:19:50 2016 # # 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 # UUID=d83c67dc-f486-49da-aed0-2e8fdf58c743 / ext4 defaults 1 1 UUID=9cfb795c-c308-4594-82cb-aff56d8b840c /boot ext4 defaults 1 2 UUID=1766229a-57ee-46b1-8bb3-1d508e37e88e swap swap defaults 0 0 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 /usr/swap/swapfile swap swap defaults 0 0
7.reboot重启系统,swap开机已经改为4g了
[[email protected] swap]# free -m total used free shared buffers cached Mem: 1862 272 1590 1 20 107 -/+ buffers/cache: 144 1718 Swap: 4095 0 4095
时间: 2024-10-21 09:47:42