Linux Exercício 16.1 Cota de disco

Linux Exercício 16.1 Cota de disco

Bem-vindo ao escanear o código QR para seguir a conta pública do WeChat, Ambition e Home, para mais conteúdo relacionado

● Preparação preliminar: há usuário1 usuário, partição / dev / sdb1 e o sistema de arquivos da partição é ext4, crie um novo diretório / mnt / ponto de montagem1

[root@localhost ~]# useradd user1
[root@localhost ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。

Device does not contain a recognized partition table
使用磁盘标识符 0xb4c67292 创建新的 DOS 磁盘标签。

命令(输入 m 获取帮助):n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
分区号 (1-4,默认 1):1
起始 扇区 (2048-41943039,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-41943039,默认为 41943039):
将使用默认值 41943039
分区 1 已设置为 Linux 类型,大小设为 20 GiB

命令(输入 m 获取帮助):
命令(输入 m 获取帮助):w				//保存重要
The partition table has been altered!

Calling ioctl() to re-read partition table.
正在同步磁盘。
[root@localhost ~]# mkdir /mnt/mountpoint1
[root@localhost ~]# mkfs -t ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5242624 blocks
262131 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=2153775104
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000
Allocating group tables: 完成                            
正在写入inode表: 完成                            
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

● Inicie o vi para editar o arquivo / etc / fstab. Monte a partição / dev / sdb1 no arquivo / etc / fstab em / mnt / mountpoint1 e adicione cotas de disco para usuários e grupos. Reinicie o sistema.

[root@localhost ~]# vi /etc/fstab
/dev/sdb1	/mnt/mountpoint1 ext4 defaults,usrquota,grpquota 0 0
##查询是否挂载
[root@localhost aoian]# mount | grep sdb
/dev/sdb1 on /mnt/mountpoint1 type ext4 (rw,relatime,seclabel,quota,usrquota,grpquota,data=ordered)

● Use o comando quotacheck para criar os arquivos aquota.user e aquota.group.

[root@localhost aoian]# quotacheck -ug /dev/sdb1
[root@localhost aoian]# cd /mnt/mountpoint1
[root@localhost mountpoint1]# ls
aquota.group  aquota.user  lost+found

● Use o comando edquota -u user1 para definir a função de quota de disco para o usuário user1. Defina o soft of blocks como 5000 e o hard to 10000. Salve e saia após a edição.

[root@localhost aoian]# edquota –u user1
Disk quotas for user user1 ( uid 1001) :
Filesystem 	 blocks 	soft 	hard 	inodes 	soft 	hard 
/dev/sdb1        0  	5000    10000      0      0		  0

● Use o comando quotaon para habilitar a função quota.

[root@localhost aoian]# quotaon -ug /mnt/mountpoint

● Verifique a cota e o uso do disco.

[root@localhost aoian]# df -h /dev/sdb1
# -h 作用显示单位便于查看

● Tente copiar arquivos cujos tamanhos excedam o limite flexível e o limite rígido da cota de disco para o diretório inicial do usuário para verificar se a função de cota de disco funciona.

[root@RHEL7-1 ~] # chmod 777 /mnt/mountpoint1
root@RHEL7- 1 ~] # su user1
[ user1@RHEL7- 1 root]$ dd if=/dev/zero of=/mnt/mountpoint1/file1 bs=6000 count=1
sdb1: warning,user block quota exceeded.
记录了1+0的读入
记录了1+0的写出
6000000字节(6.0 MB)已复制,0. 0240897秒,249 MB/秒
[user1@RHEL7-1 root]$ dd if=/dev/zero of=/mnt/mountpoint1/file2 bs=6000 count=1
sdb1: write failed, user block limit reached.
dd: 写入"/mnt/mountpoint1/file2" 出错:超出磁盘限额
记录了1+0的读入
记录了0+0的写出
4239360字节(4.2 MB)已复制,0. 015877秒,267 MB/秒

● Tente definir o limite flexível de 2 arquivos e o limite rígido de 4 arquivos sozinho e verifique se a função de cota de disco funciona.

[root@RHEL7-1 ~]# su user1
[user1@RHEL7-1 root] $ cd /mnt/ mountpoint1
[user1@RHEL7-1 mountpoint1]$ touch file1
[user1@RHEL7-1 mountpoint1] $ touch file2
[user1@RHEL7-1 mountpoint1]$ touch file3
sdb1: warning, user file quota exceeded.
[user1@RHEL7-1 mountpoint1] $ touch file4
[user1@RHEL7-1 mountpoint1] $ touch file5
sdb1: write failed,user file limit reached.
touch:无法创建"file5":超出磁盘限额

Acho que você gosta

Origin blog.csdn.net/m0_46653702/article/details/110638345
Recomendado
Clasificación