Linux系统配置交换分区

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 ~]# 

上一篇:成员方法的传参机制(基本数据类型)


下一篇:kubernetes-集群搭建-01-环境准备