重庆思庄Oracle、Redhat认证学习论坛
标题: 增加swap空间大小 [打印本页]
作者: denglj 时间: 2022-11-18 16:32
标题: 增加swap空间大小
文档课题:增加swap空间大小
以下为swap由8g增加到9g的演练过程:
1、当前swap大小[root@dbserver ~]# lsblk
NAME MAJ:MINRM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0disk
├─sda1 8:1 0 2G 0part /boot
└─sda2 8:2 0 98G 0part
├─rhel-root253:0 0 55G 0lvm /
├─rhel-swap253:1 0 8G 0lvm [SWAP]
└─rhel-home253:2 0 35G 0lvm /home
sr0 11:0 11024M 0 rom
[root@dbserver ~]# free -m
total used free shared buff/cache available
Mem: 7821 818 6362 26 640 6687
Swap: 8191 0 8191
[root@dbserver ~]# swapon -s
Filename Type Size Used Priority
/dev/dm-1 partition 83886040 -2
2、扩展swap分区2.1、新磁盘方式添加一块1g磁盘,并完成分区.
[root@dbserver ~]# lsblk -p
NAME MAJ:MINRM SIZE RO TYPE MOUNTPOINT
/dev/sda 8:0 0 100G 0disk
├─/dev/sda1 8:1 0 2G 0part /boot
└─/dev/sda2 8:2 0 98G 0part
├─/dev/mapper/rhel-root253:0 0 55G 0lvm /
├─/dev/mapper/rhel-swap253:1 0 8G 0lvm [SWAP]
└─/dev/mapper/rhel-home253:2 0 35G 0lvm /home
/dev/sdb 8:16 0 1G 0disk
└─/dev/sdb1 8:17 01023M 0 part
/dev/sr0 11:0 11024M 0 rom
说明:/dev/sdb1为新加磁盘分区
#将新加分区设置为交换区.
[root@dbserver ~]# mkswap /dev/sdb1
Setting up swapspace version 1, size = 1047548 KiB
no label, UUID=cce40e01-b659-43aa-8801-a2a0cccf77eb
#启用交换分区/dev/sdb1
[root@dbserver ~]# swapon /dev/sdb1
[root@dbserver ~]# swapon -s
Filename Type Size Used Priority
/dev/dm-1 partition 83886040 -2
/dev/sdb1 partition 10475480 -3
[root@dbserver ~]# free -m
total used free shared buff/cache available
Mem: 7821 581 6770 15 469 6946
Swap: 9214 0 9214
#设置开机自动挂载
[root@dbserver ~]# echo "/dev/sdb1 swap swapdefaults 0 0" >> /etc/fstab
说明:第一个0表示不要备份,第二0表示系统开机过程中不需要检验.
2.2、dd方式dd方式增加swap空间.
[root@dbserver ~]# dd if=/dev/zero of=/swap01 bs=1024count=1048572 #创建大小为1024m的文件
1048572+0 records in
1048572+0 records out
1073737728 bytes (1.1 GB) copied, 11.7121 s, 91.7 MB/s
说明:
bs=bytes:同时设置读入/输出的块大小为bytes个字节
count=blocks:仅拷贝blocks个块,块大小等于bs指定的字节数
[root@dbserver ~]# mkswap /swap01
Setting up swapspace version 1, size = 1048568 KiB
no label, UUID=6d8a5cb5-2fb7-4bcf-acff-5eae904dc325
[root@dbserver ~]# swapon /swap01
swapon: /swap01: insecure permissions 0644, 0600suggested.
[root@dbserver ~]# free -m
total used free shared buff/cache available
Mem: 7821 851 5276 26 1693 6640
Swap: 10238 0 10238
[root@dbserver ~]# swapon -s
Filename Type Size Used Priority
/dev/sdb1 partition 1047548 0 -2
/dev/dm-1 partition 8388604 0 -3
/swap01 file 1048568 0 -4
[root@dbserver ~]# echo "/swap01 swap swap defaults0 0" >> /etc/fstab
[root@dbserver ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Nov 25 20:55:05 2021
#
# Accessible filesystems, by reference, are maintainedunder '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/orblkid(8) for more info
#
/dev/mapper/rhel-root / xfs defaults 0 0
UUID=d2c7f75a-b3f7-46b1-84bc-56e40c0c4c5d /boot xfs defaults 0 0
/dev/mapper/rhel-home /home xfs defaults 0 0
/dev/mapper/rhel-swap swap swap defaults 0 0
/dev/sdb1 swap swap defaults 0 0
/swap01 swap swap defaults 0 0
说明:不挂载swap用swapoff/swap01.
欢迎光临 重庆思庄Oracle、Redhat认证学习论坛 (http://bbs.cqsztech.com/) |
Powered by Discuz! X3.2 |