LVM应用实例(Dark)

LVM应用实例

案例的环境和需求描述如下:公司准备在Internet中搭建邮件服务器(RHEL 6系统平台),面向全国各地的员工及部分VIP客户提供电子邮箱空间。由于用户数量众多,邮件存储需要大量的空间,考虑到动态扩容的需要,计划增加两块SCSI硬盘并构建LVM逻辑卷 (挂载到“/mailbox”目录下)专门用于存放邮件数据。 
根据上述案例环境和需求,推荐的操作步骤如下所述。

(1 )关闭服务器主机,打开机箱,正确挂接两块SCSI新硬盘。 
(2 )开启服务器主机,并执行“fdisk -I”命令进行检查,确认已识别新增的硬盘(sdb、 sdc )。 
(3)在新磁盘中进行分区,将每块硬盘的所有空间划分为一个独立的主分区,并将分区类型更改为“8e”分好区后使用“fdisk- l”命令查看,确认结果如下所示。


一、格式化、转换分区类型

1.把sdb2转换成LVM类型的分区:

[[email protected] /]# fdisk /dev/sdb

WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to         switch off the mode (command ‘c‘) and change display units to         sectors (command ‘u‘).

Command (m for help): tPartition number (1-4): 2Hex code (type L to list codes): 8eChanged system type of partition 2 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sdb: 85.9 GB, 85899345920 bytes255 heads, 63 sectors/track, 10443 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0xa8f24694

   Device Boot      Start         End      Blocks   Id  System/dev/sdb1               1        2612    20980858+  83  Linux/dev/sdb2            2613        5224    20980890   8e  Linux LVM/dev/sdb3            5225       10443    41921617+  83  Linux

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

Calling ioctl() to re-read partition table.Syncing disks.[[email protected] /]#

2.创建sdc2分区,并转变成LVM类型:

[[email protected] /]# fdisk /dev/sdc

WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to         switch off the mode (command ‘c‘) and change display units to         sectors (command ‘u‘).

