今天发现我们有台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添加磁盘空间

如下面例子:

[root@cfbdb5 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。

[root@cfbdb5 oracle]# lvextend –l +2558 /dev/vg_test/lv_test 注意:这里一定要写加号

或者lvextend -l +100%FREE /dev/vg_victor/lv_root把剩余的所有的vg空间给lv

最后,使用resize2fs /dev/myvg/mylv进行文件系统扩展。  
   
扩容的具体过程:

1.首先,我们在aws对主和从做snapshot

2.对主和从分别添加磁盘,并分区为8e格式,先master后slave

3.制作pv

4.把pv添加到vg

5.扩展lv

6.扩展文件系统resize2fs

pvcreate /dev/xvdh1  
vgextend vg-rightscale-aam-prod-db_01-06p0bc7hf5ops /dev/xvdh1    
lvextend -l +81919 /dev/mapper/vg--rightscale--aam--prod--db_01--06p0bc7hf5ops-lvol0    
fsadm resize /dev/mapper/vg--rightscale--aam--prod--db_01--06p0bc7hf5ops-lvol0

pvcreate /dev/xvdg1  
vgextend vg-rightscale-dbtest-master /dev/xvdg1 

扩展前:

# vgdisplay    
  --- Volume group ---    
  VG Name               vg-rightscale-dbtest-master    
  System ID            
  Format                lvm2    
  Metadata Areas        1    
  Metadata Sequence No  2    
  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               20.00 GiB    
  PE Size               4.00 MiB    
  Total PE              5119    
  Alloc PE / Size       4607 / 18.00 GiB    
  Free  PE / Size       512 / 2.00 GiB    
  VG UUID               0nZVTb-f4Hy-7H5e-LpeB-CgMm-26DO-60fs9G    
  

扩展后:

# vgdisplay  
  --- Volume group ---    
  VG Name               vg-rightscale-dbtest-master    
  System ID            
  Format                lvm2    
  Metadata Areas        2    
  Metadata Sequence No  3    
  VG Access             read/write    
  VG Status             resizable    
  MAX LV                0    
  Cur LV                1    
  Open LV               1    
  Max PV                0    
  Cur PV                2    
  Act PV                2    
  VG Size               29.99 GiB    
  PE Size               4.00 MiB    
  Total PE              7678    
  Alloc PE / Size       4607 / 18.00 GiB    
  Free  PE / Size       3071 / 12.00 GiB    
  VG UUID               0nZVTb-f4Hy-7H5e-LpeB-CgMm-26DO-60fs9G

 

报错:

#  lvextend –l +3071 /dev/vg-rightscale-dbtest-master/lvol0  
  Path required for Logical Volume "–l"    
  Please provide a volume group name    
  Run `lvextend --help' for more information.

应该是vg的名称不对:

lvextend -l +3071 /dev/mapper/vg--rightscale--dbtest--master-lvol0这个命令执行成功


扩展前的lv大小:

# df -Th  
Filesystem           Type   Size  Used Avail Use% Mounted on    
/dev/xvda1           ext3   9.9G  2.7G  6.7G  29% /    
none                 tmpfs  4.0G     0  4.0G   0% /dev/shm    
/dev/mapper/vg--rightscale--dbtest--master-lvol0    
                     xfs     18G  280M   18G   2% /mnt/storage

 

resize2fs /dev/vg-rightscale-dbtest-master/lvol0

报错如下:

# resize2fs /dev/mapper/vg--rightscale--dbtest--master-lvol0  
resize2fs 1.41.12 (17-May-2010)    
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/vg--rightscale--dbtest--master-lvol0    
Couldn't find valid filesystem superblock.

错误的原因:由于扩展文件系统而言,resize2fs支持ext4,但不支持xfs.

解决办法有2种:

1. xfs_growfs  /dev/mapper/vg--rightscale--dbtest--master-lvol0:

下面是关于xfs_growfs的使用说明:

xfs_growfs, xfs_info - expand an XFS filesystem用于扩展xfs文件系统

SYNOPSIS  
       xfs_growfs [ -dilnrxV ] [ -D size ] [ -e rtextsize ] [ -L size ] [ -m maxpct ] [ -t mtab ] [ -R size ] mount-point    
       xfs_info [ -t mtab ] mount-point

DESCRIPTION  
       xfs_growfs  expands  an  existing  XFS  filesystem  (see xfs(5)).  The mount-point argument is the pathname of the directory where the filesystem is mounted. The filesystem must be mounted to be grown (see    
       mount(8)).  The existing contents of the filesystem are undisturbed, and the added space becomes available for additional file storage.

       xfs_info is equivalent to invoking xfs_growfs with the -n option (see discussion below).

OPTIONS  
       -d | -D size    
              Specifies that the data section of the filesystem should be grown. If the -D size option is given, the data section is grown to that size, otherwise the data section is grown  to  the  largest  size    
              possible with the -d option. The size is expressed in filesystem blocks.

       -e     Allows the real-time extent size to be specified. In mkfs.xfs(8) this is specified with -r extsize=nnnn.

       -i     The new log is an internal log (inside the data section).  [NOTE: This option is not implemented]

       -l | -L size  
              Specifies  that the log section of the filesystem should be grown, shrunk, or moved. If the -L size option is given, the log section is changed to be that size, if possible. The size is expressed in    
              filesystem blocks.  The size of an internal log must be smaller than the size of an allocation group (this value is printed at mkfs(8) time). If neither -i nor -x is given with -l, the log continues    
              to be internal or external as it was before.  [NOTE: These options are not implemented]

       -m     Specify a new value for the maximum percentage of space in the filesystem that can be allocated as inodes. In mkfs.xfs(8) this is specified with -i maxpct=nn.

       -n     Specifies that no change to the filesystem is to be made.  The filesystem geometry is printed, and argument checking is performed, but no growth occurs.

       -r | -R size  
              Specifies  that  the real-time section of the filesystem should be grown. If the -R size option is given, the real-time section is grown to that size, otherwise the real-time section is grown to the    
              largest size possible with the -r option. The size is expressed in filesystem blocks.  The filesystem does not need to have contained a real-time section before the xfs_growfs operation.

       -t     Specifies an alternate mount table file (default is /proc/mounts if it exists, else /etc/mtab).  This is used when working with filesystems mounted without writing  to  /etc/mtab  file  -  refer  to  
              mount(8) for further details.

       -V     Prints the version number and exits. The mount-point argument is not required with -V.

       xfs_growfs  is  most  often used in conjunction with logical volumes (see md(4) and lvm(8) on Linux).  However, it can also be used on a regular disk partition, for example if a partition has been enlarged  
       while retaining the same starting block.

PRACTICAL USE  
       Filesystems normally occupy all of the space on the device where they reside. In order to grow a filesystem, it is necessary to provide added space for it to occupy. Therefore there must be  at  least  one    
       spare new disk partition available. Adding the space is often done through the use of a logical volume manager.

2.fsadm resize /dev/vg-rightscale-dbtest-slave/lvol0这个命令不会报错

但是如果是缩减磁盘空间这个命令就不支持:

fsadm -- utility to resize or check filesystem on a device

fsadm utility checks or resizes the filesystem on a device.  It tries to use the same API for ext2, ext3, ext4, ReiserFS and XFS filesystem.

fsadm: Xfs filesystem shrinking is unsupported

# df -Th  
Filesystem           Type   Size  Used Avail Use% Mounted on    
/dev/xvda1           ext3   9.9G  2.7G  6.7G  29% /    
none                 tmpfs  4.0G     0  4.0G   0% /dev/shm    
/dev/mapper/vg--rightscale--dbtest--master-lvol0    
                     xfs     30G  280M   30G   1% /mnt/storage

 

二、关于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前面需要有+,如果没有加号就表示到多少,而不是增加多少。


 

 

四、自动扩容脚本:

有待研究,最好增加用户交互。