本文内容实现从lvm创建文件系统到实现磁盘配额目的。
一、LVM
利用两块20G的硬盘
Lvm的管理命令
功能 |
物理卷管理 |
卷组管理 |
逻辑卷管理 |
Scan 扫描 |
pvscan |
vgscan |
lvscan |
Create 建立 |
pvcreate |
vgcreate |
lvcreate |
Display 显示 |
pvdisplay |
vgdisplay |
lvdisplay |
Remove 删除 |
pvremove |
vgremove |
lvremove |
Extend 扩展 |
vgextend |
lvextend |
|
Reduce 减少 |
vgreduce |
lvreduce |
pvcreate 设备名1 [设备名2 … …]
vgcreate 卷组名 物理卷名1 物理卷名2
lvcreate -L 容量大小 -n 逻辑卷名 卷组名
lvextend -L +大小 /dev/卷组名/逻辑卷名
创建物理卷 pvcreate
[[email protected] ~]# fdisk –l Disk /dev/sdb: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280bytes Sector size (logical/physical): 512 bytes /512 bytes I/O size (minimum/optimal): 512 bytes / 512bytes Disk identifier: 0x00000000 Disk /dev/sdc: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280bytes Sector size (logical/physical): 512 bytes /512 bytes I/O size (minimum/optimal): 512 bytes / 512bytes Disk identifier: 0x00000000 [[email protected] ~]# pvcreate /dev/sdb/dev/sdc Physical volume "/dev/sdb" successfully created Physical volume "/dev/sdc" successfully created
创建卷组 vgcreate
[[email protected] ~]# vgcreate vg01 /dev/sdb/dev/sdc Volume group "vg01" successfully created
创建逻辑卷 lvcreate
-查看卷组
[[email protected] ~]# vgdisplay ---Volume group --- VGName vg01 System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 1 VGAccess read/write VGStatus resizable MAXLV 0 CurLV 0 Open LV 0 MaxPV 0 CurPV 2 ActPV 2 VGSize 39.99 GiB PESize 4.00 MiB Total PE 10238 Alloc PE / Size 0 / 0 Free PE / Size 10238 / 39.99 GiB VGUUID HtIkEH-ZZP9-MOFK-dW3n-tyL8-33Gn-EODL2n
-创建逻辑卷
[[email protected] ~]# lvcreate -L 20G -n lv01vg01 Logical volume "lv01" created
-查看逻辑卷
[[email protected] ~]# lvdisplay ---Logical volume --- LVPath /dev/vg01/lv01 LVName lv01 VGName vg01 LVUUID 7Jm0jx-A4wz-AduE-B7oA-2cCJ-WOCq-bkwotJ LVWrite Access read/write LVCreation host, time localhost.localdomain, 2016-09-18 05:37:49 +0800 LVStatus available #open 0 LVSize 20.00 GiB Current LE 5120 Segments 2 Allocation inherit Read ahead sectors auto -currently set to 256 Block device 253:0
-格式化
[[email protected] ~]# mkfs.ext4/dev/vg01/lv01
-逻辑卷扩容
[[email protected] ~]# lvextend -L +19G/dev/vg01/lv01 Extending logical volume lv01 to 39.00 GiB Logical volume lv01 successfully resized
-格式化
[[email protected] ~]# resize2fs/dev/vg01/lv01 resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/vg01/lv01to 10223616 (4k) blocks. The filesystem on /dev/vg01/lv01 is now10223616 blocks long.
二、设置磁盘配额
实现磁盘限额的条件
需要 Linux 内核支持
安装 quota 软件包
Linux磁盘限额的特点
作用范围:针对指定的文件系统(分区)
限制对象:用户帐号、组帐号
限制类型:
磁盘容量(默认单位为 KB)
文件数量
限制方法:
软限制
硬限制
以支持配额功能的方式挂载文件系统
[[email protected] ~]# fdisk -l …… Disk /dev/mapper/vg01-lv01: 41.9 GB,41875931136 bytes 255 heads, 63 sectors/track, 5091 cylinders Units = cylinders of 16065 * 512 = 8225280bytes Sector size (logical/physical): 512 bytes /512 bytes I/O size (minimum/optimal): 512 bytes / 512bytes Disk identifier: 0x00000000 [[email protected] ~]# mkdir /qtest [[email protected] ~]# vim /etc/fstab …… /dev/mapper/vg01-lv01 /qtest ext4 defaults,usrquota,grpquota 0 0 [[email protected] ~]# mount /qtest [[email protected] ~]# mount | tail -1 /dev/mapper/vg01-lv01 on /qtest type ext4(rw,usrquota,grpquota)
检测磁盘配额并生成磁盘配额文件
[[email protected] ~]# quotacheck –augcv [[email protected] ~]# ll /qtest/ 总用量 32 -rw-------. 1 root root 6144 9月 18 05:59 aquota.group -rw-------. 1 root root 6144 9月 18 05:59 aquota.user drwx------. 2 root root 16384 9月 18 05:39 lost+found
编辑用户和组账号的配额设置
[[email protected] ~]# useradd p1 [[email protected] ~]# edquota -u p1 Disk quotas for user p1 (uid 500): Filesystem blocks soft hard inodes soft hard /dev/mapper/vg01-lv01 0 100000 200000 0 5 10 ~
第3列:磁盘容量软限制
第4列:磁盘容量硬限制
第6列:文件个数软限制
第7列:文件个数软限制
-对组限额
edquota -g 组名
对组限额时,以该组作为基本组的用户才受限制。
启动文件系统的磁盘配额功能
[[email protected] ~]# quotaon -ugv /qtest/ /dev/mapper/vg01-lv01 [/qtest]: groupquotas turned on /dev/mapper/vg01-lv01 [/qtest]: user quotasturned on [[email protected] ~]# quotaoff -ugv /qtest/ /dev/mapper/vg01-lv01 [/qtest]: groupquotas turned off /dev/mapper/vg01-lv01 [/qtest]: user quotasturned off
复制:Edquota -p -模板用户 -u 用户列表(u4 u5 u6 u7 u8 )
Edquota -t 更改宽限期
-验证磁盘配额功能
[[email protected] ~]# chmod 777 /qtest/ [[email protected] ~]# su - p1 [[email protected] ~]$ cd /qtest/ [[email protected] qtest]$ cat /dev/zero>> test dm-0: warning, user block quota exceeded. dm-0: write failed, user block limitreached. cat: 写入错误: 超出磁盘限额 [[email protected] qtest]$ ll -h 总用量 196M -rw-------. 1 root root 7.0K 9月 18 06:19 aquota.group -rw-------. 1 root root 7.0K 9月 18 06:11 aquota.user drwx------. 2 root root 16K 9月 18 05:39 lost+found -rw-rw-r--. 1 p1 p1 196M 9月 18 06:19 test
-查看用户或分区的配额使用情况
[[email protected] ~]# quota -u p1 Disk quotas for user p1 (uid 500): Filesystem blocks quota limit grace files quota limit grace /dev/mapper/vg01-lv01 200000* 100000 200000 6days 1 5 10 [[email protected] ~]# repquota /qtest/ *** Report for user quotas on device/dev/mapper/vg01-lv01 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 p1 +- 200000 100000 200000 6days 1 5 10
侧重用户、组帐号角度:使用quota命令
quota -u 用户名
quota -g 组名
侧重文件系统角度:使用repquota
时间: 2024-10-08 10:28:54