Command (m for help): nCommand action   e   extended   p   primary partition (1-4)2Invalid partition number for type `2‘Command action   e   extended   p   primary partition (1-4)pPartition number (1-4): 2First cylinder (2613-10443, default 2613):Using default value 2613Last cylinder, +cylinders or +size{K,M,G} (2613-10443, default 10443): +20FUnsupported suffix: ‘F‘.Supported: 10^N: KB (KiloByte), MB (MegaByte), GB (GigaByte)            2^N: K  (KibiByte), M  (MebiByte), G  (GibiByte)Last cylinder, +cylinders or +size{K,M,G} (2613-10443, default 10443): +20G

Command (m for help): P

Disk /dev/sdc: 85.9 GB, 85899345920 bytes255 heads, 63 sectors/track, 10443 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x8967e34e

   Device Boot      Start         End      Blocks   Id  System/dev/sdc1               1        2612    20980858+  83  Linux/dev/sdc2            2613        5224    20980890   83  Linux

错误操作:

Command (m for help): TPartition number (1-4): bePartition number (1-4): 2Hex code (type L to list codes): bChanged system type of partition 2 to b (W95 FAT32)

正确操作:

Command (m for help): tPartition number (1-4): 2Hex code (type L to list codes): 8eChanged system type of partition 2 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sdc: 85.9 GB, 85899345920 bytes255 heads, 63 sectors/track, 10443 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x8967e34e

   Device Boot      Start         End      Blocks   Id  System/dev/sdc1               1        2612    20980858+  83  Linux/dev/sdc2            2613        5224    20980890   8e  Linux LVM

Command (m for help):

3.保存

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.The kernel still uses the old table. The new table will be used atthe next reboot or after you run partprobe(8) or kpartx(8)

WARNING: If you have created or modified any DOS 6.xpartitions, please see the fdisk manual page for additionalinformation.Syncing disks.

4.探测

探测失败

[[email protected]test2 /]# partx /dev/sdcsdc   sdc1[[email protected]test2 /]# partx /dev/sdcsdc   sdc1[[email protected]test2 /]# partx -a /dev/sdcsdc   sdc1[[email protected]test2 /]# partx -a /dev/sdcsdc   sdc1

重启:

识别成功:

[root@test2 jason]# partprobe /dev/sdcsdc   sdc1  sdc2[root@test2 jason]# partprobe /dev/sdc

当前pv的信息

[ro[email protected] jason]# pvscan  PV /dev/sda2   VG vg_jason        lvm2 [19.51 GiB / 0    free]  PV /dev/sdb1                      lvm2 [20.01 GiB]  PV /dev/sdb2                      lvm2 [20.01 GiB]  Total: 3 [59.53 GiB] / in use: 1 [19.51 GiB] / in no VG: 2 [40.02 GiB][[email protected] jason]#

二、创建Logical Volume

1.创建pv

将sdc2创建成physical volume(物理卷):

[root@test2 jason]# pvcreate /dev/sdc2  Physical volume "/dev/sdc2" successfully created[root@test2 jason]#

再次查看pv信息:

[[email protected] jason]# pvscan  PV /dev/sda2   VG vg_jason        lvm2 [19.51 GiB / 0    free]  PV /dev/sdb1                      lvm2 [20.01 GiB]  PV /dev/sdb2                      lvm2 [20.01 GiB]  PV /dev/sdc2                      lvm2 [20.01 GiB]  Total: 4 [79.53 GiB] / in use: 1 [19.51 GiB] / in no VG: 3 [60.03 GiB][[email protected] jason]#

2.创建 VG

vg的信息:

[root@test2 jason]# lvscan  ACTIVE            ‘/dev/vg_jason/lv_root‘ [17.51 GiB] inherit  ACTIVE            ‘/dev/vg_jason/lv_swap‘ [2.00 GiB] inherit

创建mail_store的volume group(卷组):

[root@test2 jason]# pvcreate mail_store /dev/sdb2 /dev/sdc2  Device mail_store not found (or ignored by filtering).  dev_is_mpath: failed to get device for 8:18  Physical volume "/dev/sdb2" successfully created  Physical volume "/dev/sdc2" successfully created[root@test2 jason]#

再次查看vg信息:

[root@test2 jason]# vgscan  Reading all physical volumes.  This may take a while...  Found volume group "vg_jason" using metadata type lvm2

分析是因为上面的命令用错了,应该是vgcreate,而不是pvcreate

重新创建并查看:

[root@test2 jason]# vgcreate mail_store /dev/sdb2 /dev/sdc2  Volume group "mail_store" successfully created[root@test2 jason]# vgscan  Reading all physical volumes.  This may take a while...  Found volume group "mail_store" using metadata type lvm2  Found volume group "vg_jason" using metadata type lvm2[root@test2 jason]#

mail_store成功创建,并能通过vgscan查找到

[root@test2 jason]# lvcreate -L 35G -n mbox mail_store  Logical volume "mbox" created[root@test2 jason]# lvscan  ACTIVE            ‘/dev/mail_store/mbox‘ [35.00 GiB] inherit  ACTIVE            ‘/dev/vg_jason/lv_root‘ [17.51 GiB] inherit  ACTIVE            ‘/dev/vg_jason/lv_swap‘ [2.00 GiB] inherit[root@test2 jason]#

3.创建LV

创建前的lvscan:

[root@test2 jason]# lvscan  ACTIVE            ‘/dev/vg_jason/lv_root‘ [17.51 GiB] inherit  ACTIVE            ‘/dev/vg_jason/lv_swap‘ [2.00 GiB] inherit

创建mbox的lv并查看:

[root@test2 jason]# lvcreate -L 35G -n mbox mail_store  Logical volume "mbox" created[root@test2 jason]# lvscan  ACTIVE            ‘/dev/mail_store/mbox‘ [35.00 GiB] inherit  ACTIVE            ‘/dev/vg_jason/lv_root‘ [17.51 GiB] inherit  ACTIVE            ‘/dev/vg_jason/lv_swap‘ [2.00 GiB] inherit[root@test2 jason]#

创建目录

[root@test2 /]# mkdir /mailbox

4.格式化:

格式化成ext4

[root@test2 /]# mkfs.ext4 /dev/mail_store/mboxmke2fs 1.41.12 (17-May-2010)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks2293760 inodes, 9175040 blocks458752 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=4294967296280 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks:    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,    4096000, 7962624

Writing inode tables: doneCreating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 30 mounts or180 days, whichever comes first.  Use tune2fs -c or -i to override.[root@test2 /]#

5.挂载并查看:

[[email protected] /]# mount /dev/mail_store/mbox /mailbox/[[email protected] /]# df -hTFilesystem                   Type   Size  Used Avail Use% Mounted on/dev/mapper/vg_jason-lv_root ext4    18G  4.3G   13G  27% /tmpfs                        tmpfs  3.9G   72K  3.9G   1% /dev/shm/dev/sda1                    ext4   485M   40M  421M   9% /boot/dev/sdc1                    ext4    20G  421M   19G   3% /home/dev/mapper/mail_store-mbox  ext4    35G  176M   33G   1% /mailbox[[email protected] /]#

三、拓展篇:

1.在虚拟机中新建一个100G的硬盘(略):

2.只建一个分区,并转换成为LVM类型:

[[email protected] jason]# fdisk /dev/sddDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel with disk identifier 0xef9a8da9.Changes will remain in memory only, until you decide to write them.After that, of course, the previous content won‘t be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to         switch off the mode (command ‘c‘) and change display units to         sectors (command ‘u‘).

Command (m for help): nCommand action   e   extended   p   primary partition (1-4)pPartition number (1-4): 1First cylinder (1-13054, default 1):Using default value 1Last cylinder, +cylinders or +size{K,M,G} (1-13054, default 13054):Using default value 13054

Command (m for help): tSelected partition 1Hex code (type L to list codes): 8eChanged system type of partition 1 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sdd: 107.4 GB, 107374182400 bytes255 heads, 63 sectors/track, 13054 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0xef9a8da9

   Device Boot      Start         End      Blocks   Id  System/dev/sdd1               1       13054   104856223+  8e  Linux LVM

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

Calling ioctl() to re-read partition table.Syncing disks.[[email protected] jason]#

探测:

[root@test2 jason]# partprobe /dev/sddsdd   sdd1[root@test2 jason]# partprobe /dev/sdd

3.创建pv:

[[email protected] jason]# pvcreate /dev/sdd1  dev_is_mpath: failed to get device for 8:49  Physical volume "/dev/sdd1" successfully created

vg拓展mail_store:[[email protected] jason]# vgextend mail_store /dev/sdd1  Volume group "mail_store" successfully extended

vgdisplay mail_store:

[[email protected] jason]# vgdisplay mail_store  --- Volume group ---  VG Name               mail_store  System ID  Format                lvm2  Metadata Areas        3  Metadata Sequence No  3  VG Access             read/write  VG Status             resizable  MAX LV                0  Cur LV                1  Open LV               0  Max PV                0  Cur PV                3  Act PV                3  VG Size               140.01 GiB  PE Size               4.00 MiB  Total PE              35843  Alloc PE / Size       8960 / 35.00 GiB  Free  PE / Size       26883 / 105.01 GiB  VG UUID               yHpVfR-lbFL-vs9A-mzgz-m800-JLE2-Dt2z6F

[[email protected] jason]#

4.LV扩容

错误的语法:

[[email protected] jason]# lvextend -L +85G  mbox mail_store  Path required for Logical Volume "mbox"  Please provide a volume group name  Run `lvextend --help‘ for more information.

