标签:数据目录 lvm扩容
最近生产环境上MySQL数据目录需要扩容,于是在测试机器上做了实验。操作过程如下:
1. 创建与使用LVM
要创建一个LVM系统,一般需要经过以下几个步骤:
1.1 创建分区
使用分区工具(如:fdisk等)创建LVM分区,方法和创建其他一般分区的方式是
一样的,区别仅仅是LVM的分区类型为8e。本例将使用/dev/sdb1作为新分区来创
建LVM。
[root@lavenliu ~]# fdisk /dev/sdb n p 1 +1G t 1 8e w [root@lavenliu ~]# partprobe [root@lavenliu ~]# fdisk -l /dev/sdbDisk /dev/sdb: 8589 MB, 8589934592 bytes 255 heads, 63 sectors/track, 1044 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 1 123 987966 8e Linux LVM
1.2 创建PV
[root@lavenliu ~]# pvcreate /dev/sdb1 Writing physical volume data to disk "/dev/sdb1" Physical volume "/dev/sdb1" successfully created [root@lavenliu ~]# pvdisplay "/dev/sdb1" is a new physical volume of "964.81 MB" --- NEW Physical volume --- PV Name /dev/sdb1 VG Name <此处为空> PV Size 964.81 MB Allocatable NO PE Size (KByte) 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID QGSSt9-oFLu-bvs1-d3fd-PV0w-YNrh-82KRCU [root@lavenliu ~]# pvs PV VG Fmt Attr PSize PFree /dev/sdb1 <此处为空> lvm2 a-- 964.81M 964.81M
此时,我们看到了新增加的pv,因为它此时还未加入到一个VG当中,所以VG Name的值暂时为空。
1.3 创建VG
[root@lavenliu ~]# vgcreate VolGroup01 /dev/sdb1 Volume group "VolGroup01" successfully created [root@lavenliu ~]# vgs VG #PV #LV #SN Attr VSize VFree VolGroup00 1 2 0 wz--n- 37.88G 0 VolGroup01 1 0 0 wz--n- 964.00M 964.00M
创建完成VG之后,才能从VG中划分LV
1.4 创建LV
[root@lavenliu ~]# lvcreate -L 100M -n myLv01 VolGroup01 Logical volume "myLv01" created [root@lavenliu ~]# lvdisplay --- Logical volume --- LV Name /dev/VolGroup01/myLv01 VG Name VolGroup01 LV UUID 1TIUUs-QLvM-rzhA-io20-xoxh-aZwq-zQbZiC LV Write Access read/write LV Status available # open 0 LV Size 100.00 MB Current LE 25 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:2
创建了一个名为myLv01,容量大小事100M的分区,并且是从VolGroup01中划分的lv。
1.5 LV格式化及挂载
[root@lavenliu ~]# mkfs.ext3 /dev/VolGroup01/myLv01 mke2fs 1.39 (29-May-2006) Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) 25688 inodes, 102400 blocks 5120 blocks (5.00%) reserved for the super user First data block=1 Maximum filesystem blocks=67371008 13 block groups 8192 blocks per group, 8192 fragments per group 1976 inodes per group Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729 Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 22 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override [root@lavenliu ~]# mdir /test [root@lavenliu ~]# mount /dev/VolGroup01/myLv01 /test 99150 5664 88366 7% /test [root@lavenliu ~]# df -Ph Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup00-LogVol00 36G 5.6G 29G 17% / /dev/sda1 99M 12M 82M 13% /boot tmpfs 252M 0 252M 0% /dev/shm /dev/mapper/VolGroup01-myLv01 97M 5.6M 87M 7% /test
2. 扩容LVM
现在VolGroup01的容量为1G,myLv01的容量为100M,我们的目标是使VolGroup01
的容量变为2G,myLv01的容量变为200M。首先新建分区/dev/sdb2。
[root@lavenliu ~]# fdisk /dev/sdb n p 2 +1G t 2 8e w [root@lavenliu ~]# partprobe [root@lavenliu ~]# fdisk -l /dev/sdb Disk /dev/sdb: 8589 MB, 8589934592 bytes 255 heads, 63 sectors/track, 1044 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 1 123 987966 8e Linux LVM /dev/sdb2 124 246 987997+ 8e Linux LVM
2.1 VG的扩容}
[root@lavenliu ~]# pvcreate /dev/sdb2 Writing physical volume data to disk "/dev/sdb2" Physical volume "/dev/sdb2" successfully created [root@lavenliu ~]# vgextend VolGroup01 /dev/sdb2 Volume group "VolGroup01" successfully extended [root@lavenliu ~]# vgs VG #PV #LV #SN Attr VSize VFree VolGroup00 1 2 0 wz--n- 37.88G 0 VolGroup01 2 1 0 wz--n- 1.88G 1.69G
2.2 LV的扩容
[root@lavenliu ~]# lvextend -L 200M /dev/VolGroup01/myLv01 Extending logical volume myLv01 to 200.00 MB Logical volume myLv01 successfully resized [root@lavenliu ~]# resize2fs /dev/VolGroup01/myLv01 resize2fs 1.39 (29-May-2006) Filesystem at /dev/VolGroup01/myLv01 is mounted on /test; on-line resizing required Performing an on-line resize of /dev/VolGroup01/myLv01 to 204800 (1k) blocks. The filesystem on /dev/VolGroup01/myLv01 is now 204800 blocks long.
总结:本文所使用的磁盘分区形式可能与实际的生产环境有所区别,不过是名字
上的差别而已。我们这里使用的是/dev/sdb1和/dev/sdb2等,实际的存储形式可
能是/dev/xxxxxx等名称。
存储端增加了磁盘后,服务端需要进行磁盘扫描方可后续的使用该磁盘,这里只
需要把/sys/class/fc_host/hostX/issue_lip置为1即可。X的值根据实际情况
而定。
[root@lavenliu ~]# echo 1 > /sys/class/fc_host/hostX/issue_lip
本文出自 “天道酬勤” 博客,请务必保留此出处http://lavenliu.blog.51cto.com/5060944/1611229
标签:数据目录 lvm扩容
原文地址:http://lavenliu.blog.51cto.com/5060944/1611229