Linux LVM disk creation and expansion

Linux LVM disk creation and expansion

Linux LVM disk creation and expansion

Since the disk capacity of a large project does not meet the operating requirements after the upper limit for a period of time, it needs to be dynamically expanded (without downtime or data migration). At this time, if the path of the project is managed by the LVM mechanism, then this demand will be It's easy to implement.

1. Before project deployment, create LVM mount

1. Query the current mountable physical disk

fdisk -l
//查看当前有多少未挂载的可用磁盘

2. Disk partition

fdisk /dev/sdb
//分别输入 n p 1 回车 回车 t L 8e wq 保存退出
fdisk /dev/sdc
//分别输入 n p 1 回车 回车 t L 8e wq 保存退出
fdisk /dev/sdd
//分别输入 n p 1 回车 回车 t L 8e wq 保存退出
fdisk /dev/sde
//分别输入 n p 1 回车 回车 t L 8e wq 保存退出

3. Create PV

pvcreate /dev/sdb1
pvcreate /dev/sdc1
pvcreate /dev/sdd1
pvcreate /dev/sde1
//创建了 4 个物理卷

4. Create VG

vgcreate vg_group /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1
//将 4个物理卷加入到一个卷组'vg_group'中(vg_group 为卷组名,可自定义)

4. Create LV

lvcreate -l 100%VG  -n vg_1  vg_group
//将卷组 100% 容量创建为名为'vg_1'的逻辑卷组(vg_1 为逻辑卷组名,可自定义)

5. View LV path

lvdisplay
//命令显示当前 LV 信息,记录 LV path 参数

6. Format LV path

mkfs.ext4 /dev/vg_group/vg_1
//将 /dev/vg_group/vg_1 格式化为 ext 格式

7. Mount the disk

mount /dev/vg_group/vg_1 /lvm_disk
//将格式化后的 LV path 挂载到本地目录'/lvm_disk'上
//(/lvm_disk 为本地项目运行的实际目录)

8. Set up automatic mounting

vim /etc/fstab
//添加下面内容后 wq 保存退出
/dev/vg_group/vg_1 /lvm_disk ext4 defaults 0 0
//重新加载挂载
mount -a

至此,为项目部署所准备的目录 '/lvm_disk' 就创建完毕,可以将项目部署到该路径下,方便后期实现动态扩容磁盘。




2. Dynamic expansion when the disk is insufficient in the later stage

First, you need to add a physical disk to the server instance where the project is located.
9. Query the current mountable physical disk

fdisk -l
//查看新添加的物理磁盘是否存在,或需要重启服务器实例

10. Disk partition

fdisk /dev/sdf
//分别输入 n p 1 回车 回车 t L 8e wq 保存退出

11. Create PV

pvcreate /dev/sdf1
//创建了 1 个新的物理卷

12. Add/stretch a new physical volume to the physical volume group

vgextend vg_group /dev/sdf1
//将新创建的物理卷添加到之前的物理卷组中(vg_group 为之前创建的卷组)

13. View the size of the stretched physical volume group

vgs
//查看拉伸后的卷组大小,若成功,容量会增加

14. Stretching the logical volume

lvextend -l 100%VG /dev/vg_group/vg_1
//将逻辑卷组大小拉伸至最大

15. Finally, stretch the file system size

resize2fs  /dev/vg_group/vg_1
//将实际使用的文件系统大小拉伸至最大

16. Check the system mount capacity

df -h
//若成功,/lvm_disk 路径容量会扩充了刚添加的物理磁盘的大小

至此,项目所在路径的容量动态扩容也完成,未停机、数据迁移。

Guess you like

Origin blog.csdn.net/iHot99/article/details/109096164