Linux系统管理第五次作业 LVM逻辑卷 磁盘配额

被刻印的时光 ゝ 提交于 2020-03-18 15:50:28

1为主机增加80G SCSI 接口硬盘

 

 

2划分三个各20G的主分区

[root@localhost ~]# fdisk /dev/sdf

欢迎使用 fdisk (util-linux 2.23.2)

 

更改将停留在内存中,直到您决定将更改写入磁盘。

使用写入命令前请三思。

 

Device does not contain a recognized partition table

使用磁盘标识符 0xdd4cecd7 创建新的 DOS 磁盘标签。

 

命令(输入 m 获取帮助)n

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

 

3将三个主分区转换为物理卷(pvcreate),扫描系统中的物理卷

[root@localhost ~]# pvcreate /dev/sdf[1,2,3]

  Physical volume "/dev/sdf1" successfully created

  Physical volume "/dev/sdf2" successfully created

  Physical volume "/dev/sdf3" successfully created

[root@localhost ~]# pvscan

  PV /dev/sdd1   VG zhu      lvm2 [5.00 GiB / 0    free]

  PV /dev/sdd2   VG zhu      lvm2 [5.00 GiB / 0    free]

  PV /dev/sdd3   VG zhu      lvm2 [5.00 GiB / 1012.00 MiB free]

  PV /dev/sdd4   VG zhu      lvm2 [2.00 GiB / 2.00 GiB free]

  PV /dev/sde1   VG cun      lvm2 [5.00 GiB / 0    free]

  PV /dev/sde2   VG cun      lvm2 [5.00 GiB / 0    free]

  PV /dev/sde3   VG cun      lvm2 [5.00 GiB / 2.99 GiB free]

  PV /dev/sda2   VG centos   lvm2 [39.51 GiB / 44.00 MiB free]

  PV /dev/sdf1               lvm2 [20.00 GiB]

  PV /dev/sdf3               lvm2 [20.00 GiB]

  PV /dev/sdf2               lvm2 [20.00 GiB]

  Total: 11 [131.48 GiB] / in use: 8 [71.48 GiB] / in no VG: 3 [60.00 GiB]

 

4使用两个物理卷创建卷组,名字为myvg,查看卷组大小

[root@localhost ~]# vgcreate myvg /dev/sdf[1,2]

  Volume group "myvg" successfully created

[root@localhost ~]# vgdisplay /dev/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               2Hntlm-Jrmi-j3YR-mcfQ-oyBa-3RTM-Noy1ZF

 

5创建逻辑卷mylv,大小为30G

[root@localhost ~]# lvcreate -L 30G -n mylv myvg

  Logical volume "mylv" created.

 

6将逻辑卷格式化成xfs文件系统,并挂载到/data目录上,创建文件测试

[root@localhost ~]# mkfs.xfs /dev/myvg/mylv

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

[root@localhost ~]# mount /dev/myvg/mylv /dat

 

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

 

8.编辑/etc/fstab文件挂载逻辑卷,并支持磁盘配额选项

[root@localhost ~]# vim /etc/fstab

/dev/myvg/mylv     /data                    xfs      auto,usrquota,grpquota      0 0

 

9创建磁盘配额,crushlinux用户在/data目录下文件大小软限制为80M,硬限制为100M

crushlinux用户在/data目录下文件数量软限制为80个,硬限制为100个。

[root@localhost ~]# quotacheck -avug

quotacheck: Skipping /dev/mapper/myvg-mylv [/data]

quotacheck: Cannot find filesystem to check or filesystem not mounted with quota option.

[root@localhost ~]# quotaon /data

quotaon: Enforcing group quota already on /dev/mapper/myvg-mylv

quotaon: Enforcing user quota already on /dev/mapper/myvg-mylv

[root@localhost ~]# edquota -u crushlinux

Disk quotas for user crushlinux (uid 8889):

  Filesystem                   blocks       soft       hard     inodes     soft     hard

  /dev/mapper/myvg-mylv             0       81920     102400         0      80      100

[root@localhost ~]# quota -uvs crushlinux

Disk quotas for user crushlinux (uid 8889):

     Filesystem   space   quota   limit   grace   files   quota   limit   grace

/dev/mapper/myvg-mylv

                     0K  81920K    100M               0      80     100        

 

 

10使用touch dd 命令在/data目录下测试

[root@localhost ~]# su crushlinux

[crushlinux@localhost root]$ touch /data/a{1..102}

touch: 无法创建"/data/a101": 超出磁盘限额

touch: 无法创建"/data/a102": 超出磁盘限额

 

[crushlinux@localhost data]$ dd if=/dev/zero  of=/data/bigfile bs=1M count=105

dd: 写入"/data/bigfile" 出错: 超出磁盘限额

记录了91+0 的读入

记录了90+0 的写出

94371840字节(94 MB)已复制,0.0578038 秒,1.6 GB/

 

11查看配额的使用情况:用户角度

[root@localhost ~]# quota -uvs crushlinux

Disk quotas for user crushlinux (uid 8889):

     Filesystem   space   quota   limit   grace   files   quota   limit   grace

/dev/mapper/myvg-mylv

                     0K  81920K    100M             100*     80     100   6days

 

12查看配额的使用情况:文件系统角度

[root@localhost ~]# repquota -auvs

*** Report for user quotas on device /dev/mapper/myvg-mylv

Block grace time: 7days; Inode grace time: 7days

                        Space limits                File limits

User            used    soft    hard  grace    used  soft  hard  grace

----------------------------------------------------------------------

root      --      4K      0K      0K              3     0     0       

crushlinux -+      0K  81920K    100M            100    80   100  6days

 

*** Status for user quotas on device /dev/mapper/myvg-mylv

Accounting: ON; Enforcement: ON

Inode: #131 (3 blocks, 3 extents)

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!