Linux系统配置交换分区

一、交换分区理解

交换分区:内核使用交换分区,保存内存中暂不活动的数据,当内核重新需要访问这部分数据,将会把这部分重新写入内存中读取。

二、交换分区调整大小建议

内存交换分区
2G或者以下两倍的内存
2G~8G同等内存
8~64G至少4G
64G以上至少4G

三、配置交换分区

1.磁盘分区

[root@node1 ~]# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): print
Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 054D4516-ACE2-4C1A-BB38-1B93407B26A9

Device     Start      End  Sectors Size Type
/dev/sdb1   2048 12584959 12582912   6G Linux filesystem

Command (m for help): n
Partition number (2-128, default 2): 
First sector (12584960-41943006, default 12584960): 
Last sector, +sectors or +size{K,M,G,T,P} (12584960-41943006, default 41943006): +2G

Created a new partition 2 of type 'Linux filesystem' and of size 2 GiB.

Command (m for help): w

The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

2.格式化swap分区

[root@node1 ~]# mkswap /dev/sdb2
Setting up swapspace version 1, size = 2 GiB (2147479552 bytes)
no label, UUID=7b7937af-408b-4370-9bd9-baa0cb5d1c6b

3.永久挂载swap分区

# vim /etc/fstab
UUID=b7190d80-906f-4b9d-9ab4-5a503ecaea2c /                       xfs     defaults        0 0
UUID=525a30a7-d484-4ed5-9f38-f827f54e29ff /boot                   xfs     defaults        0 0
UUID=e6cf8733-5eec-4942-9429-c3e9087b6ff0 swap                    swap    defaults        0 0
UUID="deff8218-3389-4245-a6bf-1716010fd6d4" /mnt/lv01 xfs   defaults        0 0
UUID=7b7937af-408b-4370-9bd9-baa0cb5d1c6b swap swap defaults 0 0 

[root@node1 ~]# swapon -a
[root@node1 ~]# swapon -s
Filename				Type		Size	Used	Priority
/dev/nvme0n1p2                         	partition	2097148	0	-2
/dev/sdb2                              	partition	2097148	0	-3
[root@node1 ~]# 

四、查看swap分区

[root@node1 ~]# swapon -s
Filename				Type		Size	Used	Priority
/dev/nvme0n1p2                         	partition	2097148	0	-2
/dev/sdb2                              	partition	2097148	0	-3
[root@node1 ~]# 

[root@node1 ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           1966         648         831           9         485        1142
Swap:          4095           0        4095
[root@node1 ~]# 

  • 3
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

江湖有缘

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值