学习Linux的第十三天(Vdo卷的创建)

4. vdo卷的创建
什么是vdo技术,这是RHEL8中特有的技术
红帽公司收购了一个公司 叫 permabit
vdo就是 permabit这个公司的技术
vdo也不是使用lvm来管理,是一个单独的技术。
vdo最大的作用就是节省硬盘空间,可以做到一个1TB的硬盘,直接存放3TB的数据甚至更多
vdo是怎么实现这个功能的? 靠的就是删除和压缩解压缩技术 重删就是把硬盘里相同的数据以前要存多份,现在会把多余的删掉,只留一份。,压缩算法来节省空间。

我们要使用vdo技术 将一块20 GD的硬盘,直接做成60G,并且挂载到系统上直接使用

yum install -y  vdo     kmod-kvdo 

安装时间较长,大约需要几分钟,安装完成以后需要重启设备

[root@rhel8-server ~]# vdo create   --name=testvdo   --device=/dev/nvme0n3  --vdoLogicalSize=60G
Creating VDO testvdo
      The VDO volume can address 16 GB in 8 data slabs, each 2 GB.
      It can grow to address at most 16 TB of physical storage in 8192 slabs.
      If a larger maximum size might be needed, use bigger slabs.
Starting VDO testvdo
Starting compression on VDO testvdo
VDO instance 0 volume is ready at /dev/mapper/testvdo
[root@rhel8-server ~]# lsblk 
NAME              MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0                11:0    1  6.6G  0 rom  /run/media/root/RHEL-8-0-0-BaseOS-x86_64
nvme0n1           259:0    0   20G  0 disk 
├─nvme0n1p1       259:1    0    1G  0 part /boot
└─nvme0n1p2       259:2    0   19G  0 part 
  ├─rhel-root     253:0    0   17G  0 lvm  /
  └─rhel-swap     253:1    0    2G  0 lvm  [SWAP]
nvme0n2           259:3    0   20G  0 disk 
├─nvme0n2p1       259:4    0    5G  0 part 
│ └─testvg-testlv 253:2    0  4.8G  0 lvm  /volume1
├─nvme0n2p2       259:5    0    5G  0 part 
│ └─myvg-mylv     253:3    0    4G  0 lvm  /new-volume
└─nvme0n2p3       259:6    0    2G  0 part [SWAP]
nvme0n3           259:7    0   20G  0 disk 
└─testvdo         253:4    0   60G  0 vdo  
[root@rhel8-server ~]# mkfs.xfs    /dev/mapper/testvdo 
meta-data=/dev/mapper/testvdo    isize=512    agcount=4, agsize=3932160 blks
         =                       sectsz=4096  attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=15728640, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=7680, version=2
         =                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

[root@rhel8-server ~]# mkdir   /vdoblock

[root@rhel8-server /]# vim   /etc/fstab 

/dev/mapper/testvdo     /vdoblock    xfs  defaults,x-systemd.requires=vdo.service  0  0 
[root@rhel8-server /]# mount -a
[root@rhel8-server /]# df  -hT
Filesystem                Type      Size  Used Avail Use% Mounted on
devtmpfs                  devtmpfs  1.8G     0  1.8G   0% /dev
tmpfs                     tmpfs     1.9G     0  1.9G   0% /dev/shm
tmpfs                     tmpfs     1.9G   10M  1.9G   1% /run
tmpfs                     tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/rhel-root     xfs        17G  4.2G   13G  25% /
/dev/mapper/myvg-mylv     xfs       4.0G   61M  4.0G   2% /new-volume
/dev/mapper/testvg-testlv ext4      4.7G   16M  4.4G   1% /volume1
/dev/nvme0n1p1            xfs      1014M  243M  772M  24% /boot
tmpfs                     tmpfs     371M   16K  371M   1% /run/user/42
tmpfs                     tmpfs     371M  2.3M  369M   1% /run/user/0
/dev/sr0                  iso9660   6.7G  6.7G     0 100% /run/media/root/RHEL-8-0-0-BaseOS-x86_64
/dev/mapper/testvdo       xfs        60G  461M   60G   1% /vdoblock

实验5:关于逻辑卷的缩小

[root@rhel8-server /]# df  -hT     查看一下目前的大小
Filesystem                Type      Size  Used Avail Use% Mounted on
devtmpfs                  devtmpfs  1.8G     0  1.8G   0% /dev
tmpfs                     tmpfs     1.9G     0  1.9G   0% /dev/shm
tmpfs                     tmpfs     1.9G   10M  1.9G   1% /run
tmpfs                     tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/rhel-root     xfs        17G  4.2G   13G  25% /
/dev/mapper/myvg-mylv     xfs       4.0G   61M  4.0G   2% /new-volume
/dev/mapper/testvg-testlv ext4      4.7G   16M  4.4G   1% /volume1
/dev/nvme0n1p1            xfs      1014M  243M  772M  24% /boot
tmpfs                     tmpfs     371M   16K  371M   1% /run/user/42
tmpfs                     tmpfs     371M  2.3M  369M   1% /run/user/0
/dev/sr0                  iso9660   6.7G  6.7G     0 100% /run/media/root/RHEL-8-0-0-BaseOS-x86_64
/dev/mapper/testvdo       xfs        60G  463M   60G   1% /vdoblock

