RAID技术和逻辑卷管理
作者:互联网
RAID
RAID 0
条带卷,优点:多块硬盘同时读写数据,提高了读写的速度
缺点: 一块磁盘坏了,所有的都无法用了,因为数据是分散在多块磁盘里面的,出问题的概率太大,没有容错
RAID 1
镜像卷:优点:备份,每次写入数据都会备份一份,
缺点:磁盘的利用率只有百分之五十,写入数据要写双倍的,写的速率下降了
RAID 4
3块以上的硬盘,有一块盘将其中的两块盘做异或运算,得到一个校验位 ,其中一块盘坏了,通过异或可以恢复
存放校验位的那块盘是最容易坏的
RAID 5
至少3块盘,每块盘都有一个校验位和数据,避免了像RAID4那样将校验位全部写在一块磁盘上了
可用空间l利用率: (n-1)/n
RIAD 6
升级RIAD5,每块磁盘都有两个校验位和数据,最少4块才可以完成,
磁盘的利用率 n-2/n
RAID 1 0
2块做成RAID1 另外的 2块也做成RAID1 在把这两组盘做成RAID0
利用率:50%
系统失败的几率1/3
RAID 0 1
两块组合做成RAID 0 再把这个组合备份一份
磁盘的利用率:50%
系统失败的几率2/3
逻辑卷管理--LVM
实现空间的扩展,在线扩展,不影响用户的使用情况,RAID技术扩展要关机使用
缺点:逻辑上的空间,方式不透明
#PV 将磁盘标记成为PV,
将PV组合为卷组,
从卷组里面抽取一部分成为逻辑卷
逻辑卷的划分:
可以是分区,也可以是一块物理磁盘
#拿sdb1 sdb2 记为PV
[root08:21 AMcentos8 ~]#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 100G 0 part /
├─sda3 8:3 0 50G 0 part /data
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 4G 0 part [SWAP]
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 1G 0 part
└─sdb2 8:18 0 1G 0 part
sr0 11:0 1 7.7G 0 rom
[root08:25 AMcentos8 ~]#yum provides pvcreate
[root08:25 AMcentos8 ~]#yum install lvm2 -y
[root08:29 AMcentos8 ~]#rpm -ql lvm2
#查看安装该包生成了哪些命令
[root08:30 AMcentos8 ~]#rpm -ql lvm2 |grep pv
/usr/lib/systemd/system/lvm2-pvscan@.service
/usr/sbin/pvchange
/usr/sbin/pvck
/usr/sbin/pvcreate
/usr/sbin/pvdisplay
/usr/sbin/pvmove
/usr/sbin/pvremove
/usr/sbin/pvresize
/usr/sbin/pvs
/usr/sbin/pvscan
/usr/share/man/man8/pvchange.8.gz
/usr/share/man/man8/pvck.8.gz
/usr/share/man/man8/pvcreate.8.gz
/usr/share/man/man8/pvdisplay.8.gz
/usr/share/man/man8/pvmove.8.gz
/usr/share/man/man8/pvremove.8.gz
/usr/share/man/man8/pvresize.8.gz
/usr/share/man/man8/pvs.8.gz
/usr/share/man/man8/pvscan.8.gz
#相关命令
[root08:30 AMcentos8 ~]#pv
pvchange pvck pvcreate pvdisplay pvmove pvremove pvresize pvs pvscan
#标记物理卷
[root08:35 AMcentos8 /data]#pvcreate /dev/sdb{1,2}
Physical volume "/dev/sdb1" successfully created.
Physical volume "/dev/sdb2" successfully created.
#pvdisplay pvs 查看描述
#创建卷组,组名为mysql
[root08:37 AMcentos8 /data]#vgcreate mysql /dev/sdb1 /dev/sdb2
Volume group "mysql" successfully created
[root08:37 AMcentos8 /data]#vgs 查看
VG #PV #LV #SN Attr VSize VFree
mysql 2 0 0 wz--n- 1.99g 1.99g
[root08:38 AMcentos8 /data]#vgdisplay 查看卷组
#创建逻辑卷
[root08:40 AMcentos8 /data]#lvcreate -n lv_data -L 600M mysql
Logical volume "lv_data" created.
-L表示指明具体的大小 -l表示指明的PE个数 , 例如:-l 100 表示指明PE的个数为100个
[root08:45 AMcentos8 /data]#lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv_data mysql -wi-a----- 600.00m
[root08:46 AMcentos8 /data]#ll /dev/mysql/lv_data #在dev目录下的mysql卷组下面的lv_data逻辑卷
#生成的两条软链接的名字都是逻辑卷的名字
lrwxrwxrwx 1 root root 7 May 2 08:43 /dev/mysql/lv_data -> ../dm-0 #两条软链接
[root08:47 AMcentos8 /data]#ll /dev/mapper/mysql-lv_data
lrwxrwxrwx 1 root root 7 May 2 08:43 /dev/mapper/mysql-lv_data -> ../dm-0
#格式化
[root08:56 AMcentos8 /data]#mkfs.ext4 /dev/mysql/lv_data
[root08:59 AMcentos8 /data]#blkid |grep /dev/mapper/mysql-lv_data
/dev/mapper/mysql-lv_data: UUID="7aacb7f6-6cdf-4aa7-ad57-f8dfa1a1295e" TYPE="ext4"
#挂载使用
[root09:01 AMcentos8 /data]#vim /etc/fstab
[root09:04 AMcentos8 /data]#mount -a
[root09:05 AMcentos8 /data]#cp /etc/fstab /data/mysql/
[root09:06 AMcentos8 /data]#ll /data/mysql/
total 20
-rw-r--r-- 1 root root 804 May 2 09:06 fstab
drwx------ 2 root root 16384 May 2 08:57 lost+found
pvdisplay
[root08:49 AMcentos8 /data]#pvdisplay
--- Physical volume ---
PV Name /dev/sdb1
VG Name mysql
PV Size 1.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 255
Free PE 105
Allocated PE 150 被分配了150个PE
PV UUID 98SCfB-ZYau-hgVd-EZEi-rq1d-eXTe-YjE6Jc
--- Physical volume ---
PV Name /dev/sdb2
VG Name mysql
PV Size 1.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 255
Free PE 255 一个PE也没有被分配
Allocated PE 0
PV UUID QUO9AV-7PuR-vzw3-RfrU-t33E-AyEz-t7XadQ
lvdisplay
[root08:51 AMcentos8 /data]#lvdisplay
--- Logical volume ---
LV Path /dev/mysql/lv_data
LV Name lv_data
VG Name mysql
LV UUID qRF7Ic-Xcol-YsVs-QIXc-pH26-uzL7-BWm3UN
LV Write Access read/write
LV Creation host, time centos8.magedu.com, 2021-05-02 08:43:30 +0800
LV Status available
# open 0
LV Size 600.00 MiB
Current LE 150 #相当于PE
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
逻辑卷的扩展
[root09:08 AMcentos8 /data]#lvextend -L +100M /dev/mysql/lv_data 此方法直接指明大小
[root09:11 AMcentos8 /data]#lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv_data mysql -wi-ao---- 700.00m #被加了100M
或者:此方法是以PE为单位计算的
[root09:11 AMcentos8 /data]#lvextend -l +100%free /dev/mysql/lv_data
全部给了逻辑卷,容量变大了
***但是看到的是文件系统空间的大小,要同步
[root09:14 AMcentos8 /data]#df -H
Filesystem Size Used Avail Use% Mounted on
devtmpfs 482M 0 482M 0% /dev
tmpfs 500M 0 500M 0% /dev/shm
tmpfs 500M 14M 486M 3% /run
tmpfs 500M 0 500M 0% /sys/fs/cgroup
/dev/sda2 108G 14G 94G 13% /
/dev/sda3 54G 1.5G 53G 3% /data
/dev/sda1 1.1G 124M 830M 13% /boot
tmpfs 100M 0 100M 0% /run/user/0
/dev/mapper/mysql-lv_data 603M 938k 558M 1% /data/mysql
resize2fs 同步ext系列文件系统
[root09:15 AMcentos8 /data]#resize2fs /dev/mysql/lv_data
resize2fs 1.45.6 (20-Mar-2020)
Filesystem at /dev/mysql/lv_data is mounted on /data/mysql; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mysql/lv_data is now 522240 (4k) blocks long.
[root09:18 AMcentos8 /data]#df -H
Filesystem Size Used Avail Use% Mounted on
devtmpfs 482M 0 482M 0% /dev
tmpfs 500M 0 500M 0% /dev/shm
tmpfs 500M 14M 486M 3% /run
tmpfs 500M 0 500M 0% /sys/fs/cgroup
/dev/sda2 108G 14G 94G 13% /
/dev/sda3 54G 1.5G 53G 3% /data
/dev/sda1 1.1G 124M 830M 13% /boot
tmpfs 100M 0 100M 0% /run/user/0
/dev/mapper/mysql-lv_data 2.1G 1.9M 2.0G 1% /data/mysql
xfs_growfs 同步xfs 系列的文件系统
xfg_growfs mountpoint
这一点和resize2fs 不一样
扩卷组进一步扩展逻辑卷
#标记物理机
[root09:25 AMcentos8 /data]#pvcreate /dev/sdb3
Physical volume "/dev/sdb3" successfully created.
#扩展mysql这个卷组
[root09:25 AMcentos8 /data]#vgextend mysql /dev/sdb3
Volume group "mysql" successfully extended
#查看卷组被扩大
[root09:27 AMcentos8 /data]#vgdisplay
--- Volume group ---
VG Name mysql
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 3
Act PV 3
VG Size <11.99 GiB
PE Size 4.00 MiB
Total PE 3069
Alloc PE / Size 510 / 1.99 GiB
Free PE / Size 2559 / <10.00 GiB #有空闲空间了,被扩大了
VG UUID Sy9Z0L-VFTG-ZghN-ngaK-0Cjl-6Pe1-geZUbD
#扩展逻辑卷组
[root09:29 AMcentos8 /data]#lvcreate -r -L +2G /dev/mysql/lv_data
加 -r 连带文件系统一起扩展
#加 -r 以后就无需要用resize2fs 这个命令操作一次了
[root09:34 AMcentos8 /data]#df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 460M 0 460M 0% /dev
tmpfs 477M 0 477M 0% /dev/shm
tmpfs 477M 13M 464M 3% /run
tmpfs 477M 0 477M 0% /sys/fs/cgroup
/dev/sda2 100G 13G 87G 13% /
/dev/sda3 50G 1.4G 49G 3% /data
/dev/sda1 976M 118M 792M 13% /boot
tmpfs 96M 0 96M 0% /run/user/0
/dev/mapper/mysql-lv_data 4.0G 2.4M 3.8G 1% /data/mysql
逻辑卷的缩容
[root10:57 AMcentos8 ~]#pvcreate /dev/sdb{1,2}
Physical volume "/dev/sdb1" successfully created.
Physical volume "/dev/sdb2" successfully created.
[root10:58 AMcentos8 ~]#pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 lvm2 --- 5.00g 5.00g
/dev/sdb2 lvm2 --- 5.00g 5.00g
[root10:58 AMcentos8 ~]#vgcreate vg0 /dev/sdb{1,2}
Volume group "vg0" successfully created
#所有的空间都做逻辑卷
[root10:58 AMcentos8 ~]#lvcreate -n mysql -l 100%vg vg0
Logical volume "mysql" created.
[root10:59 AMcentos8 ~]#lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
mysql vg0 -wi-a----- 9.99g
[root10:59 AMcentos8 ~]#vgdisplay
--- Volume group ---
VG Name vg0
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 9.99 GiB
PE Size 4.00 MiB
Total PE 2558
Alloc PE / Size 2558 / 9.99 GiB
Free PE / Size 0 / 0
VG UUID 24EUtO-waB2-hKy8-qEHW-Qs1D-PZ2b-sPkrhb
#格式化
[root11:00 AMcentos8 ~]#mkfs.ext4 /dev/vg0/mysql
#挂载
[root11:03 AMcentos8 ~]#mount /dev/vg0/mysql /lv
#缩减逻辑卷有风险,建议先备份
1 先取消挂载
[root11:09 AMcentos8 ~]#umount /lv
2.先检查文件系统的完整,不检查文件系统后面的步骤无法实现
[root11:12 AMcentos8 ~]#fsck -f /dev/vg0/mysql
fsck from util-linux 2.32.1
e2fsck 1.45.6 (20-Mar-2020)
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/mapper/vg0-mysql: 13/655360 files (0.0% non-contiguous), 66755/2619392 blocks
3 缩减文件系统
[root11:13 AMcentos8 ~]#resize2fs /dev/vg0/mysql 1G
resize2fs 1.45.6 (20-Mar-2020)
Resizing the filesystem on /dev/vg0/mysql to 262144 (4k) blocks.
The filesystem on /dev/vg0/mysql is now 262144 (4k) blocks long.
4 缩减逻辑卷
[root11:15 AMcentos8 ~]#lvreduce -L 1G /dev/vg0/mysql
WARNING: Reducing active logical volume to 1.00 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vg0/mysql? [y/n]: y
Size of logical volume vg0/mysql changed from 9.99 GiB (2558 extents) to 1.00 GiB (256 extents).
Logical volume vg0/mysql successfully resized.
5 挂载查看容量变小
[root11:16 AMcentos8 ~]#mount /dev/vg0/mysql /lv
[root11:18 AMcentos8 ~]#df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 460M 0 460M 0% /dev
tmpfs 477M 0 477M 0% /dev/shm
tmpfs 477M 13M 464M 3% /run
tmpfs 477M 0 477M 0% /sys/fs/cgroup
/dev/sda2 100G 13G 87G 13% /
/dev/sda3 50G 1.4G 49G 3% /data
/dev/sda1 976M 118M 792M 13% /boot
tmpfs 96M 0 96M 0% /run/user/0
/dev/mapper/vg0-mysql 944M 21M 857M 3% /lv
#/dev/vg0/mysql /dev/mapper/vg0-mysql 都是dm-0的软链接
[root11:19 AMcentos8 ~]#ll /dev/vg0/mysql
lrwxrwxrwx 1 root root 7 May 2 11:16 /dev/vg0/mysql -> ../dm-0
[root11:19 AMcentos8 ~]#ll /dev/mapper/vg0-mysql
lrwxrwxrwx 1 root root 7 May 2 11:16 /dev/mapper/vg0-mysql -> ../dm-0
逻辑卷的快照
快照性能下降
空间限制,
测试用一下
#创建一个逻辑卷且格式化
[root11:45 AMcentos8 ~]#lvcreate -n binlog -L 500 vg0
[root11:45 AMcentos8 ~]#mkfs.xfs /dev/vg0/binlog
#自动挂载
[root11:49 AMcentos8 ~]#mount -a
# 拷贝数据到挂载目录
[root11:50 AMcentos8 /data/binlog]#cp /etc/fstab /etc/issue /etc/os-release /data/binlog/
#我现在的卷组里有两个逻辑卷
[root11:50 AMcentos8 /data/binlog]#lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
binlog vg0 -wi-ao---- 500.00m
mysql vg0 -wi-ao---- 1.00g
[root11:51 AMcentos8 /data/binlog]#vgdisplay
--- Volume group ---
VG Name vg0
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 9.99 GiB
PE Size 4.00 MiB
Total PE 2558
Alloc PE / Size 381 / <1.49 GiB #已经使用的PE个数是381个
Free PE / Size 2177 / 8.50 GiB #空闲的PE还有2177个
VG UUID 24EUtO-waB2-hKy8-qEHW-Qs1D-PZ2b-sPkrhb
#创建快照要确保vg的空间还够
创建快照
[root11:51 AMcentos8 /data/binlog]#lvcreate -n binlog-snapshot -s -L 100M /dev/vg0/binlog
Logical volume "binlog-snapshot" created.
-n binlog-snapshot :创建一个叫 binlog-snapshot 的快照
-s 指明是快照,不加s 就误认为是逻辑卷
-L 100M 指明快照的大小
[root12:03 PMcentos8 /data/binlog]#lvdisplay
--- Logical volume ---
LV Path /dev/vg0/mysql
LV Name mysql
VG Name vg0
LV UUID ALzsqN-W5e1-dVx6-EI8a-VG1t-cv99-rruQpo
LV Write Access read/write
LV Creation host, time centos8.magedu.com, 2021-05-02 10:59:47 +0800
LV Status available
# open 1
LV Size 1.00 GiB
Current LE 256
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
--- Logical volume ---
LV Path /dev/vg0/binlog
LV Name binlog
VG Name vg0
LV UUID 5LwdHD-7Hq1-5Pvh-WCCj-7ET6-qQ5D-2CCSKj
LV Write Access read/write
LV Creation host, time centos8.magedu.com, 2021-05-02 11:45:43 +0800
LV snapshot status source of
binlog-snapshot [active] #说明了什么是我的快照
LV Status available
# open 1
LV Size 500.00 MiB
Current LE 125
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/vg0/binlog-snapshot 3快照文件
LV Name binlog-snapshot
VG Name vg0
LV UUID uj3TxC-XQdi-KM1t-sakh-Y06j-JEmM-QfDf1X
LV Write Access read/write
LV Creation host, time centos8.magedu.com, 2021-05-02 12:03:57 +0800
LV snapshot status active destination for binlog #对binlog的快照
LV Status available
# open 0
LV Size 500.00 MiB
Current LE 125
COW-table size 100.00 MiB
COW-table LE 25
Allocated to snapshot 0.02%
Snapshot chunk size 4.00 KiB
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:4
[root12:13 PMcentos8 /data/binlog]#blkid
/dev/mapper/vg0-mysql: UUID="17eee59c-438b-415a-8fd1-9426e95469de" TYPE="ext4"
/dev/mapper/vg0-binlog: UUID="e016cbb5-3e44-414f-b150-9e39f493f036" TYPE="xfs"
/dev/sda1: UUID="37e18d75-7231-4d84-8536-18e1b3a891f6" TYPE="ext4" PARTUUID="80c09a6f-01"
/dev/sda2: UUID="55d00b68-d8ef-4c35-aa11-b8c11b91e867" TYPE="xfs" PARTUUID="80c09a6f-02"
/dev/sda3: UUID="fdcd162f-2ea2-4088-9e86-6a911336304a" TYPE="xfs" PARTUUID="80c09a6f-03"
/dev/sda5: UUID="d81ef34a-c3dd-4483-b830-4cf516cbec7c" TYPE="swap" PARTUUID="80c09a6f-05"
/dev/sdb1: UUID="fwJ2ct-4fPI-3MyZ-BKHy-DB6k-d39v-hiGrto" TYPE="LVM2_member" PARTUUID="a3103b56-01"
/dev/sdb2: UUID="xtn9y9-si6o-yWdR-VSEg-zLWc-KPjO-gzbFtB" TYPE="LVM2_member" PARTUUID="a3103b56-02"
/dev/mapper/vg0-binlog--snapshot: UUID="e016cbb5-3e44-414f-b150-9e39f493f036" TYPE="xfs"
/dev/mapper/vg0-binlog 和 /dev/mapper/vg0-binlog--snapshot 的UUID是一样的,xfs文件系统无法通过uuid来挂载
[root12:16 PMcentos8 /data/binlog]#mount /dev/vg0/binlog-snapshot /mnt/snap/
mount: /mnt/snap: wrong fs type, bad option, bad superblock on /dev/mapper/vg0-binlog--snapshot, missing codepage or helper program, or other error.
#正确的挂载方式:
[root12:17 PMcentos8 /data/binlog]#mount -o nouuid,ro /dev/vg0/binlog-snapshot /mnt/snap/
[root12:20 PMcentos8 /data/binlog]#ls /mnt/snap/ 看到数据证明快照能备份
fstab issue os-release
现在我修改逻辑卷里面的东西,但是快照里面的是不会方式变化的
[root12:25 PMcentos8 /data/binlog]#ll /data/binlog/
total 12
-rw-r--r-- 1 root root 899 May 2 11:50 fstab
-rw-r--r-- 1 root root 23 May 2 11:50 issue
-rw-r--r-- 1 root root 420 May 2 11:50 os-release
[root12:25 PMcentos8 /data/binlog]#\rm /data/binlog/fstab
[root12:26 PMcentos8 /data/binlog]#ll /mnt/snap/
total 12
-rw-r--r-- 1 root root 899 May 2 11:50 fstab #快照里面的东西不会丢失
-rw-r--r-- 1 root root 23 May 2 11:50 issue
-rw-r--r-- 1 root root 420 May 2 11:50 os-release
#现在文件里面增加了,但是快照里面的文件是不会改变的
[root12:27 PMcentos8 /data/binlog]#touch f.txt
[root12:28 PMcentos8 /data/binlog]#ll
total 8
-rw-r--r-- 1 root root 0 May 2 12:28 f.txt
-rw-r--r-- 1 root root 23 May 2 11:50 issue
-rw-r--r-- 1 root root 420 May 2 11:50 os-release
[root12:28 PMcentos8 /data/binlog]#ll /mnt/snap/ #发现快照里面永远都是最初的状态
total 12
-rw-r--r-- 1 root root 899 May 2 11:50 fstab
-rw-r--r-- 1 root root 23 May 2 11:50 issue
-rw-r--r-- 1 root root 420 May 2 11:50 os-release
恢复快照
#取消逻辑卷和快照的挂载
[root12:28 PMcentos8 /data/binlog]#umount /data/binlog/ /mnt/snap/
#恢复快照
[root12:31 PMcentos8 ~]#lvconvert --merge /dev/vg0/binlog-snapshot
Merging of volume vg0/binlog-snapshot started.
vg0/binlog: Merged: 100.00%
#完成任务,快照自动被删除
[root12:34 PMcentos8 ~]#lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
binlog vg0 -wi-a----- 500.00m
mysql vg0 -wi-ao---- 1.00g
#查看文件被恢复
root12:38 PMcentos8 ~]#mount -a
[root12:38 PMcentos8 ~]#ll /data/binlog/
total 12
-rw-r--r-- 1 root root 899 May 2 11:50 fstab
-rw-r--r-- 1 root root 23 May 2 11:50 issue
-rw-r--r-- 1 root root 420 May 2 11:50 os-release
快照的优点:
快 ,方便测试
pvmove移动PE
[root12:53 PMcentos8 ~]#pvdisplay
--- Physical volume ---
PV Name /dev/sdb1
VG Name vg0
PV Size 5.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 1279
Free PE 898
Allocated PE 381
PV UUID fwJ2ct-4fPI-3MyZ-BKHy-DB6k-d39v-hiGrto
--- Physical volume ---
PV Name /dev/sdb2
VG Name vg0
PV Size 5.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 1279
Free PE 1279
Allocated PE 0
PV UUID xtn9y9-si6o-yWdR-VSEg-zLWc-KPjO-gzbFtB
[root12:53 PMcentos8 ~]#lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
binlog vg0 -wi-ao---- 500.00m
mysql vg0 -wi-ao---- 1.00g
#移动sdb1磁盘上的PE
[root12:56 PMcentos8 ~]#pvmove /dev/sdb1
/dev/sdb1: Moved: 8.66%
/dev/sdb1: Moved: 67.19%
/dev/sdb1: Moved: 100.00%
[root12:59 PMcentos8 ~]#pvdisplay
--- Physical volume ---
PV Name /dev/sdb1 #该分区上的数据全部挪动到 /dev/sdb2 上了
VG Name vg0
PV Size 5.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 1279
Free PE 1279
Allocated PE 0
PV UUID fwJ2ct-4fPI-3MyZ-BKHy-DB6k-d39v-hiGrto
--- Physical volume ---
PV Name /dev/sdb2
VG Name vg0
PV Size 5.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 1279
Free PE 898
Allocated PE 381
PV UUID xtn9y9-si6o-yWdR-VSEg-zLWc-KPjO-gzbFtB
#从卷组里删除sdb1这个成员
[root12:59 PMcentos8 ~]#vgreduce vg0 /dev/sdb1
Removed "/dev/sdb1" from volume group "vg0"
#从pv里面删除 sdb1 这个成员,让他不是物理卷
[root01:04 PMcentos8 ~]#pvremove /dev/sdb1
Labels on physical volume "/dev/sdb1" successfully wiped.
#pvs彻底看不到他了
[root01:05 PMcentos8 ~]#pvs
PV VG Fmt Attr PSize PFree
/dev/sdb2 vg0 lvm2 a-- <5.00g <3.51g
#fdisk 删除分区
[root01:17 PMcentos8 ~]#fdisk /dev/sdb
[root01:17 PMcentos8 ~]#lsblk # sdb2里就不会有内容了
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 100G 0 part /
├─sda3 8:3 0 50G 0 part /data
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 4G 0 part [SWAP]
sdb 8:16 0 20G 0 disk
└─sdb2 8:18 0 5G 0 part
├─vg0-mysql 253:0 0 1G 0 lvm /data/mysql
└─vg0-binlog 253:1 0 500M 0 lvm /data/binlog
sr0 11:0 1 1024M 0 rom
删除逻辑卷
1.取消所有逻辑卷的挂载,且删除/etc/fstab文件里面的挂载信息
2.删除所有的逻辑卷
[root01:26 PMcentos8 ~]#lvremove /dev/vg0/*
Do you really want to remove active logical volume vg0/mysql? [y/n]: y
3.删除卷组
[root01:27 PMcentos8 ~]#vgremove vg0
4.删除物理卷
[root01:28 PMcentos8 ~]#pvremove /dev/sdb2
Labels on physical volume "/dev/sdb2" successfully wiped.
标签:binlog,逻辑,RAID,vg0,技术,dev,AMcentos8,mysql,data 来源: https://blog.51cto.com/u_14847540/2750126