Linux高级存储管理

1.逻辑卷

pv ##物理卷 被处理过的物理分区

pe ##物理扩展 设定存储最小单元

vg ##物理卷组 捆绑pv到一个组中

lv ##逻辑卷 分配最终的使用设备

watch -n 1 "pvs;echo ====;vgs;echo =====;lvs;echo =====;df -h /pub

监控命令

lvm设备建立:

使用一个新的硬盘建立

[root@westos_student50 Desktop]# fdisk /dev/sdb  建立两个分区

 

[root@westos_student50 Desktop]# udevadm settle   同步

[root@westos_student50 Desktop]# pvcreate /dev/sdb1  创建pv

  Physical volume "/dev/sdb1" successfully created.

[root@westos_student50 Desktop]# vgcreate -s 4M westosvg /dev/sdb1创建vg,-s设定pe大小位4M

  Volume group "westosvg" successfully created

[root@westos_student50 Desktop]# lvcreate -L 50M -n westoslv westosvg创建lvm -L指定大小 -n指定名称

  Rounding up size to full physical extent 52.00 MiB

  Logical volume "westoslv" created.

[root@westos_student50 Desktop]# mkfs.xfs /dev/westosvg/westoslv   格式化

[root@westos_student50 Desktop]# mkdir /pub

[root@westos_student50 Desktop]# mount /dev/westosvg/westoslv /pub   挂载

lvm拉伸:

[root@westos_student50 Desktop]# lvextend -L 80M /dev/westosvg/westoslv  拉伸设备到80M

[root@westos_student50 Desktop]# xfs_growfs /dev/westosvg/westoslv   拉伸文件系统

[root@westos_student50 Desktop]# lvextend -L 500M /dev/westosvg/westoslv  拉升到500M

[root@westos_student50 Desktop]# xfs_growfs /dev/westosvg/westoslv  拉伸文件系统

lvm设备拉伸和缩减

[root@westos_student50 Desktop]# lvextend -L 800M /dev/westosvg/westoslv  拉伸到800M

  Size of logical volume westosvg/westoslv changed from 500.00 MiB (125 extents) to 800.00 MiB (200 extents).

  Logical volume westosvg/westoslv successfully resized.

[root@westos_student50 Desktop]# xfs_growfs /dev/westosvg/westoslv  拉升文件系统

当所拉伸大小超过容量大小

[root@westos_student50 Desktop]# pvcreate /dev/sdb2    创建pv

  Physical volume "/dev/sdb2" successfully created.

[root@westos_student50 Desktop]# vgextend westosvg /dev/sdb2    vg增加一个sdb2

  Volume group "westosvg" successfully extended

[root@westos_student50 Desktop]# lvextend -L 1500M /dev/westosvg/westoslv  拉伸到1.5G

  Size of logical volume westosvg/westoslv changed from 800.00 MiB (200 extents) to 1.46 GiB (375 extents).

  Logical volume westosvg/westoslv successfully resized.

[root@westos_student50 Desktop]# xfs_growfs /dev/westosvg/westoslv  拉伸文件系统

ext4拉伸:

[root@westos_student50 Desktop]# umount /pub  卸载

[root@westos_student50 Desktop]# mkfs.ext4 /dev/westosvg/westoslv  ext4格式化

[root@westos_student50 Desktop]# mount /dev/westosvg/westoslv /pub   挂载

[root@westos_student50 Desktop]# lvextend -L 1800M /dev/westosvg/westoslv  拉伸搭配1.8G

  Size of logical volume westosvg/westoslv changed from 1.46 GiB (375 extents) to <1.76 GiB (450 extents).

[root@westos_student50 Desktop]# resize2fs /dev/westosvg/westoslv  拉伸文件系统

缩减:

[root@westos_student50 Desktop]# umount /pub  卸载

[root@westos_student50 Desktop]# e2fsck -f /dev/westosvg/westoslv  扫描

[root@westos_student50 Desktop]# resize2fs /dev/westosvg/westoslv 500M  缩减到500M

[root@westos_student50 Desktop]# lvreduce -L 500M /dev/westosvg/westoslv缩减

[root@westos_student50 Desktop]# mount /dev/westosvg/westoslv /pub 挂载

[root@westos_student50 Desktop]# pvmove /dev/sdb1 /dev/sdb2 把sdb1的数据移到sdb2

  /dev/sdb1: Moved: 31.88%

  /dev/sdb1: Moved: 90.58%

  /dev/sdb1: Moved: 100.00%

[root@westos_student50 Desktop]# vgreduce westosvg /dev/sdb1取出sdb1

  Removed "/dev/sdb1" from volume group "westosvg"

[root@westos_student50 Desktop]# pvremove /dev/sdb1 删掉sdb1

  Labels on physical volume "/dev/sdb1" successfully wiped

lvm快照:

[root@westos_student50 Desktop]# touch /pub/westosfile{1..5}

[root@westos_student50 Desktop]# ls /pub

[root@westos_student50 Desktop]# umount /pub   卸载

[root@westos_student50 Desktop]# lvcreate -L 50M -n westoslv-backup -s /dev/westosvg/westoslv进行快照

  Rounding up size to full physical extent 52.00 MiB

  Logical Volume "westoslv-backup" already exists in volume group "westosvg"

