关于数据库:分布式数据库使用逻辑卷管理存储之扩容

43次阅读

共计 9453 个字符,预计需要花费 24 分钟才能阅读完成。

浪潮云溪数据库作为一款浪潮自主研发的国产分布式数据库,一大个性便是可反对 PB 级的数据服务。从存储层面来看,云溪数据库不仅能够应用物理磁盘,也能够应用逻辑卷的形式来治理存储。应用逻辑卷,次要有以下两大场景:

(1)当业务上应用大容量的磁盘,单个物理磁盘不能满足需要时。例如:咱们须要在 /data 下挂载 30TB 的存储,而单个磁盘没有这么大的容量。如果应用逻辑卷,将多个小容量的磁盘组合成一个卷组,聚合为一个大的逻辑磁盘,即能满足需要。

(2)当数据量不确定,前期须要扩大磁盘时。在业务初期布局磁盘时,不能齐全晓得须要调配多少磁盘空间。若应用物理卷,前期则无奈扩大。如果应用逻辑卷,能够依据前期的需求量,手动扩大和膨胀。

– 基本概念 –

逻辑卷是应用逻辑卷组治理 (Logic Volume Manager) 创立进去的设施,如果要理解逻辑卷,那么首先须要理解逻辑卷治理中的一些概念。

  1. 逻辑卷管理器(Logical Volume Manager,LVM):LVM 将一个或多个硬盘的分区在逻辑上汇合,相当于一个大硬盘来应用,当硬盘的空间不够应用的时候,能够持续将其它的硬盘的分区退出其中,这样能够实现磁盘空间的动静治理,绝对于一般的磁盘分区有很大的灵活性。LVM 使系统管理员能够更不便的为利用与用户调配存储空间。
  2. 物理卷(Physical Volume,PV):指硬盘分区或从逻辑上与磁盘分区具备同样性能的设施(如 RAID),是 LVM 的根本存储逻辑块。
  3. 卷组(Volume Group,VG):PV 的汇合。是由一个或多个物理卷所组成的存储池,在卷组上能创立一个或多个逻辑卷。
  4. 逻辑卷(Logic Volume,LV):VG 中画进去的一块逻辑磁盘。相似于非 LVM 零碎中的硬盘分区,它建设在卷组之上,是一个规范的块设施,在逻辑卷之上能够建设文件系统。

物理磁盘或者磁盘分区转换为物理卷,一个或多个物理卷汇集造成一个或多个卷组,而逻辑卷就是从某个卷组外面形象进去的一块磁盘空间。具体架构如下:

– 创立 LVM –

1. 首先通过 fdisk -l 或 lsblk 查看磁盘的属性,找到要增加的磁盘名称。

vdc 是手动挂载到虚机上的一块磁盘,执行命令如下:

root@newsqltest:~# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vda    252:0    0   40G  0 disk 
|-vda1 252:1    0  571M  0 part /boot
`-vda2 252:2    0 39.5G  0 part /
vdb    252:16   0   64M  0 disk 
root@newsqltest:~# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vda    252:0    0   40G  0 disk 
|-vda1 252:1    0  571M  0 part /boot
`-vda2 252:2    0 39.5G  0 part /
vdb    252:16   0   64M  0 disk 
vdc    252:32   0   10G  0 disk 
root@newsqltest:~# fdisk -l
Disk /dev/vda: 40 GiB, 42949672960 bytes, 83886080 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: dos
Disk identifier: 0x9b600047

Device     Boot   Start      End  Sectors  Size Id Type
/dev/vda1  *       2048  1171455  1169408  571M 83 Linux
/dev/vda2       1171456 83886046 82714591 39.5G 83 Linux


Disk /dev/vdb: 64 MiB, 67108864 bytes, 131072 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: dos
Disk identifier: 0x00000000


Disk /dev/vdc: 10 GiB, 10737418240 bytes, 20971520 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

2. 应用 fdisk 将磁盘进行逻辑分区

fdisk /dev/vdc

m 来查看命令帮忙;

n 增加一张新的 partition,划分分区,以及分区的大小,这里都应用默认值,创立一个分区;

w 命令保留并退出。

root@newsqltest:~# fdisk /dev/vdc

Welcome to fdisk (util-linux 2.31.1).
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.
Created a new DOS disklabel with disk identifier 0xbb7719f5.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (1-4, default 1): 
First sector (2048-20971519, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-20971519, default 20971519): 

Created a new partition 1 of type 'Linux' and of size 10 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
root@newsqltest:~# fdisk -l
......
Device     Boot Start      End  Sectors Size Id Type
/dev/vdc1        2048 20971519 20969472  10G 83 Linux

3. 应用 lvm 来治理这个分区

1). 首先须要装置 lvm

apt-get install lvm2

