文章目录
- 前言
- 一、存储管理
- 1.parted
- 2.挂载的时候需要注意的问题
- 3.磁盘配额
- 二、高级存储管理
- 1.逻辑卷
- 2.lvm拉伸
- 3.lvm缩减
- 4.vdo(Virtual Data Optimize)
前言
上一节的基本存储中学习到了swap分区,还有剩下的磁盘配额将继续学习;以及主要会学到高级存储管理:比如逻辑卷和vdo
一、存储管理
1.parted
我们除了有MBR分区方式之外,还有parted分区方式,相对来说,我个人比较喜欢MBR分区方式,但是两种方法我们都需要掌握:
parted /dev/sdb mklabel gpt 将MBR磁盘格式化为gpg磁盘
parted /dev/sdb mklabel msdos 一个gpg磁盘格式化为MBR磁盘```powershell
[root@westos_student50 ~]# parted /dev/sdb mklabel gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? y
Information: You may need to update /etc/fstab.[root@westos_student50 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 80G 0 disk
├─sda1 8:1 0 512M 0 part /boot
├─sda2 8:2 0 4G 0 part [SWAP]
└─sda3 8:3 0 75.5G 0 part /
sdb 8:16 0 20G 0 disk
sr0 11:0 1 1024M 0 rom
[root@westos_student50 ~]# parted /dev/sdb mklabel gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? y
Information: You may need to update /etc/fstab.[root@westos_student50 ~]# parted /dev/sdb mklabel msdos
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? y
Information: You may need to update /etc/fstab.[root@westos_student50 ~]# parted /dev/sdb mkpart primary 1 100
Information: You may need to update /etc/fstab.[root@westos_student50 ~]# parted /dev/sdb mkpart primary 101 200
Information: You may need to update /etc/fstab.
parted /dev/sdb mkpart primary 1 100 对磁盘进行分区,第一个区域为1~100,以此类推
2.挂载的时候需要注意的问题
[root@westos_student50 ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=65536 blks= sectsz=512 attr=2, projid32bit=1= crc=1 finobt=1, sparse=1, rmapbt=0= reflink=1
data = bsize=4096 blocks=262144, 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=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@westos_student50 ~]# mount /dev/sdb1 /mnt/
[root@westos_student50 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 894096 0 894096 0% /dev
tmpfs 921932 0 921932 0% /dev/shm
tmpfs 921932 18092 903840 2% /run
tmpfs 921932 0 921932 0% /sys/fs/cgroup
/dev/sda3 79127812 18960016 60167796 24% /
/dev/sda1 518816 220576 298240 43% /boot
tmpfs 184384 16 184368 1% /run/user/42
tmpfs 184384 36 184348 1% /run/user/0
/dev/sdb1 1038336 40292 998044 4% /mnt
# /etc/fstab
# Created by anaconda on Tue Jun 22 19:16:36 2021
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
UUID=79151530-7d2a-46a7-80ff-fd7c1f4bf571 / xfs defaults 0 0
UUID=e96b392b-a3ba-49e1-8ea7-1bd2cccd07e2 /boot xfs defaults 0 0
UUID=ddde1134-26f7-413f-8e4b-104776b67f53 swap swap defaults 0 0
/dev/sdb1 /mnt xfs defaults 0 0
UUID=79151530-7d2a-46a7-80ff-fd7c1f4bf571 / xfs defaults 0 0
UUID=e96b392b-a3ba-49e1-8ea7-1bd2cccd07e2 /boot xfs defaults 0 0
UUID=ddde1134-26f7-413f-8e4b-104776b67f53 swap swap defaults 0 0
/dev/sdb1 swap swap defaults,pri=4 0 0
3.磁盘配额
**[root@westos_student50 ~]# fdisk /dev/sdbWelcome 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): p
Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 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: 0x446c4a54Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 2099199 2097152 1G 83 Linux
/dev/sdb2 2099200 4196351 2097152 1G 83 Linux**
格式化
[root@westos_student50 ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.45.4 (23-Sep-2019)
Creating filesystem with 262144 4k blocks and 65536 inodes
Filesystem UUID: 625a554f-b39b-47de-ae44-23750f8762fc
Superblock backups stored on blocks: 32768, 98304, 163840, 229376Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
配置磁盘配额文件
Disk quotas for user mou (uid 1001):Filesystem blocks soft hard inodes soft hard/dev/sdb1 152 0 20480 5 3 5
~
创建用户配额,创建组配额
[root@westos_student50 ~]# quotacheck -ug /dev/sdb1
[root@westos_student50 ~]# cd /disk
[root@westos_student50 disk]# ls
aquota.group aquota.user lost+found
[root@westos_student50 disk]# useradd mou
切换到普通用户,发现建立第六个模块时就不能成功建立,因为设置了只能建立五个
28672 bytes (29 kB, 28 KiB) copied, 0.000325568 s, 88.1 MB/s
[mou@westos_student50 disk]$ dd if=/dev/zero of=/disk/1 bs=1024 count=30
30+0 records in
30+0 records out
30720 bytes (31 kB, 30 KiB) copied, 0.000269243 s, 114 MB/s
[mou@westos_student50 disk]$ dd if=/dev/zero of=/disk/2 bs=1024 count=30
30+0 records in
30+0 records out
30720 bytes (31 kB, 30 KiB) copied, 0.000320665 s, 95.8 MB/s
[mou@westos_student50 disk]$ dd if=/dev/zero of=/disk/3 bs=1024 count=25
25+0 records in
25+0 records out
25600 bytes (26 kB, 25 KiB) copied, 0.000152839 s, 167 MB/s
[mou@westos_student50 disk]$ dd if=/dev/zero of=/disk/4 bs=1024 count=28
sdb1: warning, user file quota exceeded.
28+0 records in
28+0 records out
28672 bytes (29 kB, 28 KiB) copied, 0.000316575 s, 90.6 MB/s
[mou@westos_student50 disk]$ dd if=/dev/zero of=/disk/5 bs=1024 count=32
32+0 records in
32+0 records out
32768 bytes (33 kB, 32 KiB) copied, 0.000182678 s, 179 MB/s
[mou@westos_student50 disk]$ dd if=/dev/zero of=/disk/6 bs=1024 count=32
sdb1: write failed, user file limit reached.
dd: failed to open '/disk/6': Disk quota exceeded
如果新建的文件超过设置的最大限度,则不能建立
[mou@westos_student50 ~]$ dd if=/dev/zero of=/disk/1 bs=1M count=22
sdb1: write failed, user block limit reached.
dd: error writing '/disk/1': Disk quota exceeded
20+0 records in
19+0 records out
20848640 bytes (21 MB, 20 MiB) copied, 0.0435519 s, 479 MB/s
二、高级存储管理
1.逻辑卷
[root@westos_student50 ~]# pvcreate /dev/sdb2Physical volume "/dev/sdb2" successfully created.
[root@westos_student50 ~]# vgcreate westossvg -s 2M /dev/sdb2Volume group "westossvg" successfully created
[root@westos_student50 ~]# lvcreate -L 100M -n westoslv westosvg Volume group "westosvg" not found.Cannot process volume group westosvg
[root@westos_student50 ~]# lvcreate -L 100M -n westoslv westossvg Logical volume "westoslv" created.
[root@westos_student50 ~]# mkfs.xfs /dev/westossvg/westoslv
meta-data=/dev/westossvg/westoslv isize=512 agcount=4, agsize=6400 blks= sectsz=512 attr=2, projid32bit=1= crc=1 finobt=1, sparse=1, rmapbt=0= reflink=1
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=1368, version=2= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@westos_student50 ~]# mount /dev/westossvg/westoslv /disk
监控命令所看到的创建
PV VG Fmt Attr PSize PFree/dev/sdb2 westossvg lvm2 a-- 1022.00m 922.00m
====VG #PV #LV #SN Attr VSize VFreewestossvg 1 1 0 wz--n- 1022.00m 922.00m
====LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convertwestoslv westossvg -wi-ao---- 100.00m
====
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/westossvg-westoslv 95M 6.0M 89M 7% /disk
2.lvm拉伸
[root@westos_student50 ~]# lvextend -L 200M /dev/westossvg/westoslv Size of logical volume westossvg/westoslv changed from 100.00 MiB (50 extents) to 200.00 MiB (100 extents).Logical volume westossvg/westoslv successfully resized.
[root@westos_student50 ~]# lvextend -L 300M /dev/westossvg/westoslv Size of logical volume westossvg/westoslv changed from 200.00 MiB (100 extents) to 300.00 MiB (150 extents).Logical volume westossvg/westoslv successfully resized.
279 lvextend -L 1500M /dev/westossvg/westoslv 280 pvcreate /dev/sdb3281 vgextend westossvg /dev/sdb3282 lvextend -L 2500M /dev/westossvg/westoslv 283 xfs_growfs /disk/284 mount285 umount /disk286 mkfs.ext4 /dev/westossvg/westoslv 287 mount /dev/westossvg/westoslv /disk/288 df289 lvextend -L 1800M /dev/westossvg/westoslv 290 resize2fs /dev/westossvg/westoslv 291 history
3.lvm缩减
先将sdb2上的内容移动到sdb3上,再将sdb2移除就可以完成
292 umount /disk293 e2fsck -f /dev/westossvg/westoslv 294 resize2fs /dev/westossvg/westoslv 300M295 mount /dev/westossvg/westoslv /disk296 lvreduce -L 300M /dev/westossvg/westoslv 297 vgreduce westossvg /dev/sdb2298 pvmove /dev/sdb2 /dev/sdb3299 vgreduce westossvg /dev/sdb2300 pvremove /dev/sdb2
4.vdo(Virtual Data Optimize)
[root@westos_student50 ~]# cp /iso/westos.jpg /westos/
[root@westos_student50 ~]# vdostats --human-readable
Device Size Used Available Use% Space saving%
/dev/mapper/vdo1 20.0G 10.0G 10.0G 49% 1%
[root@westos_student50 ~]# cp /iso/westos.jpg /westos/
rhel-8.2-x86_64-dvd.iso westos.jpg
[root@westos_student50 ~]# cp /iso/westos.jpg /westos/westos.jpg
cp: overwrite '/westos/westos.jpg'? y
[root@westos_student50 ~]# vdostats --human-readable
Device Size Used Available Use% Space saving%
/dev/mapper/vdo1 20.0G 10.0G 10.0G 49% 1%
[root@westos_student50 ~]# vim /etc.fstab
[root@westos_student50 ~]# vim /etc/fstab
本文链接:https://my.lmcjl.com/post/7182.html
展开阅读全文
4 评论