具体操作
-
对添加的硬盘进行分区(fdisk /dev/[hs]d[a-z])
-
fdisk /dev/sdb 注意修改分区类型为8e
-
对创建的分区创建物理卷(pvcreate)
-
pvcreate /dev/sdc
-
给逻辑卷创建逻辑容器(卷组)
-
vgcreate myvg /dev/sdb[1-3] /dev/sdc
-
在卷组创建大小不同的逻辑卷(lvcreate)
-
lvcreate -L 2G -n mylv1 myvg
-
给以存在的卷组扩大容量
-
vgextend myvg /dev/sdd
-
实现在线扩大LVM容量
-
lvextend -L +2G /dev/myvg/mylv1
-
实现缩减LVM容量(不支持在线缩减)
-
umount /dev/myvg/mylv1 #卸载分区
e2fsck -f /dev/myvg/mylv1 #强制检查文件系统
resize2fs /dev/myvg/mylv1 1G #缩减逻辑大小
lvreduce -L 1G /dev/myvg/mylv1 #缩减物理边界大小
-
减小卷组容量
pvmove /dev/sdb1 #将/dev/sdb1上存储的数据移到其它物理卷中
vgreduce myvg /dev/sdb1 #将/dev/sdb1从myvg卷组中移除
pvremove /dev/sdb1 #将/dev/sdb1从物理卷上移除
-
利用给LVM创建快照,并完成备份并还原数据
在/mnt/lvm目录上,我们将原始的目录文件进行快照,然后将/mydata目录中的内容清空,并进行还原
[root@localhost ~]
# cd /mydata/
[root@localhost mydata]
# ls
index.html lost+found
[root@localhost mydata]
# cat index.html
test
[root@localhost mydata]
# lvcreate -L 30M -n backup -s -p r /dev/myvg/mylv1 #-L 快照大小 –n:快照名称 –p 权限只读 –s 创建快照
Rounding up size to full physical extent 32.00 MB
Logical volume
"backup"
created
[root@localhost mydata]
# ll
total 20
-rw-r--r-- 1 root root 5 Jun 28 01:04 index.html
drwx------ 2 root root 16384 Jun 28 00:47 lost+found
[root@localhost mydata]
# mkdir /tmp/backup #创建挂载目录
[root@localhost mydata]
# mount /dev/myvg/backup /tmp/backup/ #挂载
mount
: block device
/dev/myvg/backup
is write-protected, mounting
read
-only
[root@localhost mydata]
# cd /tmp/backup/
[root@localhost backup]
# ls
index.html lost+found
[root@localhost backup]
# mkdir /tmp/lvmbackup #创建备份目录
[root@localhost backup]
# tar jcf /tmp/lvmbackup/sandy.tar.bz2 index.html #打包并压缩文件
[root@localhost backup]
# cd ..
[root@localhost tmp]
# cd lvmbackup/
[root@localhost lvmbackup]
# ls #查看备份
sandy.
tar
.bz2
[root@localhost lvmbackup]
# cd /mydata/
[root@localhost mydata]
# ll
total 20
-rw-r--r-- 1 root root 5 Jun 28 01:04 index.html
drwx------ 2 root root 16384 Jun 28 00:47 lost+found
[root@localhost mydata]
# rm -rf * #删除所有文件
[root@localhost mydata]
#
[root@localhost mydata]
# ll
total 0
[root@localhost mydata]
# tar xf /tmp/lvmbackup/sandy.tar.bz2 #还原备份数据
[root@localhost mydata]
# ll
total 4
-rw-r--r-- 1 root root 5 Jun 28 01:04 index.html
[root@localhost mydata]
# cat index.html
test
[root@localhost mydata]
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2
9.5G 1.8G 7.2G 21% /
/dev/sda3
4.8G 138M 4.4G 4%
/data
/dev/sda1
251M 17M 222M 7%
/boot
tmpfs 60M 0 60M 0%
/dev/shm
/dev/mapper/myvg-mylv1
1008M 67M 901M 7%
/mydata
/dev/mapper/myvg-mylv1
1008M 67M 901M 7%
/tmp/backup
[root@localhost mydata]
#