当前位置:网站首页>分布式数据库使用逻辑卷管理存储之扩容
分布式数据库使用逻辑卷管理存储之扩容
2022-06-23 13:33:00 【ZNBase】
浪潮云溪数据库作为一款浪潮自主研发的国产分布式数据库,一大特性便是可支持 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 是手动挂载到虚机上的一块磁盘,执行命令如下:
[email protected]:~# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTvda 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[email protected]:~# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTvda 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 diskvdc 252:32 0 10G 0 disk[email protected]:~# fdisk -lDisk /dev/vda: 40 GiB, 42949672960 bytes, 83886080 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x9b600047Device Boot Start End Sectors Size Id Type/dev/vda1 * 2048 1171455 1169408 571M 83 Linux/dev/vda2 1171456 83886046 82714591 39.5G 83 LinuxDisk /dev/vdb: 64 MiB, 67108864 bytes, 131072 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x00000000Disk /dev/vdc: 10 GiB, 10737418240 bytes, 20971520 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytes
2. 使用 fdisk 将磁盘进行逻辑分区
fdisk /dev/vdc
m 来查看命令帮助;
n 添加一张新的 partition,划分分区,以及分区的大小,这里都使用默认值,创建一个分区;
w 命令保存并退出。
[email protected]:~# fdisk /dev/vdcWelcome 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): nPartition typep 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): wThe partition table has been altered.Calling ioctl() to re-read partition table.Syncing disks.[email protected]:~# 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 查看信息
[email protected]:~# pvcreate /dev/vdc1Physical volume "/dev/vdc1" successfully created.[email protected]:~# pvdisplay"/dev/vdc1" is a new physical volume of "<10.00 GiB"--- NEW Physical volume ---PV Name /dev/vdc1VG NamePV Size <10.00 GiBAllocatable NOPE Size 0Total PE 0Free PE 0Allocated PE 0PV UUID 5FxevL-aneV-Xhe6-pFEv-b3pH-l4v4-Gb6TeA
3). 创建 Volume Group (VG).
vgcreate vg-newsql /dev/vdc1
[email protected]:~# vgcreate vg-newsql /dev/vdc1Volume group "vg-newsql" successfully created[email protected]:~# vgscanReading 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 逻辑卷)
[email protected]:~# lvcreate -n lv-newsql -l 100%VG vg-newsqlLogical volume "lv-newsql" created.[email protected]:~# lvdisplay--- Logical volume ---LV Path /dev/vg-newsql/lv-newsqlLV Name lv-newsqlVG Name vg-newsqlLV UUID bMsyAX-xatH-cdTY-JbzE-4ao5-QR6h-j4Z7ONLV Write Access read/writeLV Creation host, time newsqltest, 2021-01-27 16:09:54 +0800LV Status available# open 0LV Size <10.00 GiBCurrent LE 2559Segments 1Allocation inheritRead ahead sectors auto- currently set to 256Block device 253:0
4. 格式化并挂载逻辑卷至 /data
1). 第一步格式化逻辑卷
mkfs.ext4 /dev/vg-newsql/lv-newsql
2). 将逻辑卷挂载到 home 文件夹下面
mount /dev/vg-newsql/lv-newsql /data
[email protected]:~# mkfs.ext4 /dev/vg-newsql/lv-newsqlmke2fs 1.44.1 (24-Mar-2018)Creating filesystem with 2620416 4k blocks and 655360 inodesFilesystem UUID: a667f950-9b91-45ce-9931-8fb147173054Superblock backups stored on blocks:32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632Allocating group tables: doneWriting inode tables: doneCreating journal (16384 blocks): doneWriting superblocks and filesystem accounting information: done[email protected]:~# mount /dev/vg-newsql/lv-newsql /datamount: /data: mount point does not exist.[email protected]:~# mkdir /data[email protected]:~# mount /dev/vg-newsql/lv-newsql /data[email protected]:~# df -hFilesystem Size Used Avail Use% Mounted onudev 3.9G 0 3.9G 0% /devtmpfs 798M 3.2M 795M 1% /run/dev/vda2 39G 2.8G 35G 8% /tmpfs 3.9G 0 3.9G 0% /dev/shmtmpfs 5.0M 0 5.0M 0% /run/locktmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup/dev/vda1 547M 77M 430M 16% /boottmpfs 798M 0 798M 0% /run/user/0/dev/mapper/vg--newsql-lv--newsql 9.8G 37M 9.3G 1% /data
至此,10G 的盘已卷组的方式挂载至 /data 目录。
- 扩容 -
1. 添加磁盘:
[email protected]:~# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTvda 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 diskvdc 252:32 0 10G 0 disk`-vdc1 252:33 0 10G 0 part`-vg--newsql-lv--newsql 253:0 0 10G 0 lvm /datavdd 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
[email protected]:~# parted /dev/vdeGNU Parted 3.2Using /dev/vdeWelcome to GNU Parted! Type 'help' to view a list of commands.(parted) helpalign-check TYPE N check partition N for TYPE(min|opt) alignmenthelp [COMMAND] print general help, or help on COMMANDmklabel,mktable LABEL-TYPE create a new disklabel (partition table)mkpart PART-TYPE [FS-TYPE] START END make a partitionname NUMBER NAME name partition NUMBER as NAMEprint [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all found partitions, or a particular partitionquit exit programrescue START END rescue a lost partition near START and ENDresizepart NUMBER END resize partition NUMBERrm NUMBER delete partition NUMBERselect DEVICE choose the device to editdisk_set FLAG STATE change the FLAG on selected devicedisk_toggle [FLAG] toggle the state of FLAG on selected deviceset NUMBER FLAG STATE change the FLAG on partition NUMBERtoggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBERunit UNIT set the default unit to UNITversion 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.10TBalign-check TYPE N check partition N for TYPE(min|opt) alignmenthelp [COMMAND] print general help, or help on COMMANDmklabel,mktable LABEL-TYPE create a new disklabel (partition table)mkpart PART-TYPE [FS-TYPE] START END make a partitionname NUMBER NAME name partition NUMBER as NAMEprint [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all found partitions, or a particular partitionquit exit programrescue START END rescue a lost partition near START and ENDresizepart NUMBER END resize partition NUMBERrm NUMBER delete partition NUMBERselect DEVICE choose the device to editdisk_set FLAG STATE change the FLAG on selected devicedisk_toggle [FLAG] toggle the state of FLAG on selected deviceset NUMBER FLAG STATE change the FLAG on partition NUMBERtoggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBERunit UNIT set the default unit to UNITversion display the version number and copyright information of GNU PartedWarning: 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? yesWarning: The resulting partition is not properly aligned for best performance.Ignore/Cancel? ignore(parted) quitInformation: You may need to update /etc/fstab.
[email protected]:~# mkfs.ext4 /dev/vdemke2fs 1.44.1 (24-Mar-2018)Found a gpt partition table in /dev/vdeProceed anyway? (y,N) yCreating filesystem with 550502400 4k blocks and 137625600 inodesFilesystem UUID: a08b03f2-05b7-4029-b317-0e07f93fb6d2Superblock backups stored on blocks:32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,102400000, 214990848, 512000000Allocating group tables: doneWriting inode tables: doneCreating journal (262144 blocks): doneWriting superblocks and filesystem accounting information: done
3. 创建 pv 卷, 与使用 lvm 来管理这个分区中创建 Physical Volume 的步骤相同:
pvcreate /dev/vdd1
4. 扩展物理硬盘到同一个卷组里面,每个组管理不同物理磁盘:
vgextend vg-newsql /dev/vdd1
[email protected]:~# vgextend vg-newsql /dev/vdd1Volume group "vg-newsql" successfully extended
5. 从卷组里面向逻辑卷里面分配空间:
lvextend -l +100% FREE /dev/mapper/vg--newsql-lv--newsql(向逻辑卷里面分配空间)
[email protected]:~# lvextend -l +100%FREE /dev/mapper/vg--newsql-lv--newsqlSize 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
[email protected]:~# resize2fs /dev/mapper/vg--newsql-lv--newsqlresize2fs 1.44.1 (24-Mar-2018)Filesystem at /dev/mapper/vg--newsql-lv--newsql is mounted on /data; on-line resizing requiredold_desc_blocks = 2, new_desc_blocks = 3The filesystem on /dev/mapper/vg--newsql-lv--newsql is now 5240832 (4k) blocks long.
7. 查看:
df -h 当发现该逻辑卷(resize2fs /dev/mapper/vg--newsql-lv--newsql)的空间增大时,表示添加成功。
[email protected]:~# df -hFilesystem Size Used Avail Use% Mounted onudev 3.9G 0 3.9G 0% /devtmpfs 798M 3.2M 795M 1% /run/dev/vda2 39G 2.8G 35G 8% /tmpfs 3.9G 0 3.9G 0% /dev/shmtmpfs 5.0M 0 5.0M 0% /run/locktmpfs 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
边栏推荐
- Deci 和英特尔如何在 MLPerf 上实现高达 16.8 倍的吞吐量提升和 +1.74% 的准确性提升
- Runtime application self-protection (rasp): self-cultivation of application security
- Acquisition of wechat applet JSON for PHP background database transformation
- 【深入理解TcaplusDB技术】单据受理之表管理
- Low grain prices hurt farmers, low wages hurt farmers!
- [untitled]
- Detailed explanation of kubernetes log monitoring system architecture
- MIT 6.031 Reading5 : Version Control学习心得
- Penetration test - right raising topic
- php接收和发送数据
猜你喜欢

