前提:确保裁减后容量要不原来设备已用的容量要大
1、取消挂载,停止使用
# umount /dev/mapper/mysql--vg-mysql--lv
2、手工检测文件系统是否有错
# fsck -f /dev/mysql-vg/mysql-lv
3、调整文件系统的容量
# resize2fs /dev/mysql-vg/mysql-lv 1.50G
4、裁减容量
# lvreduce -L 1.50G /dev/mysql-vg/mysql-lv
WARNING: Reducing active logical volume to 1.51 GB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce mysql-lv? [y/n]: y
Reducing logical volume mysql-lv to 1.51 GB
Logical volume mysql-lv successfully resized
# lvs
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
mysql-lv mysql-vg -wi-a- 1.51G
5、再次检查文件系统
-------------------------------------------------------------------------------
例子1:实现LVM条带化
# pvs
PV VG Fmt Attr PSize PFree
/dev/sda7 mysql-vg lvm2 a- 1.91G 936.00M
/dev/sda8 mysql-vg lvm2 a- 1.91G 1.91G
创建:
# lvcreate -L 300M -n webroot -i 2 mysql-vg
Using default stripesize 64.00 KB
Rounding size (75 extents) up to stripe boundary size (76 extents)
Logical volume "webroot" created
# pvs
PV VG Fmt Attr PSize PFree
/dev/sda7 mysql-vg lvm2 a- 1.91G 784.00M
/dev/sda8 mysql-vg lvm2 a- 1.91G 1.77G
验证
# iostat -dk sda7 sda8 2
例子2:实现lvm镜像
# lvcreate -L 500M -n uplv -m 1 mysql-vg
Logical volume "uplv" created
-m 1 把数据保存到一个原始设备,明且镜像保存到另外一个原始设备。
至少需要三个原始设备,其中还有一个保存镜像日志
删除逻辑卷
# lvremove /dev/mysql-vg/uplv
例子3:实现lvm快照
快照卷不支持镜像lv
对一个普通的lv建立快照
# lvcreate -L 100M -n mysql-lv-sp -s /dev/mysql-vg/mysql-lv
Logical volume "mysql-lv-sp" created
挂载,看到的数据和mysql-lv是一样
# mount /dev/mysql-vg/mysql-lv-sp /mnt/mysql-lv-sp/
根据快照原理,一般用于快速备份。
例子:使用快照卷实现mysql的"热"备份
前提:mysql数据文件保存在逻辑卷
锁表
mysql> flush tables with read lock;
创建快照
解锁
mysql> unlock tables;
挂载快照卷,拷贝数据到备份目录
# lvcreate -L 100M -n mysql-lv-sp -s /dev/mysql-vg/mysql-lv
Logical volume "mysql-lv-sp" created
==========================================
实现iSCSI
硬盘 ------数据总线------主机 <---直连存储
硬盘 ------FC网络-------主机 <--- SAN
硬盘 ----Internet(tcp/ip)---主机 <--- IPSAN
tartgetInitiator
tcp/ip协议头[ scsi协议数据 ]
一、实现iscsi的target (模拟存储的服务器)
# yum install scsi-target-utils -y
# vim /etc/tgt/targets.conf
# vim /etc/tgt/targets.conf
<target iqn.2011-11.com.upl:webroot>
backing-store /dev/sda5
</target>
# service tgtd start
# tgtadm --lld iscsi --op show --mode target
Target 1: iqn.2011-11.com.upl:webroot
System information:
Driver: iscsi
State: ready
I_T nexus information:
LUN information:
LUN: 0
Type: controller
SCSI ID: deadbeaf1:0
SCSI SN: beaf10
Size: 0 MB
Online: Yes
Removable media: No
Backing store: No backing store
LUN: 1
Type: disk
SCSI ID: deadbeaf1:1
SCSI SN: beaf11
Size: 2056 MB
Online: Yes
Removable media: No
Backing store: /dev/sda5
Account information:
ACL information:
ALL