线上服务器磁盘资源不够用了,有没有,苦恼!!!
把磁盘相互挂载,,不好用有土鳖。。让那帮死开发瞧不起。
还好你来了。。。LVM逻辑卷管理:lvm的构成如下图
PV:是物理的磁盘分区
VG:LVM中的物理的磁盘分区,也就是PV,必须加入VG,可以将VG理解为一个仓库或者是几个大的硬盘。
LV:也就是从VG中划分的逻辑分区
线上的资源环境是这样的:
[admin@56_74 ~]# df -ThFilesystem Type Size Used Avail Use% Mounted on/dev/sda1 ext3 9.9G 1.6G 7.8G 17% //dev/sda3 ext3 20G 240M 19G 2% /usr/local/dev/sda4 ext3 103G 132M 98G 1% /datatmpfs tmpfs 16G 32K 16G 1% /dev/shm/dev/sdb1 ext3 134G 129M 128G 1% /data1
/data 和/data1 各 一百多G,看着愁人啊~~~能合并使用就好了,不是吗?
第一步,umount /data 和/data1的磁盘,并注释fstab的磁盘信息,不然小心kernel 恐慌。。。哈哈
第二步,变更/dev/sda4和/data/sdb1的磁盘类型
先搞/data/sdb1 [admin@56_74 ~]# fdisk /dev/sdbWARNING: 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): pDisk /dev/sdb: 146.2 GB, 146163105792 bytes255 heads, 63 sectors/track, 17769 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000 Device Boot Start End Blocks Id System/dev/sdb1 1 17769 142729461 83 LinuxCommand (m for help): tSelected partition 1Hex code (type L to list codes): L 0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris 1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT- 2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT- 3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT- 4 FAT16 <32M 41 PPC PReP Boot 85 Linux extended c7 Syrinx 5 Extended 42 SFS 86 NTFS volume set da Non-FS data 6 FAT16 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / . 7 HPFS/NTFS 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility 8 AIX 4f QNX4.x 3rd part 8e Linux LVM df BootIt 9 AIX bootable 50 OnTrack DM 93 Amoeba e1 DOS access a OS/2 Boot Manag 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O b W95 FAT32 52 CP/M 9f BSD/OS e4 SpeedStor c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs e W95 FAT16 (LBA) 54 OnTrackDM6 a5 FreeBSD ee GPT f W95 Ext'd (LBA) 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/10 OPUS 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b11 Hidden FAT12 5c Priam Edisk a8 Darwin UFS f1 SpeedStor 12 Compaq diagnost 61 SpeedStor a9 NetBSD f4 SpeedStor 14 Hidden FAT16 <3 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary 16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS 17 Hidden HPFS/NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE 18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto1b Hidden W95 FAT3 75 PC/IX bb Boot Wizard hid fe LANstep 1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT 1e Hidden W95 FAT1Hex code (type L to list codes): 8eChanged system type of partition 1 to 8e (Linux LVM)Command (m for help): pDisk /dev/sdb: 146.2 GB, 146163105792 bytes255 heads, 63 sectors/track, 17769 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000 Device Boot Start End Blocks Id System/dev/sdb1 1 17769 142729461 8e Linux LVMCommand (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.[admin@56_74 ~]# partprobe /dev/sdb
再搞SDA4
[admin@56_74 ~]# fdisk /dev/sdaWARNING: 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): pDisk /dev/sda: 146.2 GB, 146163105792 bytes64 heads, 32 sectors/track, 139392 cylindersUnits = cylinders of 2048 * 512 = 1048576 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00064d08 Device Boot Start End Blocks Id System/dev/sda1 * 1 10241 10486768 83 Linux/dev/sda2 10242 12289 2097152 82 Linux swap / Solaris/dev/sda3 12290 32769 20971520 83 Linux/dev/sda4 32770 139392 109181952 83 LinuxCommand (m for help): tPartition number (1-4): 4Hex code (type L to list codes): 8eChanged system type of partition 4 to 8e (Linux LVM)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)Syncing disks.[admin@56_74 ~]# partprobe /dev/sda
第三步:根据逻辑图,咱们创建PV:
[admin@56_74 ~]# pvcreate /dev/sda4 /dev/sdb1 File descriptor 3 (socket:[222175]) leaked on pvcreate invocation. Parent PID 12138: -bash Writing physical volume data to disk "/dev/sda4" Physical volume "/dev/sda4" successfully created Writing physical volume data to disk "/dev/sdb1" Physical volume "/dev/sdb1" successfully created
第四步,创建VG
[admin@56_74 ~]# vgcreate Vgroup1 /dev/sdb1 /dev/sda4 File descriptor 3 (socket:[222175]) leaked on vgcreate invocation. Parent PID 12138: -bash Volume group "Vgroup1" successfully created
第五步,创建lv,并格式化挂载
[admin@56_74 ~]# lvcreate -L 240G -n lv1 Vgroup1File descriptor 3 (socket:[222175]) leaked on lvcreate invocation. Parent PID 12138: -bash Logical volume "lv1" created[admin@56_74 ~]# mkfs.ext3 /dev/llog loop0 loop1 loop2 loop3 loop4 loop5 loop6 loop7 lp0 lp1 lp2 lp3 [admin@56_74 ~]# mkfs.ext3 /dev/llog loop0 loop1 loop2 loop3 loop4 loop5 loop6 loop7 lp0 lp1 lp2 lp3 [admin@56_74 ~]# mkfs.ext3 /dev/Vgroup1/lv1 mke2fs 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 blocks15728640 inodes, 62914560 blocks3145728 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=42949672961920 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, 11239424, 20480000, 23887872Writing inode tables: done Creating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 24 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.[admin@56_74 ~]# [admin@56_74 ~]# [admin@56_74 ~]# mount /dev/Vgroup1/lv1 /data
[admin@56_74 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on/dev/sda1 ext3 9.9G 1.6G 7.8G 17% //dev/sda3 ext3 20G 240M 19G 2% /usr/localtmpfs tmpfs 16G 32K 16G 1% /dev/shm/dev/mapper/Vgroup1-lv1 ext3 237G 188M 225G 1% /data小结:以下是摘自LVM管理的一部分命令。
一、PV管理
1、创建
pvcreate /dev/sdb1 #磁盘需要为lvm类型
2、查看
pvscan
3、删除
pvremove
二、VG管理
1、创建:
vgcreate [ -s <8M|16M> ] vg 0 /dev/sdb1
格式:vgcreate [-s <8M|16M|...>] vg0 /dev/sdb{1,2,3...}
-s:指定扩展块(PE)的大小,默认为4MB;(相当与磁盘上的簇,扩展逻辑卷的基本单位。 后面的值可以是8M 16M 32M 64M .....最多65532个扩展块。vg0:新创建的卷组的名字。2、查看
vgdisplay
vgscan
3、删除某个PV
vgreduce /dev/sdb1
4、删除整个vg
vgremove /dev/vg0
5、增加某个PV到vg中
vgextend vg0 /dev/sdb1
三、LV管理
1、创建
lvcreate -L 512M -n data vg0
#-L 指定磁盘大小 -n 指定磁盘名称
2、格式化
因为lv层级是可以被系统挂载的,所以可以进行格式化相应的文件系统
mkfs.ext3 /dev/vg0/data
3、增大lv的大小
lvextend -L +100M /dev/vg0/data
resize2fs /dev/vg0/data
4、减小lv的大小
lvreduce -L -100M /dev/vg0/data
resize2fs /dev/vg0/data
关于增大和删小的说明:如果增大没有什么,减小的时候,可能会对已有数据进行影响,如果当前已有数据远远大于削减后的磁盘容量,则削减容量的同时会删除一些数据。谨记
5、删除某个lv
lvremove /dae/vg0/data
好了,大总结:
LVM创建过程:PV - VG - LV
删除过程恰恰相反为:LV - VG -PV