linux高级储存管理

linux高级储存管理,第1张

linux高级储存管理 1、lvm名词解释

2、lvm设备的建立
监控命令:
[root@node1 ~]# watch -n 1 "pvs;echo =======;vgs;echo ========;lvs;echo ====;df -h /weixindata"
[root@node1 ~]# fdisk /dev/vdb 

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-10485759, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-10485759, default 10485759): +1G

Created a new partition 1 of type 'Linux' and of size 1 GiB.
Partition #1 contains a xfs signature.

Do you want to remove the signature? [Y]es/[N]o: y

The signature will be removed by a write command.

Command (m for help): t 
Selected partition 1
Hex code (type L to list all codes): 8e  
Changed type of partition 'Linux' to 'Linux LVM'.

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 
First sector (2099200-10485759, default 2099200): 
Last sector, +sectors or +size{K,M,G,T,P} (2099200-10485759, default 10485759): +1G

Created a new partition 2 of type 'Linux' and of size 1 GiB.

Command (m for help): t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): 8e

Changed type of partition 'Linux' to 'Linux LVM'.

Command (m for help): wq
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

[root@node1 ~]# fdisk -l
Disk /dev/vda: 8 GiB, 8589934592 bytes, 16777216 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x657e7edc

Device     Boot   Start      End  Sectors  Size Id Type
/dev/vda1  *       2048  1026047  1024000  500M 83 Linux
/dev/vda2       1026048  2050047  1024000  500M 82 Linux swap / Solaris
/dev/vda3       2050048 16777215 14727168    7G 83 Linux


Disk /dev/vdb: 5 GiB, 5368709120 bytes, 10485760 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xa14f4727

Device     Boot   Start     End Sectors Size Id Type
/dev/vdb1          2048 2099199 2097152   1G 8e Linux LVM
/dev/vdb2       2099200 4196351 2097152   1G 8e Linux LVM 
root@node1 ~]# udevadm settle  同步分区表
[root@node1 ~]# pvcreate /dev/vdb1   制作物理卷,处理物理分区叫物理卷
  Physical volume "/dev/vdb1" successfully created.
[root@node1 ~]# pvcreate /dev/vdb2  制作物理卷,处理物理分区叫物理卷
  Physical volume "/dev/vdb2" successfully created.
[root@node1 ~]# vgcreate vg0 /dev/vdb1  制作物理卷组
  Volume group "vg0" successfully created
[root@node1 ~]# vgdisplay  查看物理卷组
  --- Volume group ---
  VG Name               vg0
  System ID             
  Format                lvm2
  metadata Areas        1
  metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               1020.00 MiB
  PE Size               4.00 MiB         pe是4M ,划分设备必须是pe的整数倍,所以在制做pv的时候可以指定pe的大小
  Total PE              255
  Alloc PE / Size       0 / 0   
  Free  PE / Size       255 / 1020.00 MiB
  VG UUID               ZgN301-saXX-ZU5G-caK6-WHP4-eVf3-SC9qmI
[root@node1 ~]# vgremove vg0  删除vg0重新指定
  Volume group "vg0" successfully removed
[root@node1 ~]# vgcreate -s 2M vg0 /dev/vdb1   制作vg时指定pe大小为2M
  Volume group "vg0" successfully created
[root@node1 ~]# vgdisplay 
  --- Volume group ---
  VG Name               vg0
  System ID             
  Format                lvm2
  metadata Areas        1
  metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               1022.00 MiB
  PE Size               2.00 MiB    pe变成2M
  Total PE              511
  Alloc PE / Size       0 / 0   
  Free  PE / Size       511 / 1022.00 MiB
  VG UUID               GhsiK9-KXD8-8Y6H-1yOF-aRnJ-mcFc-CtGQtl
[root@node1 ~]# lvcreate -L 22M -n lv0 vg0   -L 指定pe大小  -n名字  vg0表示在vg0取lv0
  Logical volume "lv0" created.
  [root@node1 ~]# lvcreate -L 22M -n lv0 vg0
  Logical volume "lv0" created.