正确的lv扩容操作:

[root@test2 jason]# lvextend -L +85G /dev/mail_store/mbox  Extending logical volume mbox to 120.00 GiB  Logical volume mbox successfully resized

扩容后查看:

[root@test2 jason]# lvscan  ACTIVE            ‘/dev/mail_store/mbox‘ [120.00 GiB] inherit  ACTIVE            ‘/dev/vg_jason/lv_root‘ [17.51 GiB] inherit  ACTIVE            ‘/dev/vg_jason/lv_swap‘ [2.00 GiB] inherit

5.挂载

刚才为了重新加一个100G的硬盘重启,重启后的mount信息:

[[email protected] jason]# df -hTFilesystem                   Type   Size  Used Avail Use% Mounted on/dev/mapper/vg_jason-lv_root ext4    18G  4.3G   13G  27% /tmpfs                        tmpfs  3.9G   72K  3.9G   1% /dev/shm/dev/sda1                    ext4   485M   40M  421M   9% /boot/dev/sdc1                    ext4    20G  421M   19G   3% /home[[email protected] jason]# mount/dev/mapper/vg_jason-lv_root on / type ext4 (rw)proc on /proc type proc (rw)sysfs on /sys type sysfs (rw)devpts on /dev/pts type devpts (rw,gid=5,mode=620)tmpfs on /dev/shm type tmpfs (rw)/dev/sda1 on /boot type ext4 (rw)/dev/sdc1 on /home type ext4 (rw)none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)

