今天发现我们有台AWS的机器磁盘use%=87%,我们需要对磁盘进行扩容,当然在不宕机的情况下是最好,但是我们还是需要选择最安全的方式。下面是2种方案:
一、方案:
方案1.直接添加500G磁盘,把160G数据拷贝到新磁盘,按照20m/s计算,同时向需要花费时间:2.5h
如果是主的数据拷贝到主新磁盘,从数据拷贝到从的新磁盘:这个速度有待计算,另外还需要修改info文件对应的路径。
方案2.动态(不宕机的情况添加磁盘)
由于我们AAM数据库服务器磁盘做了LVM所以我们只需要把新的pv往以前的vg添加即可。但具体的磁盘性能还需要测试。
首先,我们添加新磁盘,然后初始化pv
把pv添加到vg,查看信息看到vg空闲的空间
lvextend对原来的lv进行扩展:
lvextend: Add space to a logical volume给lv添加磁盘空间
如下面例子:
[[email protected] oracle]# vgdisplay
--- Volume group ---
VG Name vg_test
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 6
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size 19.99 GB
PE Size 4.00 MB
Total PE 5118
Alloc PE / Size 2560 / 10.00 GB
Free PE / Size 2558 / 9.99 GB
VG UUID YEYtOr-JpCK-P7MV-FFVo-BgEi-Ooef-IG3hlc
确定当前卷组剩余空间9.99GB,剩余PE数量为2558个。在这里将所有的剩余空间全部增加给逻辑卷 /dev/vg_test/lv_test。
[[email protected] oracle]# lvextend –l +2558 /dev/vg_test/lv_test 注意:这里一定要写加号
最后,使用resize2fs /dev/myvg/mylv进行文件系统扩展。
二、关于LVM(logical volume manager)的一些基础知识:
lvextend是扩展逻辑卷,lvreduce是缩小逻辑卷,lvresize是扩展或缩小逻辑卷。
You can use Logical Volume Manager (LVM) to manage multiple physical volumes and configure mirroring
and striping of logical volumes to provide data redundancy and increase I/O performance.你可以使用lvm管理多个物理磁盘和配置mirroring和striping来踢动数据冗余,增加IO性能。
In LVM, you
first create volume groups from physical volumes, which are storage devices such as disk array LUNs,
software or hardware RAID devices, hard drives, and disk partitions. You can then create logical volumes
in a volume group.你可以用LUN磁盘阵列,软件或者硬件raid,硬盘,和磁盘分区来创建vg .
A logical volume functions as a partition that in its implementation might be spread over
multiple physical disks.一个lv用作一个分区或许会被分布到多个物理磁盘。
You can increase the size of logical volumes and change
their layout dynamically without needing to schedule system down time to reconfigure physical storage.
你可以在不宕机的情况下重新配置物理存储来增加lv大小并动态地改变他们的分配。
LVM uses the device mapper (DM) that provides an abstraction layer that allows the creation of logical
devices above physical devices and provides the foundation for software RAID, encryption, and other
storage features.LVM使用device mapper来提供允许在物理设备之上创建逻辑设备的抽象层并提供软件raid,加密和另外存储特性功能。
三、制作的过程:
1.Initializing and Managing Physical Volumes初始化和管理pv
Before you can create a volume group, you must initialize the physical devices that you want to use as
physical volumes with LVM.在你创建vg之前,你必须初始化用作pv的物理设备
举例:
For example, set up /dev/sdb, /dev/sdc, /dev/sdd, and /dev/sde as physical volumes比如把几个物理设备/dev/sdb /dev/sdc /dev/sdd /dev/sde制作一个pv:
pvcreate -v /dev/sd[bcde]
To display information about physical volumes, you can use the pvdisplay, pvs, and pvscan
commands. 你可以通过使用pvdisplay/pvs/pvscan来详细pv的详细信息。
移除pv :
To remove a physical volume from the control of LVM, use the pvremove command.
Other commands that are available for managing physical volumes include pvchange, pvck, pvmove,
and pvresize.关于pv的一些另外的命令:pvchange/pvck/pvmove/pvresize
怎么样使用帮助?
For more information, see the lvm(8), pvcreate(8):http://www.man7.org/linux/man-pages/man8/pvcreate.8.html
2.Creating and Managing Volume Groups创建vg
Having initialized the physical volumes, you can add them to a new or existing volume group.初始化pv后,你可以把它添加到一个新的或者已经存在的vg
举例:创建一个叫myvg的vg
vgcreate -v myvg /dev/sd[bcde]
LVM divides the storage space within a volume group into physical extents, which are the smallest unit that
LVM uses when allocating storage to logical volumes. The default size of an extent is 4 MB
lvm把一个vg的存储空间划分成physical extents,它是当分配存储给lv时,lvm使用的最小的单元。默认大小是4MB.
下面几个例子比较重要:
To add physical volumes to a volume group, use the vgextend command使用vgextend命令添加pv到vg:
vgextend [options] volume_group physical_volume ...
To remove physical volumes from a volume group, use the vgreduce command从vg移除pv,使用vgreduce命令:
vgreduce [options] volume_group physical_volume ...
To display information about volume groups, you can use the vgdisplay, vgs, and vgscan commands.显示vg的信息使用vgdisplay/vgs/vgscan
怎么移除vg: vgremove volume_group
另外的一些vg命令:
vgchange, vgck, vgexport,
vgimport, vgmerge, vgrename, and vgsplit.
3.Creating and Managing Logical Volumes创建和管理lv:
怎么创建lv:
lvcreate [options] --size size --name logical_volume volume_group
举例:创建一个2G的lv
lvcreate -v --size 2g --name mylv myvg
一些相关的命令:
lvchange, lvconvert,
lvmdiskscan, lvmsadc, lvmsar, lvrename, and lvresize.
lvextend是扩展逻辑卷,lvreduce是缩小逻辑卷,lvresize是扩展或缩小逻辑卷。
例如增加100M空间:
lvextend -L +100M /dev/vg1000/lvol0注意:100M前面需要有+,如果没有加号就表示到多少,而不是增加多少。