[root@westos_student50 Desktop]# mount /dev/westosvg/westoslv-backup /pub 挂载

[root@westos_student50 Desktop]# ls /pub

[root@westos_student50 Desktop]# rm -rf /pub/*

[root@westos_student50 Desktop]# umount /pub

[root@westos_student50 Desktop]# lvremove /dev/westosvg/westoslv-backup删掉

Do you really want to remove active logical volume westosvg/westoslv-backup? [y/n]: y

  Logical volume "westoslv-backup" successfully removed

[root@westos_student50 Desktop]# lvcreate -L 50M -n westoslv-backup -s /dev/westosvg/westoslv  快照

  Rounding up size to full physical extent 52.00 MiB

  Logical volume "westoslv-backup" created.

[root@westos_student50 Desktop]# mount /dev/westosvg/westoslv-backup /pub 挂载

[root@westos_student50 Desktop]# ls /pub

lvm删除:

[root@westos_student50 Desktop]# umount /pub   卸载

[root@westos_student50 Desktop]# df

Filesystem     1K-blocks     Used Available Use% Mounted on

devtmpfs          377424        0    377424   0% /dev

tmpfs             405260        0    405260   0% /dev/shm

tmpfs             405260    11904    393356   3% /run

tmpfs             405260        0    405260   0% /sys/fs/cgroup

/dev/sda3       79127812 18851992  60275820  24% /

/dev/sda1         518816   220672    298144  43% /boot

tmpfs              81052       16     81036   1% /run/user/42

tmpfs              81052       32     81020   1% /run/user/0

[root@westos_student50 Desktop]# lvremove /dev/westosvg/westoslv-backup  删除快照

Do you really want to remove active logical volume westosvg/westoslv-backup? [y/n]: y

  Logical volume "westoslv-backup" successfully removed

[root@westos_student50 Desktop]# lvremove /dev/westosvg/westoslv   删除设备

Do you really want to remove active logical volume westosvg/westoslv? [y/n]: y

  Logical volume "westoslv" successfully removed

[root@westos_student50 Desktop]# vgremove westosvg   删除

  Volume group "westosvg" successfully removed

[root@westos_student50 Desktop]# pvremove /dev/sdb2    删除

  Labels on physical volume "/dev/sdb2" successfully wiped.

 

[root@westos_student50 Desktop]# fdisk /dev/sdb

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): d

Partition number (1,2, default 2): 1

Partition 1 has been deleted.

Command (m for help): d

Selected partition 2

Partition 2 has been deleted.

Command (m for help): 2

2: unknown command

Command (m for help): p

Disk /dev/sdb: 10 GiB, 10737418240 bytes, 20971520 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: 0x00577655

Command (m for help): wq

The partition table has been altered.

Calling ioctl() to re-read partition table.

Syncing disks.

[root@westos_student50 Desktop]# udevadm settle同步

2.vdo

建立:

[root@westos_student50 Desktop]# vdo create --name=westos-vdo --device /dev/nvme0n1  创建vdo

[root@westos_student50 Desktop]# vdo status --name westos-vdo    查看vdo

[root@westos_student50 Desktop]# vdo status --name westos-vdo | less  查看一下两个是否开启(/+查询名字)

Deduplication: enabled ##vdo检测并删除重复数据的功能时开启的

Compression: enabled ##vdo数据压缩功能开启

[root@westos_student50 Desktop]# mkfs.xfs -K /dev/mapper/westos-vdo格式化

[root@westos_student50 Desktop]# mount /dev/mapper/westos-vdo /pub  挂载  

[root@westos_student50 Desktop]# vdostats --human-readable   查看vdo状况

Device                    Size      Used Available Use% Space saving%

/dev/mapper/westos-vdo      5.0G      3.0G      2.0G  60%           98%

[root@westos_student50 Desktop]# umount /pub

[root@westos_student50 Desktop]# vdo stop --name westos-vdo  停掉vdo

Stopping VDO westos-vdo

[root@westos_student50 Desktop]# vdostats --human-readable  查看

[root@westos_student50 Desktop]# vdo start --name westos-vdo   启动

Starting VDO westos-vdo

Starting compression on VDO westos-vdo

VDO instance 1 volume is ready at /dev/mapper/westos-vdo

[root@westos_student50 Desktop]# systemctl status vdo.service

[root@westos_student50 Desktop]# man vdo

[root@westos_student50 Desktop]# vim /etc/fstab  开机时自动启动

[root@westos_student50 Desktop]# systemctl status vdo.service

 

[root@westos_student50 Desktop]# mount -a   自动挂栽

[root@westos_student50 Desktop]# umount /pub

[root@westos_student50 Desktop]# vdo stop --name westos-vdo

Stopping VDO westos-vdo

[root@westos_student50 Desktop]# vdo remove --name westos-vdo  删除

Removing VDO westos-vdo

Stopping VDO westos-vdo

vdo: WARNING - VDO service westos-vdo already stopped

[root@westos_student50 Desktop]# vdo start --name westos-vdo  删掉后无法启动

vdo: ERROR - VDO volume westos-vdo not found

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

黑 哲

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值