重新挂载并查看:

[[email protected] jason]# mount /dev/mail_store/mbox /mailbox/[[email protected] jason]# mount/dev/mapper/vg_jason-lv_root on / type ext4 (rw)proc on /proc type proc (rw)sysfs on /sys type sysfs (rw)devpts on /dev/pts type devpts (rw,gid=5,mode=620)tmpfs on /dev/shm type tmpfs (rw)/dev/sda1 on /boot type ext4 (rw)/dev/sdc1 on /home type ext4 (rw)none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)/dev/mapper/mail_store-mbox on /mailbox type ext4 (rw)

查看mbox的容量:

[[email protected] jason]# df -hTFilesystem                   Type   Size  Used Avail Use% Mounted on/dev/mapper/vg_jason-lv_root ext4    18G  4.3G   13G  27% /tmpfs                        tmpfs  3.9G   72K  3.9G   1% /dev/shm/dev/sda1                    ext4   485M   40M  421M   9% /boot/dev/sdc1                    ext4    20G  421M   19G   3% /home/dev/mapper/mail_store-mbox  ext4    35G  176M   33G   1% /mailbox

6.更新磁盘容量

查看resize2fs的用法:

[[email protected] jason]# resize2fsresize2fs 1.41.12 (17-May-2010)Usage: resize2fs [-d debug_flags] [-f] [-F] [-M] [-P] [-p] device [new_size]

使用resize2fs更新mbox的容量:

[[email protected] jason]# resize2fs /dev/mail_store/mboxresize2fs 1.41.12 (17-May-2010)Filesystem at /dev/mail_store/mbox is mounted on /mailbox; on-line resizing requiredold desc_blocks = 3, new_desc_blocks = 8Performing an on-line resize of /dev/mail_store/mbox to 31457280 (4k) blocks.The filesystem on /dev/mail_store/mbox is now 31457280 blocks long.

更新成功:

[[email protected] jason]# df -hTFilesystem                   Type   Size  Used Avail Use% Mounted on/dev/mapper/vg_jason-lv_root ext4    18G  4.3G   13G  27% /tmpfs                        tmpfs  3.9G   72K  3.9G   1% /dev/shm/dev/sda1                    ext4   485M   40M  421M   9% /boot/dev/sdc1                    ext4    20G  421M   19G   3% /home/dev/mapper/mail_store-mbox  ext4   119G  188M  112G   1% /mailbox[[email protected] jason]#
时间: 2024-08-01 16:42:28

LVM应用实例(Dark)的相关文章

LVM应用实例

LVM应用实例 案例的环境和需求描述如下:公司准备在Internet中搭建邮件服务器(RHEL 6系统平台),面向全国各地的员工及部分VIP客户提供电子邮箱空间.由于用户数量众多,邮件存储需要大量的空间,考虑到动态扩容的需要,计划增加两块SCSI硬盘并构建LVM逻辑卷 (挂载到"/mailbox"目录下)专门用于存放邮件数据.根据上述案例环境和需求,推荐的操作步骤如下所述. (1 )关闭服务器主机,打开机箱,正确挂接两块SCSI新硬盘.(2 )开启服务器主机,并执行"fdis

LVM分区实例

大致思路: 1.创建物理卷,对磁盘分区进行初始化. 2.生成卷组. 3.在已有的卷组中创建逻辑卷. 4.格式化并挂载逻辑卷. LVM(Logical Volume Manager)是基于内核的一种逻辑卷管理器.适合管理大存储设备,并允许用户动态调整文件系统的大小.快照功能可以帮助我们快速备份数据. 几个概念: 物理卷(PV):是LVM的逻辑存储块. 卷组(VG):是LVM逻辑概念上的磁盘设备.由单个或多个物理卷组和而成. 物理长度(PE):逻辑意义上磁盘的最小存储单元.LVM默认PE大小为4MB

LVM逻辑卷:创建LVM分区实例

