华为FusionCompute虚拟机挂载点磁盘空间在线扩容

需求描述:

由于数据中心某平台测试环境数据库服务器(192.168.104.7)挂载点/usr磁盘空间不足,导致Oracle数据库无法正常运行,因此需要对/usr挂载点进行在线扩容,由原来的200G扩容至300G。

处理过程如下:

1.登陆虚拟机查看磁盘挂载使用情况,看到/usr挂载点空间使用已经100%

[ ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                  16G     0   16G   0% /dev
tmpfs                     16G     0   16G   0% /dev/shm
tmpfs                     16G  194M   16G   2% /run
tmpfs                     16G     0   16G   0% /sys/fs/cgroup
/dev/mapper/centos-root   50G  123M   50G   1% /
/dev/mapper/centos-usr   200G  200G   17M 100% /usr
/dev/xvda1              1014M  157M  858M  16% /boot
/dev/mapper/centos-var   100G  773M  100G   1% /var
/dev/mapper/centos-home   10G   10G   20K 100% /home
nfs1.ccic.com:/nfs/temp  450G  358G   93G  80% /software/temp
tmpfs                    3.2G     0  3.2G   0% /run/user/0
tmpfs                    3.2G     0  3.2G   0% /run/user/1001

查看当前虚拟机有几块磁盘

[ ~]# lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sr0              11:0    1  1024M  0 rom
xvda            202:0    0   500G  0 disk
├─xvda1         202:1    0     1G  0 part /boot
├─xvda2         202:2    0 267.9G  0 part
│ ├─centos-root 253:0    0    50G  0 lvm  /
│ ├─centos-swap 253:1    0   7.9G  0 lvm  [SWAP]
│ ├─centos-usr  253:2    0   200G  0 lvm  /usr
│ ├─centos-home 253:3    0    10G  0 lvm  /home
│ └─centos-var  253:4    0   100G  0 lvm  /var
└─xvda3         202:3    0 231.1G  0 part
  └─centos-usr  253:2    0   200G  0 lvm  /usr

1.登陆FusionCompute虚拟化web界面,找到需要绑定磁盘的虚拟机
华为FusionCompute虚拟机挂载点磁盘空间在线扩容
2.选择更多功能-->绑定磁盘
华为FusionCompute虚拟机挂载点磁盘空间在线扩容
3.创建磁盘,然后绑定给虚拟机
华为FusionCompute虚拟机挂载点磁盘空间在线扩容
4.输入需要绑定磁盘的大小和磁盘名称,然后点击确定。
华为FusionCompute虚拟机挂载点磁盘空间在线扩容
5.虚拟机绑定磁盘后,登陆虚拟机可看到新增的磁盘

[ ~]# lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sr0              11:0    1  1024M  0 rom
xvda            202:0    0   500G  0 disk
├─xvda1         202:1    0     1G  0 part /boot
├─xvda2         202:2    0 267.9G  0 part
│ ├─centos-root 253:0    0    50G  0 lvm  /
│ ├─centos-swap 253:1    0   7.9G  0 lvm  [SWAP]
│ ├─centos-usr  253:2    0   200G  0 lvm  /usr
│ ├─centos-home 253:3    0    10G  0 lvm  /home
│ └─centos-var  253:4    0   100G  0 lvm  /var
└─xvda3         202:3    0 231.1G  0 part
  └─centos-usr  253:2    0   200G  0 lvm  /usr
xvde            202:64   0   100G  0 disk

6.查看虚拟机上的lvm和vg信息

[ ~]# vgs
  VG     #PV #LV #SN Attr   VSize   VFree
  centos   2   5   0 wz--n- 498.99g <131.12g
[ ~]# lvs
  LV   VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home centos -wi-ao----  10.00g
  root centos -wi-ao----  50.00g
  swap centos -wi-ao----  <7.88g
  usr  centos -wi-ao---- 200.00g
  var  centos -wi-ao---- 100.00g

7.创建物理分区

[ ~]# fdisk /dev/xvde
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x251e7667.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-209715199, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199): t
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199):
Using default value 209715199
Partition 1 of type Linux and of size 100 GiB is set

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition ‘Linux‘ to ‘Linux LVM‘

