Linux Swap 启停及swappiness设置
生成swap分区 可以通过磁盘分区和文件两种方式进行操作 1. 通过磁盘分区 划出一块4G磁盘fdisk /dev/sdb sdb磁盘对应的文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 [root@centosgpt ~]# fdisk /dev/sdb Command (m for help): n Partition number (1-128, default 1): First sector (34-41943006, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-41943006, default 41943006): +4G Created partition 1 ... Command (m for help): p ... # Start End Size Type Name 1 2048 8390655 4G Linux filesyste .. Command (m for help): w The partition table has been altered! 创建分区mkswap /dev/sdb1 sdb1对应分区 1 2 3 [root@centosgpt ~]# mkswap /dev/sdb1 Setting up swapspace version 1, size = 1020 KiB no label, UUID=5dabc5b1-d763-4757-9e0c-383f0cacb0ea 2. 通过文件生成 生成文件dd if=/dev/zero of=/swap bs=1MB count=1024 bs 以1M为单位, count多少个1MB块 1 2 3 4 [root@centosgpt ~]# dd if=/dev/zero of=/swap bs=1MB count=1024 1024+0 records in 1024+0 records out 1024000000 bytes (1.0 GB) copied, 1.36373 s, 751 MB/s 赋予权限chown root:root /swap chmod 600 /swap 1 2 [root@centosgpt ~]# chown root:root /swap [root@centosgpt ~]# chmod 600 /swap 创建分区 mkswap -L swap /swap 1 2 3 [root@centosgpt ~]# mkswap -L swap /swap Setting up swapspace version 1, size = 999996 KiB LABEL=swap, UUID=e382380e-c729-40e6-bf3b-823d5cd9b55f 3. 通过LVM2创建 1 2 3 4 1. Create the LVM2 logical volume of size 2 GB: # lvcreate VolGroup00 -n LogVol02 -L 2G 2. Format the new swap space: # mkswap /dev/VolGroup00/LogVol02 https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/storage_administration_guide/ch-swapspace 开启关闭swap分区 1.开启分区 swapon -s ...