1.为主机增加80G SCSI 接口硬盘
[root@localhost ~]# fdisk -l //列出当前系统所有硬盘设备及其分区的信息
磁盘 /dev/sda:42.9 GB, 42949672960 字节,83886080 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0008ccd2
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 83886079 41430016 8e Linux LVM
磁盘 /dev/sdb:85.9 GB, 85899345920 字节,167772160 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
2.划分三个各20G的主分区
[root@localhost ~]# fdisk /dev/sdb //进入磁盘sdb进行分区
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
Device does not contain a recognized partition table
使用磁盘标识符 0x7be66d35 创建新的 DOS 磁盘标签。
命令(输入 m 获取帮助):n //建立新的fenqu
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
分区号 (1-4,默认 1):
起始 扇区 (2048-167772159,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-167772159,默认为 167772159):+20G
分区 1 已设置为 Linux 类型,大小设为 20 GiB
命令(输入 m 获取帮助):n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
分区号 (2-4,默认 2):
起始 扇区 (41945088-167772159,默认为 41945088):
将使用默认值 41945088
Last 扇区, +扇区 or +size{K,M,G} (41945088-167772159,默认为 167772159):+20G
分区 2 已设置为 Linux 类型,大小设为 20 GiB
命令(输入 m 获取帮助):n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
分区号 (3,4,默认 3):
起始 扇区 (83888128-167772159,默认为 83888128):
将使用默认值 83888128
Last 扇区, +扇区 or +size{K,M,G} (83888128-167772159,默认为 167772159):+20G
分区 3 已设置为 Linux 类型,大小设为 20 GiB
命令(输入 m 获取帮助):p
磁盘 /dev/sdb:85.9 GB, 85899345920 字节,167772160 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x7be66d35
设备 Boot Start End Blocks Id System
/dev/sdb1 2048 41945087 20971520 83 Linux
/dev/sdb2 41945088 83888127 20971520 83 Linux
/dev/sdb3 83888128 125831167 20971520 83 Linux
命令(输入 m 获取帮助):w //保存分区设置并退出
3.将三个主分区转换为物理卷(pvcreate),扫描系统中的物理卷
[root@localhost ~]# pvcreate /dev/sdb[123]
Physical volume "/dev/sdb1" successfully created
Physical volume "/dev/sdb2" successfully created
Physical volume "/dev/sdb3" successfully created
[root@localhost ~]# pvscan //扫描系统中的物理卷
PV /dev/sda2 VG centos lvm2 [39.51 GiB / 44.00 MiB free]
PV /dev/sdb3 lvm2 [20.00 GiB]
PV /dev/sdb1 lvm2 [20.00 GiB]
PV /dev/sdb2 lvm2 [20.00 GiB]
4.使用两个物理卷创建卷组,名字为myvg,查看卷组大小
[root@localhost ~]# vgcreate myvg /dev/sdb[12] //将sdb1 sdb2 两个物理卷创建卷组 名字为myvg
Volume group "myvg" successfully created
[root@localhost ~]# vgdisplay myvg //查看卷组大小
--- Volume group ---
VG Name myvg
System ID
Format lvm2
Metadata Areas 2
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 2
Act PV 2
VG Size 39.99 GiB
PE Size 4.00 MiB
Total PE 10238
Alloc PE / Size 0 / 0
Free PE / Size 10238 / 39.99 GiB
VG UUID Gu4Uom-tzmy-7pkC-FHga-FrSH-m8s7-YSW2Cv
5.创建逻辑卷mylv,大小为30G
[root@localhost ~]# lvcreate -L 30G -n mylv myvg //.创建逻辑卷mylv,大小为30G
Logical volume "mylv" created.
[root@localhost ~]# lvdisplay /dev/myvg/mylv //查看逻辑卷mylv的大小
--- Logical volume ---
LV Path /dev/myvg/mylv
LV Name mylv
VG Name myvg
LV UUID odaxxT-1A1l-3gtt-0El5-Bo7h-lbY0-1SL1N2
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2019-08-01 17:54:39 +0800
LV Status available
# open 0
LV Size 30.00 GiB
Current LE 7680
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
6.将逻辑卷格式化成xfs文件系统,并挂载到/data目录上,创建文件测试
[root@localhost ~]# mkfs.xfs /dev/myvg/mylv //将逻辑卷/dev/myvg/mylv 格式化成xfs文件系统
meta-data=/dev/myvg/mylv isize=256 agcount=4, agsize=1966080 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=7864320, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=3840, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost ~]# mkdir /data //创建目录/data
[root@localhost ~]# mount /dev/myvg/mylv /data //将/dev/myvg/mylv 挂载到/data
7.增大逻辑卷到35G
[root@localhost ~]# lvextend -L +5G /dev/myvg/mylv // 增大逻辑卷
Size of logical volume myvg/mylv changed from 30.00 GiB (7680 extents) to 35.00 GiB (8960 extents).
Logical volume mylv successfully resized
[root@localhost ~]# df -Th //查看磁盘大小
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root xfs 38G 4.6G 33G 13% /
devtmpfs devtmpfs 985M 0 985M 0% /dev
tmpfs tmpfs 994M 84K 994M 1% /dev/shm
tmpfs tmpfs 994M 8.9M 986M 1% /run
tmpfs tmpfs 994M 0 994M 0% /sys/fs/cgroup
/dev/sda1 xfs 497M 107M 391M 22% /boot
/dev/sr0 iso9660 4.1G 4.1G 0 100% /run/media/root/CentOS 7 x86_64
/dev/mapper/myvg-mylv xfs 35G 33M 35G 1% /data
8.编辑/etc/fstab文件挂载逻辑卷,并支持磁盘配额选项
[root@localhost ~]# vi /etc/fstab //编辑/etc/fstab文件挂载逻辑卷
#
# /etc/fstab
# Created by anaconda on Thu Jul 25 20:29:27 2019
#
# 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
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=ac8a3229-bfd7-4ed5-a776-7bfb7d35c8a8 /boot xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
/dev/myvg/mylv /data xfs defaults,usrquota,grpquota 0 0 //增加的内容
~
~
~
~
~
~
~
~
~
~
~
~
~
~
:wq //保存退出
9.创建磁盘配额,crushlinux用户在/data目录下文件大小软限制为80M,硬限制为100M,
crushlinux用户在/data目录下文件数量软限制为80个,硬限制为100个
[root@localhost ~]# mkfs.ext4 /dev/sdb3 //
[root@localhost ~]# mkdir /data2
[root@localhost ~]# mount /dev/sdb3 /data2
[root@localhost ~]# mount -o remount,usrquota,grpquota /data2
[root@localhost ~]# mount | grep /data2
/dev/sdb3 on /data2 type ext4 (rw,relatime,seclabel,quota,usrquota,grpquota,data=ordered)
[root@localhost ~]# grep /dev/sdb3 /etc/mtab
/dev/sdb3 /data2 ext4 rw,seclabel,relatime,quota,usrquota,grpquota,data=ordered 0 0
[root@localhost ~]# vim /etc/fstab //编辑 /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Jul 25 20:29:27 2019
#
# 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
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=ac8a3229-bfd7-4ed5-a776-7bfb7d35c8a8 /boot xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
/dev/myvg/mylv /data xfs defaults 0 0
/dev/sdb3 /data2 ext4 defaults,usrquota,grpquota 0 0 //增加内容
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
:wq
[root@localhost ~]# useradd crushlinux //创建用户
[root@localhost ~]# passwd crushlinux //加密用户
更改用户 crushlinux 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
[root@localhost ~]# quotacheck -avug //扫描文件系统并建立磁盘配额记录文件
quotacheck: Your kernel probably supports journaled quota but you are not using it. Consider switching to journaled quota to avoid running quotacheck after an unclean shutdown.
quotacheck: Scanning /dev/sdb3 [/data2] done
quotacheck: Cannot stat old user quota file /data2/aquota.user: 没有那个文件或目录. Usage will not be subtracted.
quotacheck: Cannot stat old group quota file /data2/aquota.group: 没有那个文件或目录. Usage will not be subtracted.
quotacheck: Cannot stat old user quota file /data2/aquota.user: 没有那个文件或目录. Usage will not be subtracted.
quotacheck: Cannot stat old group quota file /data2/aquota.group: 没有那个文件或目录. Usage will not be subtracted.
quotacheck: Checked 2 directories and 0 files
quotacheck: Old file not found.
quotacheck: Old file not found.
[root@localhost ~]# quotaon -avug //启动磁盘配额服务
/dev/sdb3 [/data2]: group quotas turned on
/dev/sdb3 [/data2]: user quotas turned on
[root@localhost ~]# edquota -u crushlinux
Disk quotas for user crushlinux (uid 1001):
Filesystem blocks soft hard inodes soft hard
/dev/sdb3 0 81920 102400 80 100
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
:wq
10.使用touch dd 命令在/data目录下测试
[root@localhost ~]# su crushlinux //切换用户crushlinux
[crushlinux@localhost root]$ dd if=/dev/zero of=/data2/ceshi bs=1M count=90
sdb3: warning, user block quota exceeded.
记录了90+0 的读入
记录了90+0 的写出
94371840字节(94 MB)已复制,0.0975859 秒,967 MB/秒
[crushlinux@localhost root]$ dd if=/dev/zero of=/data2/ceshi bs=1M count=101
sdb3: warning, user block quota exceeded.
sdb3: write failed, user block limit reached.
dd: 写入"/data2/ceshi" 出错: 超出磁盘限额
记录了101+0 的读入
记录了100+0 的写出
104857600字节(105 MB)已复制,0.0685996 秒,1.5 GB/秒
[crushlinux@localhost root]$ touch /data2/{1..90}.txt //创建90个文件
sdb3: warning, user file quota exceeded. //警告 超过用户文件配额
11.查看配额的使用情况:用户角度
[crushlinux@localhost root]$ quota //查看用户的限额报表
Disk quotas for user crushlinux (uid 1001):
Filesystem blocks quota limit grace files quota limit grace
/dev/sdb3 102400* 81920 102400 6days 91* 80 100 6days
12.查看配额的使用情况:文件系统角度
[root@localhost ~]# repquota -avug //查看文件系统的限额报表
*** Report for user quotas on device /dev/sdb3
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 20 0 0 2 0 0
crushlinux ++ 102400 81920 102400 6days 91 80 100 6days
Statistics:
Total blocks: 7
Data blocks: 1
Entries: 2
Used average: 2.000000
*** Report for group quotas on device /dev/sdb3
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
Group used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 20 0 0 2 0 0
crushlinux -- 102400 0 0 91 0 0
Statistics:
Total blocks: 7
Data blocks: 1
Entries: 2
Used average: 2.000000
来源:https://www.cnblogs.com/mengwei123/p/11285071.html