linux操作系统下的用户磁盘配额场景介绍

韵味老鸟 2024-09-14 15:06:57

linux 操作系统下的用户磁盘配额场景介绍

安装部署qutoa

root@meng:~# apt install quota

Reading package lists... Done

Building dependency tree... Done

Reading state information... Done

Suggested packages:

libnet-ldap-perl rpcbind default-mta | mail-transport-agent

The following NEW packages will be installed:

quota

0 upgraded, 1 newly installed, 0 to remove and 224 not upgraded.

Need to get 213 kB of archives.

After this operation, 1249 kB of additional disk space will be used.

Get:1 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/main amd64 quota amd64 4.06-1build2 [213 kB]

Fetched 213 kB in 2s (123 kB/s)

Preconfiguring packages ...

Selecting previously unselected package quota.

(Reading database ... 75135 files and directories currently installed.)

Preparing to unpack .../quota_4.06-1build2_amd64.deb ...

Unpacking quota (4.06-1build2) ...

Setting up quota (4.06-1build2) ...

Processing triggers for man-db (2.10.2-1) ...

Scanning processes...

Scanning linux images...

Running kernel seems to be up-to-date.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.

给系统账号 meng 配置配额

root@meng:~# id meng

uid=1000(meng) gid=1000(meng) groups=1000(meng),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),110(lxd)

root@meng:~# quota

root@meng:~# which quota

/usr/bin/quota

修改/etc/fstab文件支持配额

root@meng:~# cat /etc/fstab

# /etc/fstab: static file system information.

#

# Use 'blkid' to print the universally unique identifier for a

# device; this may be used with UUID= as a more robust way to name devices

# that works even if disks are added and removed. See fstab(5).

#

# <file system> <mount point> <type> <options> <dump> <pass>

# / was on /dev/ubuntu-vg/ubuntu-lv during curtin installation

/dev/disk/by-id/dm-uuid-LVM-YoRsmY1YOgfCYYiq7hmRVFR12j0fXJtVxxT6h8Tp7Gv0wPdyXnwGoX67m4e2hGQi / ext4 defaults 0 1

# /boot was on /dev/sda2 during curtin installation

/dev/disk/by-uuid/9f85f04d-eef5-4538-b062-caf325262174 /boot ext4 defaults 0 1

改成:

/dev/disk/by-id/dm-uuid-LVM-YoRsmY1YOgfCYYiq7hmRVFR12j0fXJtVxxT6h8Tp7Gv0wPdyXnwGoX67m4e2hGQi / ext4 defaults,usrquota 0 2

重新挂载文件系统

sudo mount -o remount /

使用quotacheck命令创建配额数据库文件

sudo quotacheck -cug / # -c表示创建,-u表示用户配额,-g表示组配额

使用setquota命令为用户meng设置配额,例如限制其使用100MB的软限制和120MB的硬限制:

sudo setquota -u meng 100M 120M 0 0 /

这里,0 0表示不设置inode限制。

使用quota命令检查用户meng的配额:

sudo quota -u meng

使用repquota命令可以生成所有用户的配额使用情况报告

sudo repquota -s /

sudo repquota -a

0 阅读:0

韵味老鸟

简介:感谢大家的关注