lvm disk space for server consolidation

1    LVM 2 will achieve the total disk space "combined" and mount it to the same directory

1.1   Partition

First check disk information on non-partitioned disk partitioning process (select the disk you want to merge, here is vdb, vdc).

 

 

 

Above, it can be seen there is no partition plate 5, selected dev / vdb to partition, as follows:

 

 

 

 

 Input p, and sequentially input the figure:

 

 

 Finally, view the partition result, as shown:

 

 

 / Dev / vdc disc can repeat the above operation.

1.2   Creating Physical Volumes

First check the LVM is not installed, use yum list installed | grep lvm look no installation, if not installed with yum install lvm2 command it.

The command to create a physical volume pvcreate; use the command you want to add to all partitions or create disk volumes group physical volume;

 

 

 1.3   to create a volume group

Command to create a volume group is vgcreate; use this command to create a complete volume group physical volume pvcreate established;

It will create a physical volume / dev / vdb1 for the volume group named vgmongo of:

 

 

 1.4   Add a new physical volume into the volume group

This step is the critical step 2 into one of the disk space; when the system or add a new physical disk volume, and to add it to the existing volume group, can use vgextend command;

Adding physical volume / dev / vdc1 to vgmongo volume group:

 

 

 1.5   View Volume Groups

Check the volume group with vgs:

 

 

     From the results echo command vgs view volume group vgmongo successfully added, and the total size of the total space for the two physical disks (depending conversion units, so it is not accurate 43G).

1.6   Creating a Logical Volume

Command to create a logical volume lvcreate; use this command to create a logical volume on a volume group created using vgcreate.

在卷组vgmongo上创建一个名为lvmongo的逻辑卷,起大小为39.99G;

-n:指定逻辑卷名                   -L:指定逻辑卷大小

 

 

 1.7   格式化逻辑卷

将创建的lvmysql逻辑卷格式化为ext4 

 

 

 1.8   创建挂载目录并挂载

创建挂载目录(/mongodb_data)并挂载。

 

 

 做开机自动挂载

编辑 /etc/fstab  添加红色圈内容

 

 

 1.9   查看是否挂载成功

 

 

 2    LVM对现有盘进行动态扩容

当前将/dev/vdd 盘的空间加入mongodb_data中 操作如下

2.1   先做分区

具体实现参考 1.1磁盘分区

2.2   格式化分区

mkfs -t ext4 /dev/vdd1

 

 

 2.3   查看磁盘卷组信息

 

 

 2.4   创建物理卷

创建物理卷的命令为pvcreate

 

 

 2.5   扩展卷组

注意此处是扩展卷组不是创建。使用vgextend命令在现有的卷组vgmongo上添加 vdd1。

 

 

 2.6   扩展逻辑卷

扩展逻辑卷, 即扩容,将添加的大小增加进来。

lvextend -l +100%FREE /dev/mapper/vgmongo-lvmongo

 

 

 # 上述命令是将所有的空闲空间都扩容到逻辑卷中, 也可指定扩容的大小:

lvextend -l +100G /dev/mapper/vgmongo-lvmongo

2.7   查看磁盘卷组信息

 

 

 2.8   调整文件系统的大小

重新读取磁盘大小。

resize2fs /dev/mapper/vgmongo-lvmongo

 

 

 2.9   确认操作成功

查看空间大小变化。

 

Guess you like

Origin www.cnblogs.com/long88-club/p/12208554.html