一.概述 LVM(Logical Volume Manager)是基于内核的一种逻辑卷管理器,LVM适合于管理大存储设备,并允许用户动态调整文件系统的大小.此外LVM快照功能可以帮助我们快速备份数据. (1)物理卷(PV):物理卷是最底层概念,是LVM的逻辑存储块,物理卷与磁盘分区是逻辑对应的关系.多个LVM物理卷可以合并或者拆分,从而实现容量的扩容和缩减. (2)卷组(VG):卷组是LVM逻辑概念上的磁盘设备,通过将单个或多个物理卷组合后生成卷组. (3)物理长度(PE):物理长度是将物理卷组

LVM: Logical Volume Manager 逻辑卷管理

一.LVM介绍 LVM: Logical Volume Manager, Version: 2 允许对卷进行方便操作的抽象层,包括重新设定文件系统的大小 允许在多个物理设备间重新组织文件系统 将设备指定为物理卷 用一个或者多个物理卷来创建一个卷组 le   逻辑盘区 ,从卷组中划分pe给逻辑卷后,即成为le pe : 物理盘区.即在卷组中指定的块,在物理设备中的表现 物理卷是用固定大小的物理区域( Physical Extent,PE)来定义的 在物理卷上创建的逻辑卷是由物理区域( PE)组成

LVM逻辑卷(理论实验结合学习更高效!)

本章和大家分享的是Linux系统中LVM逻辑卷的相关内容,接下来我们会从以下几个内容中进行详细说明:1.LVM概述2.LVM的管理命令3.LVM应用实例 LVM概述:Logical Volume Manager,逻辑卷管理:1.动态调整磁盘容量,从而提高磁盘管理的灵活性2./boot分区用于存放引导文件,不能基于LVM创建3.图形界面管理工具:system-config-lvm LVM机制的基本概念:1.PV(物理卷)最基本的结构单元2.VG(卷组)3.LV(逻辑卷) 主要命令: 功能 物理卷管

Linux命令 LVM与磁盘管理

LVM与磁盘配额一.LVM逻辑卷管理1.LVM概述Logical Volume Manager,逻辑卷管理(1)动态调整磁盘容量,从而提高磁盘管理的灵活性.(2)/boot分区用于存放引导文件,不能基于LVM创建(3)图形界面管理工具:system-config-lvmLVM机制的基本概念(1)PV (Physical Volume 物理卷)物理卷是LVM机制的基本储存设备,通常对应为一个普通分区或整个硬盘.物理卷是由多个默认大小为4MB的基本单元(PE)组成的,在它的头部会创建一个保留分区,用

LVM逻辑卷管理与实际操作

今天给大家介绍如何准确评估和分配各个磁盘的容量,掌握动态调整Linux分区容量的方法 · 文章总览1.LVM相关概述2.LVM逻辑卷相关命令介绍3.LVM应用实列 · ------------相关概述------------ LVM是Linux系统中对磁盘分区进行管理的一中逻辑机制,它是建立在硬盘和分区之上,文件系统之下的一个逻辑区,在建立文件系统上屏蔽了下层的磁盘分区布局,能够在保持现有数据不变的情况下动态调整磁盘容量,从而提高磁盘管理的灵活性.·在学习LVM的管理操作之前首先要了解LVM的几

理论+实操:LVM与磁盘配额

[TOC] 前言: LVM是逻辑卷管理的简称,它是Linux环境下对磁盘分区管理的一种机制,实现文件系统跨越不同磁盘和分区,工作原理是将若干个磁盘分区连接成一个整块卷组,在卷组上随意创建逻辑卷组,最后在逻辑卷组上创建文件系统,管理员可以动态调整逻辑卷的大小,不会丢失现有的数据,通过创建LVM可以对磁盘进行动态管理. 一:LVM(逻辑卷)概述 1.1 Logical Volume Manager,逻辑卷管理 动态调整磁盘容量,从而提高磁盘管理的灵活性 /boot(系统内核)分区用于存放引导文件,不

OpenStack之各组件介绍

OpenStack简介 OpenStack既是一个社区,也是一个项目和一个开源软件,它提供了一个部署云的操作平台或工具集.其宗旨在于:帮助组织运行为虚拟计算或存储服务的云,为公有云.私有云,也为大云.小云提供可扩展的.灵活的云计算. 以下是OpenStack的重要构成部分: Nova - 计算服务 Swift - 对象存储服务 Glance - 镜像服务 Keystone - 认证服务 Horizon - UI服务 Neutron-网络服务 Cinder-块存储服务 Ceilometer-监控服