2). 创立 Physical Volume(PV)

pvcreate /dev/vdc1

胜利之后能够通过 pvdisplay 查看信息

root@newsqltest:~# pvcreate /dev/vdc1
  Physical volume "/dev/vdc1" successfully created.
root@newsqltest:~# pvdisplay
  "/dev/vdc1" is a new physical volume of "<10.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/vdc1
  VG Name               
  PV Size               <10.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               5FxevL-aneV-Xhe6-pFEv-b3pH-l4v4-Gb6TeA

3). 创立 Volume Group (VG).

vgcreate vg-newsql /dev/vdc1

root@newsqltest:~# vgcreate vg-newsql /dev/vdc1
  Volume group "vg-newsql" successfully created
root@newsqltest:~# vgscan
  Reading volume groups from cache.
  Found volume group "vg-newsql" using metadata type lvm2

4). 创立 Logical Volumes (LV).

lvcreate -n lv-newsql -l 100% VG vg-newsql (将所有的 vg-newsql 的内存都给这个 lv-newsql 逻辑卷)

root@newsqltest:~# lvcreate -n lv-newsql -l 100%VG vg-newsql
  Logical volume "lv-newsql" created.
root@newsqltest:~# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg-newsql/lv-newsql
  LV Name                lv-newsql
  VG Name                vg-newsql
  LV UUID                bMsyAX-xatH-cdTY-JbzE-4ao5-QR6h-j4Z7ON
  LV Write Access        read/write
  LV Creation host, time newsqltest, 2021-01-27 16:09:54 +0800
  LV Status              available
  # open                 0
  LV Size                <10.00 GiB
  Current LE             2559
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

4. 格式化并挂载逻辑卷至 /data

1). 第一步格式化逻辑卷

mkfs.ext4 /dev/vg-newsql/lv-newsql

2). 将逻辑卷挂载到 home 文件夹上面

mount /dev/vg-newsql/lv-newsql /data

root@newsqltest:~# mkfs.ext4 /dev/vg-newsql/lv-newsql
mke2fs 1.44.1 (24-Mar-2018)
Creating filesystem with 2620416 4k blocks and 655360 inodes
Filesystem UUID: a667f950-9b91-45ce-9931-8fb147173054
Superblock backups stored on blocks: 
  32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done 

root@newsqltest:~# mount /dev/vg-newsql/lv-newsql /data
mount: /data: mount point does not exist.
root@newsqltest:~# mkdir /data
root@newsqltest:~# mount /dev/vg-newsql/lv-newsql /data
root@newsqltest:~# df -h
Filesystem                         Size  Used Avail Use% Mounted on
udev                               3.9G     0  3.9G   0% /dev
tmpfs                              798M  3.2M  795M   1% /run
/dev/vda2                           39G  2.8G   35G   8% /
tmpfs                              3.9G     0  3.9G   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
tmpfs                              3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/vda1                          547M   77M  430M  16% /boot
tmpfs                              798M     0  798M   0% /run/user/0
/dev/mapper/vg--newsql-lv--newsql  9.8G   37M  9.3G   1% /data

至此,10G 的盘已卷组的形式挂载至 /data 目录。

– 扩容 –

1. 增加磁盘:

root@newsqltest:~# lsblk
NAME                      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vda                       252:0    0   40G  0 disk 
|-vda1                    252:1    0  571M  0 part /boot
`-vda2                    252:2    0 39.5G  0 part /
vdb                       252:16   0   64M  0 disk 
vdc                       252:32   0   10G  0 disk 
`-vdc1                    252:33   0   10G  0 part 
`-vg--newsql-lv--newsql 253:0    0   10G  0 lvm  /data
vdd                       252:48   0   10G  0 disk

2. 格式化磁盘

1). 当磁盘大小小于 2TB 的时候,与创立 LVM 的第 2 步骤雷同:

fdisk /dev/vdd

m 来查看命令帮忙

n 增加一张新的 partition,划分分区,以及分区的大小,这里我都应用默认值,创立一个分区

w 命令保留并退出

2)当大于 2TB 的时候,应用如下命令:

a. 编辑 /dev/sda 磁盘

parted /dev/vde

b. 设立磁盘分区类型

mklabel gpt

c. 设置默认单位为 TB、GB

unit TB

d. 创立分区大小

mkpart primary 0 0 or mkpart primary 0.00TB 2.10TB

e. quit

f. 格式化磁盘

mkfs.ext4 /dev/vde

root@newsqltest:~# parted /dev/vde
GNU Parted 3.2
Using /dev/vde
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) help                                                             
  align-check TYPE N                        check partition N for TYPE(min|opt) alignment
  help [COMMAND]                           print general help, or help on COMMAND
  mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)
  mkpart PART-TYPE [FS-TYPE] START END     make a partition
  name NUMBER NAME                         name partition NUMBER as NAME
print [devices|free|list,all|NUMBER]     display the partition table, available devices, free space, all found partitions, or a particular partition
  quit                                     exit program
  rescue START END                         rescue a lost partition near START and END
  resizepart NUMBER END                    resize partition NUMBER
  rm NUMBER                                delete partition NUMBER
  select DEVICE                            choose the device to edit
  disk_set FLAG STATE                      change the FLAG on selected device
  disk_toggle [FLAG]                       toggle the state of FLAG on selected device
set NUMBER FLAG STATE                    change the FLAG on partition NUMBER
  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER
  unit UNIT                                set the default unit to UNIT
  version                                  display the version number and copyright information of GNU Parted
(parted) mklabel gpt                                                      
(parted) unit TB
(parted) mkpart primary 0 0 or mkpart primary 0.00TB 2.10TB               
  align-check TYPE N                        check partition N for TYPE(min|opt) alignment
  help [COMMAND]                           print general help, or help on COMMAND
  mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)
  mkpart PART-TYPE [FS-TYPE] START END     make a partition
  name NUMBER NAME                         name partition NUMBER as NAME
print [devices|free|list,all|NUMBER]     display the partition table, available devices, free space, all found partitions, or a particular partition
  quit                                     exit program
  rescue START END                         rescue a lost partition near START and END
  resizepart NUMBER END                    resize partition NUMBER
  rm NUMBER                                delete partition NUMBER
  select DEVICE                            choose the device to edit
  disk_set FLAG STATE                      change the FLAG on selected device
  disk_toggle [FLAG]                       toggle the state of FLAG on selected device
set NUMBER FLAG STATE                    change the FLAG on partition NUMBER
  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER
  unit UNIT                                set the default unit to UNIT
  version                                  display the version number and copyright information of GNU Parted
Warning: You requested a partition from 0.00TB to 2.10TB (sectors 0..4101562500).
The closest location we can manage is 0.00TB to 0.00TB (sectors 34..2047).
Is this still acceptable to you?
Yes/No? yes                                                               
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? ignore                                                     
(parted) quit                                                             
Information: You may need to update /etc/fstab.
root@newsqltest:~# mkfs.ext4 /dev/vde                                     
mke2fs 1.44.1 (24-Mar-2018)
Found a gpt partition table in /dev/vde
Proceed anyway? (y,N) y
Creating filesystem with 550502400 4k blocks and 137625600 inodes
Filesystem UUID: a08b03f2-05b7-4029-b317-0e07f93fb6d2
Superblock backups stored on blocks: 
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
102400000, 214990848, 512000000

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done 

3. 创立 pv 卷,与应用 lvm 来治理这个分区中创立 Physical Volume 的步骤雷同:

pvcreate /dev/vdd1

4. 扩大物理硬盘到同一个卷组外面,每个组治理不同物理磁盘:

vgextend vg-newsql /dev/vdd1

root@newsqltest:~# vgextend vg-newsql /dev/vdd1
  Volume group "vg-newsql" successfully extended

5. 从卷组外面向逻辑卷外面调配空间:

lvextend -l +100% FREE /dev/mapper/vg–newsql-lv–newsql(向逻辑卷外面调配空间)

root@newsqltest:~# lvextend -l +100%FREE /dev/mapper/vg--newsql-lv--newsql
  Size of logical volume vg-newsql/lv-newsql changed from <10.00 GiB (2559 extents) to 19.99 GiB (5118 extents).
  Logical volume vg-newsql/lv-newsql successfully resized.

6. 重启逻辑卷使其失效:

resize2fs /dev/mapper/vg–newsql-lv–newsql

root@newsqltest:~# resize2fs /dev/mapper/vg--newsql-lv--newsql
resize2fs 1.44.1 (24-Mar-2018)
Filesystem at /dev/mapper/vg--newsql-lv--newsql is mounted on /data; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 3
The filesystem on /dev/mapper/vg--newsql-lv--newsql is now 5240832 (4k) blocks long.

7. 查看:

df -h 当发现该逻辑卷(resize2fs /dev/mapper/vg–newsql-lv–newsql)的空间增大时,示意增加胜利。

root@newsqltest:~# df -h
Filesystem                         Size  Used Avail Use% Mounted on
udev                               3.9G     0  3.9G   0% /dev
tmpfs                              798M  3.2M  795M   1% /run
/dev/vda2                           39G  2.8G   35G   8% /
tmpfs                              3.9G     0  3.9G   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
tmpfs                              3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/vda1                          547M   77M  430M  16% /boot
/dev/mapper/vg--newsql-lv--newsql   20G   44M   19G   1% /data

正文完
 0