[root@node1 ~]# mkfs.xfs /dev/vg0/lv0   格式化lv0
meta-data=/dev/vg0/lv0           isize=512    agcount=1, agsize=5632 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=5632, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=1368, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@node1 ~]# mount /dev/vg0/lv0 /weixindata/  挂载
3、lvm拉伸
[root@node1 ~]# lvextend -L 50M /dev/vg0/lv0  拉伸到50M
  Size of logical volume vg0/lv0 changed from 22.00 MiB (11 extents) to 50.00 MiB (25 extents).
  Logical volume vg0/lv0 successfully resized.
 [root@node1 ~]# xfs_growfs /dev/vg0/lv0 拉伸后,拉伸的空间也需要格式化
meta-data=/dev/mapper/vg0-lv0    isize=512    agcount=1, agsize=5632 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=5632, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=1368, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 5632 to 12800
 [root@node1 ~]# lvextend -L 1500M /dev/vg0/lv0  lvm拉伸到1500M不够情况
  Insufficient free space: 725 extents needed, but only 486 available
[root@node1 ~]# vgextend vg0 /dev/vdb2  拉伸vg
  Volume group "vg0" successfully extended
[root@node1 ~]# lvextend -L 1500M /dev/vg0/lv0  lvm拉伸就够用了
  Size of logical volume vg0/lv0 changed from 50.00 MiB (25 extents) to 1.46 GiB (750 extents).
  Logical volume vg0/lv0 successfully resized.
[root@node1 ~]# xfs_growfs /dev/vg0/lv0  格式化
meta-data=/dev/mapper/vg0-lv0    isize=512    agcount=3, agsize=5632 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=12800, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=1368, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 12800 to 384000
4、lvm缩减
[root@node1 ~]# umount /weixindata  卸载掉之前挂载,因为xfs格式不能缩减
[root@node1 ~]# mkfs.ext4 /dev/vg0/lv0  格式文件系统为ext4
[root@node1 ~]# mount /dev/vg0/lv0 /weixindata/ 挂载
[root@node1 ~]# lvextend -L 1800M /dev/vg0/lv0  拉伸设备
[root@node1 ~]# resize2fs /dev/vg0/lv0  拉伸文件系统
resize2fs 1.45.4 (23-Sep-2019)
Filesystem at /dev/vg0/lv0 is mounted on /weixindata; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/vg0/lv0 is now 460800 (4k) blocks long
[root@node1 ~]# e2fsck -f /dev/vg0/lv0 检测,防止数据拉的过小对数据造成损坏
e2fsck 1.45.4 (23-Sep-2019)
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/vg0/lv0: 11/120000 files (0.0% non-contiguous), 16862/460800 blocks
[root@node1 ~]# resize2fs /dev/vg0/lv0 500M  缩减文件系统为500M
resize2fs 1.45.4 (23-Sep-2019)
Resizing the filesystem on /dev/vg0/lv0 to 128000 (4k) blocks.
The filesystem on /dev/vg0/lv0 is now 128000 (4k) blocks long.
[root@node1 ~]# lvreduce -L 500M /dev/vg0/lv0   缩减设备
  WARNING: Reducing active logical volume to 500.00 MiB.
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vg0/lv0? [y/n]: y
  Size of logical volume vg0/lv0 changed from <1.76 GiB (900 extents) to 500.00 MiB (250 extents).
  Logical volume vg0/lv0 successfully resized.
[root@node1 ~]# mount /dev/vg0/lv0 /weixindata/ 挂载
root@node1 ~]# vgreduce vg0 /dev/vdb2   /dev/vdb2 设备时闲置的可以取出来
若没有闲置需要取出来
[root@node1 ~]# vgreduce vg0 /dev/vdb1  /dev/vdb1设备没有闲置取不出来
  Physical volume "/dev/vdb1" still in use