Command (m for help): p

Disk /dev/xvde: 107.4 GB, 107374182400 bytes, 209715200 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
Disk label type: dos
Disk identifier: 0x251e7667

    Device Boot      Start         End      Blocks   Id  System
/dev/xvde1            2048   209715199   104856576   8e  Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

8.创建物理逻辑卷

[ ~]# pvcreate /dev/xvde1
  Physical volume "/dev/xvde1" successfully created.
[ ~]# lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sr0              11:0    1  1024M  0 rom
xvda            202:0    0   500G  0 disk
├─xvda1         202:1    0     1G  0 part /boot
├─xvda2         202:2    0 267.9G  0 part
│ ├─centos-root 253:0    0    50G  0 lvm  /
│ ├─centos-swap 253:1    0   7.9G  0 lvm  [SWAP]
│ ├─centos-usr  253:2    0   200G  0 lvm  /usr
│ ├─centos-home 253:3    0    10G  0 lvm  /home
│ └─centos-var  253:4    0   100G  0 lvm  /var
└─xvda3         202:3    0 231.1G  0 part
  └─centos-usr  253:2    0   200G  0 lvm  /usr
xvde            202:64   0   100G  0 disk
└─xvde1         202:65   0   100G  0 part

9.先扩容lvm所在的vg卷组

[ ~]# vgs
  VG     #PV #LV #SN Attr   VSize   VFree
  centos   2   5   0 wz--n- 498.99g <131.12g
[ ~]# vgextend centos /dev/xvde1  ##扩容卷组centos的大小
  Volume group "centos" successfully extended
[ ~]# vgs
  VG     #PV #LV #SN Attr   VSize    VFree
  centos   3   5   0 wz--n- <598.99g 231.11g

10.接下来扩容/usr挂载点空间大小,并对文件系统进行xfs_growfs 格式化。

[ ~]# lvextend /dev/centos/usr /dev/xvde1
  Size of logical volume centos/usr changed from 200.00 GiB (51200 extents) to <300.00 GiB (76799 extents).
  Logical volume centos/usr successfully resized.

[ ~]# xfs_growfs /dev/centos/usr
meta-data=/dev/mapper/centos-usr isize=512    agcount=8, agsize=6553600 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=52428800, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=12800, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 52428800 to 78642176
[ ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                  16G     0   16G   0% /dev
tmpfs                     16G     0   16G   0% /dev/shm
tmpfs                     16G  194M   16G   2% /run
tmpfs                     16G     0   16G   0% /sys/fs/cgroup
/dev/mapper/centos-root   50G  123M   50G   1% /
/dev/mapper/centos-usr   300G  200G  101G  67% /usr
/dev/xvda1              1014M  157M  858M  16% /boot
/dev/mapper/centos-var   100G  773M  100G   1% /var
/dev/mapper/centos-home   10G   10G   20K 100% /home
nfs1.ccic.com:/nfs/temp  450G  358G   93G  80% /software/temp
tmpfs                    3.2G     0  3.2G   0% /run/user/0
tmpfs                    3.2G     0  3.2G   0% /run/user/1001
nfs1.ccic.com:/nfs/ccic  450G  358G   93G  80% /software/ccic
[ ~]# lvscan
  ACTIVE            ‘/dev/centos/root‘ [50.00 GiB] inherit
  ACTIVE            ‘/dev/centos/home‘ [10.00 GiB] inherit
  ACTIVE            ‘/dev/centos/swap‘ [<7.88 GiB] inherit
  ACTIVE            ‘/dev/centos/usr‘ [<300.00 GiB] inherit
  ACTIVE            ‘/dev/centos/var‘ [100.00 GiB] inherit

经验总结

在centos7.x上,可对挂载点lvm空间大小进行在线、不关机弹性缩减和扩容操作,因此在很多系统环境规划时,建议使用lvm技术,可以根据应用数据的大小对空间进行弹性扩容操作。