重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
我的博客已迁移到xdoujiang.com请去那边和我交流 基础环境 1、当前版本 cat /etc/debian_version 7.8 2、安装包lvm2 apt-get install lvm2 -y 一、将sdb sdc sdd三块分区加到卷组(hadoop),并创建5G的逻辑卷(hadoop1),PE默认 1、使用pvcreate命令将sdb sdc sdd分区创建成物理卷(pvcreate - initialize a disk or partition for use by LVM) pvcreate /dev/sdb /dev/sdc /dev/sdd Writing physical volume data to disk "/dev/sdb" Physical volume "/dev/sdb" successfully created Writing physical volume data to disk "/dev/sdc" Physical volume "/dev/sdc" successfully created Writing physical volume data to disk "/dev/sdd" Physical volume "/dev/sdd" successfully created EXAMPLES Initialize partition #4 on the third SCSI disk and the entire fifth SCSI disk for later use by LVM: pvcreate /dev/sdc4 /dev/sde 2、使用pvs或pvdisplay命令查看 1)pvs(pvs - report information about physical volumes) PV VG Fmt Attr PSize PFree /dev/sdb lvm2 a-- 10.00g 10.00g /dev/sdc lvm2 a-- 10.00g 10.00g /dev/sdd lvm2 a-- 10.00g 10.00g 2)pvdisplay(pvdisplay - display attributes of a physical volume) "/dev/sdb" is a new physical volume of "10.00 GiB" --- NEW Physical volume --- PV Name /dev/sdb VG Name PV Size 10.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID OkVC5O-SWOq-daXZ-BrNy-Hy83-G9Sm-d8bMT4 "/dev/sdc" is a new physical volume of "10.00 GiB" --- NEW Physical volume --- PV Name /dev/sdc VG Name PV Size 10.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID 7vg9eM-pIRR-Ahi0-BNvn-A1pr-WQa0-hvdC9X "/dev/sdd" is a new physical volume of "10.00 GiB" --- NEW Physical volume --- PV Name /dev/sdd VG Name PV Size 10.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID MyPYTC-Vk4P-ltjL-SX6w-jK3V-422c-HACxOK 3、使用vgcreate命令创建hadoop卷组并将sdb sdc sdd加入到卷组里(vgcreate - create a volume group) vgcreate hadoop /dev/sdb /dev/sdc /dev/sdd Volume group "hadoop" successfully created 这里使用默认的PE 4MB EXAMPLES To create a volume group named test_vg using physical volumes /dev/sdk1, and /dev/sdl1 with default physical extent size of 4MB: vgcreate test_vg /dev/sdk1 /dev/sdl1 4、使用vgs或vgdisplay命令查看 1)vgs(vgs - report information about volume groups) VG #PV #LV #SN Attr VSize VFree hadoop 3 0 0 wz--n- 29.99g 29.99g 2)vgdisplay(vgdisplay - display attributes of volume groups) --- Volume group --- VG Name hadoop System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 3 Act PV 3 VG Size 29.99 GiB PE Size 4.00 MiB Total PE 7677 Alloc PE / Size 0 / 0 Free PE / Size 7677 / 29.99 GiB VG UUID 9BpObQ-0qNt-7MRM-cJ4Y-aMyE-5ZEd-GoSi9N 5、使用lvcreate命令创建逻辑卷为hadoop1 大小是5G(lvcreate creates a new logical volume in a volume group) lvcreate -L 5G -n hadoop1 hadoop Logical volume "hadoop1" created -L, --size LogicalVolumeSize[bBsSkKmMgGtTpPeE] Gives the size to allocate for the new logical volume.A size suffix of K for kilobytes,M for megabytes, G for gigabytes,T for terabytes,P for petabytes or E for exabytes is optional.Default unit is megabytes. 6、使用lvs或lvdisplay命令查看 1)lvs(lvs - report information about logical volumes) LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert hadoop1 hadoop -wi-a--- 5.00g 2)lvdisplay(lvdisplay - display attributes of a logical volume) --- Logical volume --- LV Path /dev/hadoop/hadoop1 LV Name hadoop1 VG Name hadoop LV UUID y8CHyc-G7du-h9jZ-XV4T-dvZC-bzv1-NdsbS0 LV Write Access read/write LV Creation host, time debian, 2015-06-12 23:51:09 -0400 LV Status available # open 0 LV Size 5.00 GiB Current LE 1280 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 254:0 7、将/dev/hadoop/hadoop1格式化成ext4 mkfs.ext4 /dev/hadoop/hadoop1 8、写进/etc/fatab中并挂载 /dev/mapper/hadoop-hadoop1 /hadoop ext4 defaults 0 0 mount -a 9、查看是否挂载成功 df -Th Filesystem Type Size Used Avail Use% Mounted on rootfs rootfs 9.2G 1.7G 7.1G 19% / udev devtmpfs 10M 0 10M 0% /dev tmpfs tmpfs 99M 256K 99M 1% /run /dev/disk/by-uuid/f730250f-21de-45dd-a3e7-6c5d74508f4b ext4 9.2G 1.7G 7.1G 19% / tmpfs tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs tmpfs 961M 0 961M 0% /run/shm /dev/sda5 ext4 17G 180M 16G 2% /opt /dev/mapper/hadoop-hadoop1 ext4 5.0G 138M 4.6G 3% /hadoop 二、将/dev/mapper/hadoop-hadoop1逻辑卷夸大到40G并挂载 1、使用pvcreate命令将sde分区创建成物理卷 pvcreate /dev/sde Writing physical volume data to disk "/dev/sde" Physical volume "/dev/sde" successfully created 2、使用vgextend命令将sde加入到卷组hadoop(vgextend - add physical volumes to a volume group) vgextend hadoop /dev/sde Volume group "hadoop" successfully extended Examples vgextend vg00 /dev/sda4 /dev/sdn1 tries to extend the existing volume group vg00 by the new physical volumes (see pvcreate(8)) /dev/sdn1 and /dev/sda4. 3、先查看下卷组有多少PE vgdisplay --- Volume group --- VG Name hadoop System ID Format lvm2 Metadata Areas 4 Metadata Sequence No 8 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 4 Act PV 4 VG Size 39.98 GiB PE Size 4.00 MiB Total PE 10236 Alloc PE / Size 8956 / 34.98 GiB Free PE / Size 1280 / 5.00 GiB VG UUID 9BpObQ-0qNt-7MRM-cJ4Y-aMyE-5ZEd-GoSi9N 一共有10236个PE 4、使用lvextend命令将现有逻辑卷为hadoop1增大到40G(lvextend - extend the size of a logical volume) lvextend -l 10236 /dev/hadoop/hadoop1 Extending logical volume hadoop1 to 39.98 GiB Logical volume hadoop1 successfully resized -l, --extents [+]LogicalExtentsNumber[%{VG|LV|PVS|FREE|ORIGIN}] Extend or set the logical volume size in units of logical extents. 5、使用resize2fs命令扩大文件系统(resize2fs - ext2/ext3/ext4 file system resizer) resize2fs /dev/hadoop/hadoop1 resize2fs 1.42.5 (29-Jul-2012) Filesystem at /dev/hadoop/hadoop1 is mounted on /hadoop; on-line resizing required old_desc_blocks = 1, new_desc_blocks = 3 Performing an on-line resize of /dev/hadoop/hadoop1 to 10481664 (4k) blocks. The filesystem on /dev/hadoop/hadoop1 is now 10481664 blocks long. 6、最后检查下是否扩大到40G了 df -Th Filesystem Type Size Used Avail Use% Mounted on rootfs rootfs 9.2G 1.7G 7.1G 19% / udev devtmpfs 10M 0 10M 0% /dev tmpfs tmpfs 99M 260K 99M 1% /run /dev/disk/by-uuid/f730250f-21de-45dd-a3e7-6c5d74508f4b ext4 9.2G 1.7G 7.1G 19% / tmpfs tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs tmpfs 961M 0 961M 0% /run/shm /dev/sda5 ext4 17G 180M 16G 2% /opt /dev/mapper/hadoop-hadoop1 ext4 40G 143M 38G 1% /hadoop 三、参考文章 https://wiki.archlinux.org/index.php/LVM_%28%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87%29