[root@node1 ~]# pvmove  /dev/vdb1  /dev/vdb2  将vdb1上的数据移动到vdb2上
  /dev/vdb1: Moved: 2.40%
  /dev/vdb1: Moved: 100.00%
[root@node1 ~]# vgreduce vg0 /dev/vdb1 缩减vg,取出vdb1
  Removed "/dev/vdb1" from volume group "vg0"
[root@node1 ~]# pvremove /dev/vdb1  缩减pv,直接删除掉pv
  Labels on physical volume "/dev/vdb1" successfully wiped.
5 、lvm快照
[root@node1 ~]# touch  /weixindata/westosfile{1..10}   建立文件
[root@node1 ~]# umount /weixindata/   卸载
[root@node1 ~]# ls /weixindata/   卸载后数据看不见
[root@node1 ~]# lvcreate -L 50M -s /dev/vg0/lv0 -n lv0-backup   -s后面跟需要快照的设备  -n后面跟自己命名的快昭名字
  Logical volume "lv0-backup" created.
[root@node1 ~]# mount /dev/vg0/lv0-backup /weixindata/  快照不需要格式化,可以直接挂载
[root@node1 ~]# ls /weixindata/
lost+found   westosfile10  westosfile3  westosfile5  westosfile7  westosfile9
westosfile1  westosfile2   westosfile4  westosfile6  westosfile8

如何删除快照
[root@node1 ~]# umount /weixindata 
[root@node1 ~]# lvremove /dev/vg0/lv0-backup  删除lvm快照
Do you really want to remove active logical volume vg0/lv0-backup? [y/n]: y
  Logical volume "lv0-backup" successfully removed
[root@node1 ~]# lvcreate -L 50M -n lv0-backup -s /dev/vg0/lv0   重新快照lvm
  Logical volume "lv0-backup" created.
[root@node1 ~]# mount /dev/vg0/lv0-backup /weixindata/  挂载
[root@node1 ~]# ls /weixindata/  数据又出现了
lost+found   westosfile10  westosfile3  westosfile5  westosfile7  westosfile9
westosfile1  westosfile2   westosfile4  westosfile6  westosfile8
6、lvm删除
root@node1 ~]# umount /weixindata  卸载
[root@node1 ~]# lvs
  LV         VG  Attr       LSize   Pool Origin Data%  meta%  Move Log Cpy%Sync Convert
  lv0        vg0 owi-a-s--- 500.00m                                                    
  lv0-backup vg0 swi-a-s---  50.00m      lv0    0.06                                   
[root@node1 ~]# lvremove /dev/vg0/lv0-backup  删除lvm快照
Do you really want to remove active logical volume vg0/lv0-backup? [y/n]: y
  Logical volume "lv0-backup" successfully removed
  [root@node1 ~]# lvremove /dev/vg0/lv0   删除lvm
Do you really want to remove active logical volume vg0/lv0? [y/n]: y
  Logical volume "lv0" successfully removed
[root@node1 ~]# vgremove vg0 删除vg0
  Volume group "vg0" successfully removed
[root@node1 ~]# pvremove /dev/vdb2  删除pv
  Labels on physical volume "/dev/vdb2" successfully wiped.

7、vdo(虚拟机数据优化器)设备的企业需求及建立

vdo 压缩数据
uds 优化重复数据

[root@node1 ~]# dd if=/dev/zero of=/dev/vdb bs=1M count=1 清空分区
vdo建立
[root@node1 ~]# vdo create --name westos_vdo1 --device  /dev/vdb  整块设备创建vdo
Creating VDO westos_vdo1
      Logical blocks defaulted to 523108 blocks.
      The VDO volume can address 2 GB in 1 data slab.
      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 westos_vdo1