白皮书丨英特尔携手知名RISC-V工具提供商Ashling,着力扩展多平台RISC-V支持

构建英特尔 DevCloud

The data value reported by DTU cannot be filled into Tencent cloud database through Tencent cloud rule engine

Best practices for auto plug-ins and automatic batch processing in openvinotm 2022.1

【课程预告】基于飞桨和OpenVINO 的AI表计产业解决方案 | 工业读表与字符检测

Edge and IOT academic resources

leetcode:42.接雨水

微信小程序之下拉菜单场景

quartus調用&設計D觸發器——仿真&時序波驗證

Intel ® extensions for pytorch* accelerate pytorch
随机推荐
Quartus call & Design d Trigger - simulation & time sequence Wave Verification
Wechat applet pop up the optional menu from the bottom
Problems during MySQL uninstallation
[digital signal processing] linear time invariant system LTI (judge whether a system is a "non time varying" system | case 1 | transform before shift | shift before transform)
Ks008 SSM based press release system
使用OpenVINOTM预处理API进一步提升YOLOv5推理性能
【无标题】
Binding events of wechat applet in wx:for
Detailed explanation of serial port, com, UART, TTL, RS232 (485) differences
SQLserver2008r2安装dts组件不成功
渗透测试-提权专题
Technology creates value and teaches you how to collect wool
Go write file permission WriteFile (filename, data, 0644)?
Do you know which position in the IT industry has the most girls?
How to install the DTS component of SQL server2008r2 on win10 64 bit systems?
面向 PyTorch* 的英特尔 扩展助力加速 PyTorch
爱思唯尔-Elsevier期刊的校稿流程记录(Proofs)(海王星Neptune)(遇到问题:latex去掉章节序号)
DTU上报的数据值无法通过腾讯云规则引擎填入腾讯云数据库中
Hexiaopeng: if you can go back to starting a business, you won't name the product in your own name
【深入理解TcaplusDB技术】单据受理之表管理