在做磁盘裁剪的时候,首先必须要把文件系统给取消挂载

[root@rhel8-server /]# umount  /dev/mapper/testvg-testlv 
[root@rhel8-server /]# df -hT
Filesystem            Type      Size  Used Avail Use% Mounted on
devtmpfs              devtmpfs  1.8G     0  1.8G   0% /dev
tmpfs                 tmpfs     1.9G     0  1.9G   0% /dev/shm
tmpfs                 tmpfs     1.9G   10M  1.9G   1% /run
tmpfs                 tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/rhel-root xfs        17G  4.2G   13G  25% /
/dev/mapper/myvg-mylv xfs       4.0G   61M  4.0G   2% /new-volume
/dev/nvme0n1p1        xfs      1014M  243M  772M  24% /boot
tmpfs                 tmpfs     371M   16K  371M   1% /run/user/42
tmpfs                 tmpfs     371M  2.3M  369M   1% /run/user/0
/dev/sr0              iso9660   6.7G  6.7G     0 100% /run/media/root/RHEL-8-0-0-BaseOS-x86_64
/dev/mapper/testvdo   xfs        60G  463M   60G   1% /vdoblock

裁剪前必须要检测文件系统,避免把文件系统的错误扩大化导致文件系统奔溃

[root@rhel8-server /]# e2fsck -f   /dev/testvg/testlv 
e2fsck 1.44.3 (10-July-2018)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/testvg/testlv: 11/319488 files (0.0% non-contiguous), 40540/1258496 blocks
[root@rhel8-server /]# 
[root@rhel8-server /]# resize2fs  /dev/testvg/testlv     2G
resize2fs 1.44.3 (10-July-2018)
Resizing the filesystem on /dev/testvg/testlv to 524288 (4k) blocks.
The filesystem on /dev/testvg/testlv is now 524288 (4k) blocks long.

[root@rhel8-server /]# lvreduce   -L   2G   /dev/testvg/testlv 
  WARNING: Reducing active logical volume to 2.00 GiB.
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce testvg/testlv? [y/n]: y
  Size of logical volume testvg/testlv changed from 4.80 GiB (1229 extents) to 2.00 GiB (512 extents).
  Logical volume testvg/testlv successfully resized.
[root@rhel8-server /]# mount -a
[root@rhel8-server /]# df  -hT
Filesystem                Type      Size  Used Avail Use% Mounted on
devtmpfs                  devtmpfs  1.8G     0  1.8G   0% /dev
tmpfs                     tmpfs     1.9G     0  1.9G   0% /dev/shm
tmpfs                     tmpfs     1.9G   10M  1.9G   1% /run
tmpfs                     tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/rhel-root     xfs        17G  4.2G   13G  25% /
/dev/mapper/myvg-mylv     xfs       4.0G   61M  4.0G   2% /new-volume
/dev/nvme0n1p1            xfs      1014M  243M  772M  24% /boot
tmpfs                     tmpfs     371M   16K  371M   1% /run/user/42
tmpfs                     tmpfs     371M  2.3M  369M   1% /run/user/0
/dev/sr0                  iso9660   6.7G  6.7G     0 100% /run/media/root/RHEL-8-0-0-BaseOS-x86_64
/dev/mapper/testvdo       xfs        60G  463M   60G   1% /vdoblock
/dev/mapper/testvg-testlv ext4      2.0G   12M  1.8G   1% /volume1

实验6 逻辑卷的删除

[root@rhel8-server /]# umount   /dev/mapper/testvg-testlv 
[root@rhel8-server /]# 
[root@rhel8-server /]# vim /etc/fstab      配置文件需要清除这一行命令
[root@rhel8-server /]# 
[root@rhel8-server /]# 
[root@rhel8-server /]# lvremove   /dev/testvg/testlv 
Do you really want to remove active logical volume testvg/testlv? [y/n]: y
  Logical volume "testlv" successfully removed
[root@rhel8-server /]# vgremove   testvg 
  Volume group "testvg" successfully removed
[root@rhel8-server /]# pvremove    /dev/nvme0n2p1 
  Labels on physical volume "/dev/nvme0n2p1" successfully wiped.