Starting compression on VDO westos_vdo1
VDO instance 0 volume is ready at /dev/mapper/westos_vdo1  生成设备文件
[root@node1 ~]# mkfs.xfs -K /dev/mapper/westos_vdo1  格式化
meta-data=/dev/mapper/westos_vdo1 isize=512    agcount=4, agsize=130777 blks
         =                       sectsz=4096  attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=523108, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@node1 ~]# mount /dev/mapper/westos_vdo1 /weixindata/  挂载
[root@node1 ~]# vdo status --name westos_vdo1 | less 查看vdo信息
VDO status:
  Date: '2021-10-23 09:14:51+08:00'
  Node: node1
Kernel module:
  Loaded: true
  Name: kvdo
  Version information:
    kvdo version: 6.2.2.117
Configuration:
  File: /etc/vdoconf.yml
  Last modified: '2021-10-22 17:47:41'
VDOs:
  westos_vdo1:
    Acknowledgement threads: 1
    Activate: enabled
    Bio rotation interval: 64
    Bio submission threads: 4
    Block map cache size: 128M
    Block map period: 16380
。。。。。。。。。。。
其中有两个参数必须开启:
Deduplication:enabled  vdo检测并删除重复数据
compression:enabled vdo数据压缩功能开启

[root@node1 ~]# vdostats --human-readable  查看设备的存储状态
Device                    Size      Used Available Use% Space saving%
/dev/mapper/westos_vdo1      5.0G      3.0G      2.0G  60%           98%
[root@node1 ~]# watch -n -1 vdostats --human-readable  监控设备的存储状态
Every 0.1s: vdostats --human-readable                             node1: Sat Oct 23 09:32:26 2021
Device                    Size      Used Available Use% Space saving%
/dev/mapper/westos_vdo1   5.0G      3.5G	 1.5G  70%           50%
[root@foundation50 images]# cd /var/www/html/westos/images/   进入镜像
[root@foundation50 images]# scp install.img root@172.25.254.100:weixindata/  将install.img文件拷贝到虚拟机node1上
[root@foundation50 images]# scp install.img root@172.25.254.100:/weixindata/install1.img 
[root@node1 ~]# cd /weixindata/
[root@node1 weixindata]# ls
install1.img  install.img    拷贝了两份相同的数据
但是vdo数据优化功能开启后,他只占用一份数据
8、vdo设备的挂载

vdo设备开机自动挂载/etc/fstab是在vdo服务启动之后才能挂载的,但是系统会先访问/etc/fstab,再启动服务,这样重启系统,系统就会启动不起来,挂载时需要加x-systemd.requires=vdo.service参数,可用man vdo查看

[root@node1 weixindata]# vim /etc/fstab 
/dev/mapper/westos_vdo1                  /mnt                     xfs     defaults,x-systemd.requires=vdo.service  0 0
9、vdo设备删除
[root@node1 ~]# df
Filesystem              1K-blocks    Used Available Use% Mounted on
devtmpfs                   907604       0    907604   0% /dev
tmpfs                      935400       0    935400   0% /dev/shm
tmpfs                      935400    9368    926032   2% /run
tmpfs                      935400       0    935400   0% /sys/fs/cgroup
/dev/vda3                 7353344 4374696   2978648  60% /
/dev/vda1                  506528  218976    287552  44% /boot
/dev/mapper/westos_vdo1   2082192 1136092    946100  55% /mnt
tmpfs                      187080    1180    185900   1% /run/user/42
tmpfs                      187080       4    187076   1% /run/user/0
[root@node1 ~]# umount /mnt  卸载
[root@node1 ~]# vim /etc/fstab  删除挂载
/dev/mapper/westos_vdo1                  /mnt                     xfs     defaults,x-systemd.requires=vdo.service  0 0
[root@node1 ~]# vdo stop --name westos_vdo1  关掉vdo设备
Stopping VDO westos_vdo1
[root@node1 ~]# vdo remove --name westos_vdo1  删除vdo

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4695337.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-07
下一篇 2022-11-07

发表评论

登录后才能评论

评论列表(0条)

保存