2019独角兽企业重金招聘Python工程师标准>>>
准备磁盘分区
fdisk /dev/sdb
n 创建三个新分区,分别1G
t 改变分区类型为8e准备物理卷
pvcreate /dev/sdb1
pvcreate /dev/sdb2
pvcreate /dev/sdb3pvdisplay/pvs 列出当前的物理卷
pvremove /dev/sdb3 删除物理卷准备卷组
vgcreate vg1 /dev/sdb1 /dev/sdb2 /dev/sdb3
vgdisplay /vgs列出卷组
vgremove vg1 删除物理卷创建逻辑卷
lvcreate -L 200M -n lv1 vg1
lvdisplay 列出逻辑卷
格式化mkfs.xfs /dev/vg1/lv1,再挂载
lvremove /dev/vg1/lv1 删除逻辑卷扩容逻辑卷
lvresize -L 300M /dev/vg1/lv1 重新设置卷大小
e2fsck -f /dev/vg1/lv1 检查磁盘错误 (ext4执行)
resize2fs /dev/vg1/lv1 更新逻辑卷信息(ext4执行)
xfs_growfs /dev/vg1/lv1 xfs文件系统需要执行缩减逻辑卷(xfs不支持 )
先umount
e2fsck -f /dev/vg1/lv1 检查磁盘错误(ext)
resize2fs /dev/vg1/lv1 100M 更新逻辑卷信息(ext)
lvresize -L 100M /dev/vg1/lv1 重新设置卷大小扩展卷组
fdisk /dev/sdb 新增/dev/sdb5(逻辑分区8e) 2G
pvcreate /dev/sdb5
vgextend vg1 /dev/sdb5
lvresize -L 100M /dev/vg1/lv1 重新设置卷大小
Lvm
1.创建物理分区;
2.物理分区设置成物理卷;
3.物理卷设置成卷组;
4.卷组划分成逻辑卷,
5.然后再格式化,挂载
先创建3个分区,在分区的时候按创建分区,按t设置分区类型8e 为lvm;
[root@linux-128 ~]# fdisk /dev/sdb
命令(输入 m 获取帮助):n
Partition type:p primary (0 primary, 0 extended, 4 free)e extended
Select (default p): p
分区号 (1-4,默认 1):
起始 扇区 (2048-41943039,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-41943039,默认为 41943039):+1G
分区 1 已设置为 Linux 类型,大小设为 1 GiB命令(输入 m 获取帮助):t
已选择分区 1
Hex 代码(输入 L 列出所有代码):8e
已将分区“Linux”的类型更改为“Linux LVM”命令(输入 m 获取帮助):p磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xbc339889设备 Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 8e Linux LVM
/dev/sdb2 2099200 4196351 1048576 8e Linux LVM
/dev/sdb3 4196352 6293503 1048576 8e Linux LVM
1.创建物理卷
需要安装命令:pvcreate
小知识:如果只知道命令,不知道这个命令是那个包安装的,可以使用命令:yum provides /*/[命令] 来查找命令是那个包安装的。
[root@linux-128 ~]# yum provides /*/pvcreate
已加载插件:fastestmirror
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/2): extras/7/x86_64/primary_db | 129 kB 00:00:00
(2/2): updates/7/x86_64/primary_db | 3.6 MB 00:00:02
Loading mirror speeds from cached hostfile* base: mirrors.aliyun.com* extras: mirrors.aliyun.com* updates: mirrors.cn99.com
extras/7/x86_64/filelists_db | 486 kB 00:00:00
updates/7/x86_64/filelists_db | 2.1 MB 00:00:01
1:bash-completion-2.1-6.el7.noarch : Programmable completion for Bash
源 :base
匹配来源:
文件名 :/usr/share/bash-completion/completions/pvcreate
7:lvm2-2.02.171-8.el7.x86_64 : Userland logical volume management tools
源 :base
匹配来源:
文件名 :/usr/sbin/pvcreate
lvm2-2.02.171-8.el7.x86_64 这个就是包名。
[root@linux-128 ~]# yum install -y lvm2
- 安装完使用命令:pvcreate 创建物理卷
[root@linux-128 ~]# pvcreate /dev/sdb1
WARNING: ext4 signature detected on /dev/sdb1 at offset 1080. Wipe it? [y/n]: yWiping ext4 signature on /dev/sdb1.Physical volume "/dev/sdb1" successfully created.
[root@linux-128 ~]# pvcreate /dev/sdb2Physical volume "/dev/sdb2" successfully created.
[root@linux-128 ~]# pvcreate /dev/sdb3Physical volume "/dev/sdb3" successfully created.
- 物理卷创建完后,使用命令:pvdisplay或者pvs来查看信息:
[root@linux-128 ~]# pvdisplay"/dev/sdb2" is a new physical volume of "1.00 GiB"--- NEW Physical volume ---PV Name /dev/sdb2VG NamePV Size 1.00 GiBAllocatable NOPE Size 0Total PE 0Free PE 0Allocated PE 0PV UUID GqWi3Q-4XT9-1RyO-JE3C-Zber-oPw5-4zGyyp"/dev/sdb1" is a new physical volume of "1.00 GiB"--- NEW Physical volume ---PV Name /dev/sdb1VG NamePV Size 1.00 GiBAllocatable NOPE Size 0Total PE 0Free PE 0Allocated PE 0PV UUID zxaUnf-kxNt-Udki-sYSk-B3so-8hi1-qTM9gB"/dev/sdb3" is a new physical volume of "1.00 GiB"--- NEW Physical volume ---PV Name /dev/sdb3VG NamePV Size 1.00 GiBAllocatable NOPE Size 0Total PE 0Free PE 0Allocated PE 0PV UUID 6TgcyT-DY1j-9PHt-upJH-nZql-V20D-Ttbm1w
[root@linux-128 ~]# pvsPV VG Fmt Attr PSize PFree/dev/sdb1 lvm2 --- 1.00g 1.00g/dev/sdb2 lvm2 --- 1.00g 1.00g/dev/sdb3 lvm2 --- 1.00g 1.00g
- pvremove /dev/sdb3 删除物理卷
2.创建卷组
- 命令:vgcreate来创建卷组,可以1或者多个物理卷来创建1个卷组;
- 格式:vgcreate [卷组名] dev/sdb1 多个物理卷用空格隔开;
root@linux-128 ~]# vgcreate vg1 /dev/sdb1 dev/sdb2Device dev/sdb2 not found (or ignored by filtering).
- 用命令:vgdisplay 或者vgs来查看信息:
[root@linux-128 ~]# vgdisplay--- Volume group ---VG Name vg1System IDFormat lvm2Metadata Areas 2Metadata Sequence No 1VG Access read/writeVG Status resizableMAX LV 0Cur LV 0Open LV 0Max PV 0Cur PV 2Act PV 2VG Size 1.99 GiBPE Size 4.00 MiBTotal PE 510Alloc PE / Size 0 / 0Free PE / Size 510 / 1.99 GiBVG UUID FbIw1F-dYh6-LL3L-Ah8O-NSTQ-v5gN-G2Lpsy
[root@linux-128 ~]# vgsVG #PV #LV #SN Attr VSize VFreevg1 2 0 0 wz--n- 1.99g 1.99g
- vgremove vg1 删除物理卷
3.创建逻辑卷
- 命令:lvcreate
[root@linux-128 ~]# lvcreate -L 100M -n lv1 vg1Logical volume "lv1" created.
- 命令:lvdisplay或者lvs来查看信息
[root@linux-128 ~]# lvdisplay--- Logical volume ---LV Path /dev/vg1/lv1LV Name lv1VG Name vg1LV UUID TOmOhK-Hf1Y-aKkQ-nfP4-9tu3-cmUD-lbGjMzLV Write Access read/writeLV Creation host, time linux-128, 2017-11-06 22:54:39 +0800LV Status available# open 0LV Size 100.00 MiBCurrent LE 25Segments 1Allocation inheritRead ahead sectors auto- currently set to 8192Block device 253:0
[root@linux-128 ~]# lvsLV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convertlv1 vg1 -wi-a----- 100.00m
4.格式化成ext4
[root@linux-128 ~]# mkfs.ext4 /dev/vg1/lv1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=1024 (log=0)
分块大小=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
25688 inodes, 102400 blocks
5120 blocks (5.00%) reserved for the super user
第一个数据块=1
Maximum filesystem blocks=33685504
13 block groups
8192 blocks per group, 8192 fragments per group
1976 inodes per group
Superblock backups stored on blocks:8193, 24577, 40961, 57345, 73729Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (4096 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
5.挂载:mount
root@linux-128 ~]# mount /dev/vg1/lv1 /mnt
[root@linux-128 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 16G 1.3G 15G 8% /
devtmpfs 907M 0 907M 0% /dev
tmpfs 916M 0 916M 0% /dev/shm
tmpfs 916M 8.6M 908M 1% /run
tmpfs 916M 0 916M 0% /sys/fs/cgroup
/dev/sda1 197M 109M 88M 56% /boot
tmpfs 184M 0 184M 0% /run/user/0
/dev/mapper/vg1-lv1 93M 1.6M 85M 2% /mnt
[root@linux-128 ~]# mkdir /mnt/1122
[root@linux-128 ~]# touch /mnt/23.txt
[root@linux-128 ~]# echo "112233" > 23.txt
[root@linux-128 ~]# cat 23.txt
112233
扩容逻辑卷
- Etx4系统类型扩容前要先卸载挂载点
[root@linux-128 ~]# umount /mnt
- 命令:lvresize -L 来扩容,重新设置卷大小
[root@linux-128 ~]# lvresize -L 200M /dev/vg1/lv1Size of logical volume vg1/lv1 changed from 100.00 MiB (25 extents) to 200.00 MiB (50 extents).Logical volume vg1/lv1 successfully resized.
- e2fsck -f /dev/vg1/lv1 检查磁盘错误 (ext4执行)
[root@linux-128 ~]# e2fsck -f /dev/vg1/lv1
e2fsck 1.42.9 (28-Dec-2013)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要信息
/dev/vg1/lv1: 13/25688 files (7.7% non-contiguous), 8897/102400 blocks
- resize2fs /dev/vg1/lv1 更新逻辑卷信息(ext4执行)
[root@linux-128 ~]# resize2fs /dev/vg1/lv1
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vg1/lv1 to 204800 (1k) blocks.
The filesystem on /dev/vg1/lv1 is now 204800 blocks long.
- 挂载
[root@linux-128 ~]# mount /dev/vg1/lv1 /mnt
[root@linux-128 ~]# ls /mnt
1122 23.txt lost+found
[root@linux-128 ~]# cat 23.txt
112233
扩容之前创建的文件还存在,说明扩容不影响之前的文件。
缩减逻辑卷
- 先卸载挂载点
[root@linux-128 ~]# umount /mnt
- e2fsck -f /dev/vg1/lv1 检查磁盘错误(ext)
[root@linux-128 ~]# e2fsck -f /dev/vg1/lv1
e2fsck 1.42.9 (28-Dec-2013)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要信息
/dev/vg1/lv1: 13/49400 files (7.7% non-contiguous), 11885/204800 blocks
- resize2fs /dev/vg1/lv1 100M 更新逻辑卷信息(ext)
[root@linux-128 ~]# resize2fs /dev/vg1/lv1 100M
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vg1/lv1 to 102400 (1k) blocks.
The filesystem on /dev/vg1/lv1 is now 102400 blocks long.
- lvresize -L 100M /dev/vg1/lv1 重新设置卷大小
[root@linux-128 ~]# lvresize -L 100M /dev/vg1/lv1WARNING: Reducing active logical volume to 100.00 MiB.THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vg1/lv1? [y/n]: ySize of logical volume vg1/lv1 changed from 200.00 MiB (50 extents) to 100.00 MiB (25 extents).Logical volume vg1/lv1 successfully resized.
查看信息
[root@linux-128 ~]# lvsLV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convertlv1 vg1 -wi-a----- 100.00m
- 挂载
[root@linux-128 ~]# mount /dev/vg1/lv1 /mnt
[root@linux-128 ~]# cat /mnt/23.txt
[root@linux-128 ~]# cat 23.txt
112233
并不会因缩容导致文件丢失
Xfs类型来扩容
- 先卸载挂载点
[root@linux-128 ~]# umount /mnt
- 设置文件类型
[root@linux-128 ~]# mkfs.xfs -f /dev/vg1/lv1
meta-data=/dev/vg1/lv1 isize=512 agcount=4, agsize=6400 blks= sectsz=512 attr=2, projid32bit=1= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=25600, imaxpct=25= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=855, version=2= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@linux-128 ~]# lvsLV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convertlv1 vg1 -wi-ao---- 100.00m
[root@linux-128 ~]# mount /dev/vg1/lv1 /mnt
[root@linux-128 ~]# ls /mnt
[root@linux-128 ~]# mkdir /mnt/123
[root@linux-128 ~]# touch /mnt/12.txt
[root@linux-128 ~]# echo '123123' > /mnt/12.txt
[root@linux-128 ~]# cat /mnt/12.txt
123123
- lvresize -L 300M /dev/vg1/lv1;扩容300M
[root@linux-128 ~]# lvresize -L 300M /dev/vg1/lv1Size of logical volume vg1/lv1 changed from 100.00 MiB (25 extents) to 300.00 MiB (75 extents).Logical volume vg1/lv1 successfully resized.
[root@linux-128 ~]# lvsLV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convertlv1 vg1 -wi-ao---- 300.00m
4.xfs_growfs /dev/vg1/lv1; xfs文件系统需要执行
[root@linux-128 ~]# xfs_growfs /dev/vg1/lv1
meta-data=/dev/mapper/vg1-lv1 isize=512 agcount=4, agsize=6400 blks= sectsz=512 attr=2, projid32bit=1= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=25600, imaxpct=25= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=855, version=2= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 25600 to 76800
[root@linux-128 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 16G 1.3G 15G 8% /
devtmpfs 907M 0 907M 0% /dev
tmpfs 916M 0 916M 0% /dev/shm
tmpfs 916M 8.6M 908M 1% /run
tmpfs 916M 0 916M 0% /sys/fs/cgroup
/dev/sda1 197M 109M 88M 56% /boot
tmpfs 184M 0 184M 0% /run/user/0
/dev/mapper/vg1-lv1 297M 5.5M 292M 2% /mnt
[root@linux-128 ~]# cat /mnt/12.txt
123123
卷组扩容
- 逻辑卷最大扩容到卷组的大小,当逻辑卷扩容到卷组大小的时候,就要想办法给卷组扩容,之前用/dev/sdb1和/dev/sdb2组成的卷组vg1,我们现在见/dev/sdb3加进来
[root@linux-128 ~]# vgextend vg1 /dev/sdb3Volume group "vg1" successfully extended
[root@linux-128 ~]# vgsVG #PV #LV #SN Attr VSize VFreevg1 3 1 0 wz--n- <2.99g <2.70g
- lvresize -L 100M /dev/vg1/lv1 重新设置卷大小
[root@linux-128 ~]# lvresize -L 500M /dev/vg1/lv1Size of logical volume vg1/lv1 changed from 300.00 MiB (75 extents) to 500.00 MiB (125 extents).Logical volume vg1/lv1 successfully resized.
[root@linux-128 ~]# lvsLV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convertlv1 vg1 -wi-ao---- 500.00m
磁盘故障 多半是因为磁盘挂载出现问题
- 输入root账号
- vi /etc/fstab 删除最下面一行,保存退出
3 重启服务器