实验7 : 逻辑卷快照技术
LVM还具备有“快照卷”功能,该功能类似于虚拟机软件的还原时间点功能。例如,可以对某一个逻辑卷设备做一次快照,如果日后发现数据被改错了,就可以利用之前做好的快照卷进行覆盖还原。LVM的快照卷功能有两个特点:
快照卷的容量必须等同于逻辑卷的容量;
快照卷仅一次有效,一旦执行还原操作后则会被立即自动删除。

[root@rhel8-server /]# vgdisplay 
  --- Volume group ---
  VG Name               myvg
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <5.00 GiB
  PE Size               4.00 MiB
  Total PE              1279
  Alloc PE / Size       1024 / 4.00 GiB
  Free  PE / Size       255 / 1020.00 MiB
  VG UUID               6DqrkB-18SV-uf0r-AvzU-QgJY-8Zib-lc5OEe
   
[root@rhel8-server /]# echo "hello,world"    >   /new-volume/readme.txt     //在还原时间点快照前写入一个文件,验证恢复快照不会丢失之前的文件  
[root@rhel8-server /]# ls  -l   /new-volume/      检查刚刚写入的文件是否存在
total 4
-rw-r--r--. 1 root root 12 Jan 18 03:43 readme.txt
[root@rhel8-server /]# lvcreate   -L   120M   -s     -n  SNAP   /dev/myvg/mylv       //给这个lv卷打一个快照
  Logical volume "SNAP" created.
[root@rhel8-server /]# lvdisplay            //查看lv所有卷组,会发现快照卷已经存在了
  --- Logical volume ---
  LV Path                /dev/myvg/mylv
  LV Name                mylv
  VG Name                myvg
  LV UUID                LzpESZ-2eF4-j1hf-ZJAj-DYKA-dl1y-BsGTF0
  LV Write Access        read/write
  LV Creation host, time rhel8-server, 2022-01-18 01:51:32 -0500
  LV snapshot status     source of
                         SNAP [active]
  LV Status              available
  # open                 1
  LV Size                4.00 GiB
  Current LE             1024
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:3
   
  --- Logical volume ---
  LV Path                /dev/myvg/SNAP
  LV Name                SNAP
  VG Name                myvg
  LV UUID                uw7iP9-ahPA-W4b1-fgto-0UlM-p7Zi-ts3vxz
  LV Write Access        read/write
  LV Creation host, time rhel8-server, 2022-01-18 03:44:13 -0500
  LV snapshot status     active destination for mylv
  LV Status              available
  # open                 0
  LV Size                4.00 GiB
  Current LE             1024
  COW-table size         120.00 MiB
  COW-table LE           30
  Allocated to snapshot  0.00%
  Snapshot chunk size    4.00 KiB
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:6

在逻辑卷所挂载的目录中创建一个100MB的垃圾文件,然后再查看快照卷的状态。可以发现存储空间占的用量上升了

[root@rhel8-server /]# dd  if=/dev/zero    of=/new-volume/files   count=1  bs=100M
1+0 records in
1+0 records out
104857600 bytes (105 MB, 100 MiB) copied, 0.138176 s, 759 MB/s
[root@rhel8-server /]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/myvg/mylv
  LV Name                mylv
  VG Name                myvg
  LV UUID                LzpESZ-2eF4-j1hf-ZJAj-DYKA-dl1y-BsGTF0
  LV Write Access        read/write
  LV Creation host, time rhel8-server, 2022-01-18 01:51:32 -0500
  LV snapshot status     source of
                         SNAP [active]
  LV Status              available
  # open                 1
  LV Size                4.00 GiB
  Current LE             1024
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:3
   
  --- Logical volume ---
  LV Path                /dev/myvg/SNAP
  LV Name                SNAP
  VG Name                myvg
  LV UUID                uw7iP9-ahPA-W4b1-fgto-0UlM-p7Zi-ts3vxz
  LV Write Access        read/write
  LV Creation host, time rhel8-server, 2022-01-18 03:44:13 -0500
  LV snapshot status     active destination for mylv
  LV Status              available
  # open                 0
  LV Size                4.00 GiB
  Current LE             1024
  COW-table size         120.00 MiB
  COW-table LE           30
  Allocated to snapshot  83.67%
  Snapshot chunk size    4.00 KiB
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:6

恢复快照之前必须要取消挂载

[root@rhel8-server /]# umount   /new-volume 
[root@rhel8-server /]# lvconvert --merge   /dev/myvg/SNAP        通过lvconvert --merge 来指定快照SNAP恢复
  Merging of volume myvg/SNAP started.
  myvg/mylv: Merged: 35.58%
  myvg/mylv: Merged: 100.00%
[root@rhel8-server /]# mount -a         //挂载所有卷组
[root@rhel8-server /]# cd /new-volume/
[root@rhel8-server new-volume]# ll       //此时刚刚的100M垃圾随着快照技术已经删除了
total 4
-rw-r--r--. 1 root root 12 Jan 18 03:43 readme.txt
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值