盗版视频网站怎么做的,饮食网站开发需求,wordpress 图片命名,漳州做网站优化Linux是一个多用户多任务的操作系统#xff0c;在使用中可能会有几个人对服务器有操作#xff0c;几个用户共同使用一个共享磁盘的情况#xff0c;因为我们的硬盘是有限的#xff0c;我们需要对用户的空间进行限制。这里使用磁盘配额#xff0c;可以很方便的对用户的空间进…Linux是一个多用户多任务的操作系统在使用中可能会有几个人对服务器有操作几个用户共同使用一个共享磁盘的情况因为我们的硬盘是有限的我们需要对用户的空间进行限制。这里使用磁盘配额可以很方便的对用户的空间进行额度限制。1加入一块硬盘分出一个主分区[rootlocalhost ~]# fdisk /dev/sdbDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel with disk identifier 0xa03faa82.Changes will remain in memory only, until you decide to write them.After that, of course, the previous content wont be recoverable.Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)WARNING: DOS-compatible mode is deprecated. Its strongly recommended toswitch off the mode (command c) and change display units tosectors (command u).Command (m for help): nCommand actione extendedp primary partition (1-4)pPartition number (1-4): 1First cylinder (1-2610, default 1):Using default value 1Last cylinder, cylinders or size{K,M,G} (1-2610, default 2610):Using default value 2610Command (m for help): pDisk /dev/sdb: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits cylinders of 16065 * 512 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0xa03faa82Device Boot Start End Blocks Id System/dev/sdb1 1 2610 20964793 83 LinuxCommand (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.2.格式化分区并挂载[rootlocalhost ~]# mkfs.ext4 /dev/sdb1[rootlocalhost ~]# mkdir /data ##创建一个用户共享使用的目录[rootlocalhost ~]# mount /dev/sdb1 /data/ ##将分区挂载到共享目录[rootlocalhost ~]# mount ##查看挂载情况/dev/mapper/VolGroup-lv_root on / type ext4 (rw)proc on /proc type proc (rw)sysfs on /sys type sysfs (rw)devpts on /dev/pts type devpts (rw,gid5,mode620)tmpfs on /dev/shm type tmpfs (rw)/dev/sda1 on /boot type ext4 (rw)none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)/dev/sdb1 on /data type ext4 (rw)写入到开机挂载里面[rootlocalhost ~]# vi /etc/fstab[rootlocalhost ~]# tail -1 /etc/fstab/dev/sdb1 /data ext4 defaults 0 03.重新挂载使文件目录支持磁盘配额[rootlocalhost ~]# mount -o remount,usrquota,grpquota /dev/sdb1[rootlocalhost ~]# mount/dev/mapper/VolGroup-lv_root on / type ext4 (rw)proc on /proc type proc (rw)sysfs on /sys type sysfs (rw)devpts on /dev/pts type devpts (rw,gid5,mode620)tmpfs on /dev/shm type tmpfs (rw)/dev/sda1 on /boot type ext4 (rw)none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)/dev/sdb1 on /data type ext4 (rw,usrquota,grpquota) ##再次查看分区挂载可以看到支持磁盘配额同样使它开机挂载支持磁盘配额[rootlocalhost ~]# vi /etc/fstab[rootlocalhost ~]# tail -1 /etc/fstab/dev/sdb1 /data ext4 defaults,usrquota,grpquota 0 03。下载磁盘配额软件[rootlocalhost ~]# yum -y install quota4.生成磁盘配额的数据库文件[rootlocalhost ~]# quotacheck -ugvc /data/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/sdb1 [/data] donequotacheck: Cannot stat old user quota file /data/aquota.user: 没有那个文件或目录. Usage will not be substracted.quotacheck: Cannot stat old group quota file /data/aquota.group: 没有那个文件或目录. Usage will not be substracted.quotacheck: Cannot stat old user quota file /data/aquota.user: 没有那个文件或目录. Usage will not be substracted.quotacheck: Cannot stat old group quota file /data/aquota.group: 没有那个文件或目录. Usage will not be substracted.quotacheck: Checked 2 directories and 0 filesquotacheck: Old file not found.quotacheck: Old file not found.查看生成的磁盘配置数据库文件[rootlocalhost ~]# ls /data/aquota.group aquota.user lostfound5.新建需要限制的用户和组[rootlocalhost ~]# useradd u01 ##新建用户[rootlocalhost ~]# useradd u02[rootlocalhost ~]# echo 123123 |passwd --stdin u01更改用户 u01 的密码 。passwd 所有的身份验证令牌已经成功更新。[rootlocalhost ~]# echo 123123 |passwd --stdin u02更改用户 u02 的密码 。passwd 所有的身份验证令牌已经成功更新。[rootlocalhost ~]# groupadd g01 ##新建组[rootlocalhost ~]# usermod -g g01 u01 ##将用户加入组[rootlocalhost ~]# usermod -g g01 u02[rootlocalhost ~]# id u01 ##确认用户信息uid500(u01) gid502(g01) 组502(g01)[rootlocalhost ~]# id u02uid501(u02) gid502(g01) 组502(g01)6.对用户进行额度配置setauota -u 用户 或(-g 组) 大小软限制 大小硬限制 数量软限制 数量硬限制 对哪个目录##大小限制的单位是kb软限制是当达到这个限制时再创建文件或导入数据会出现提示信息不过还可以再往里面新建。当到达硬限制时就真的无法创建了。[rootlocalhost ~]# setquota -u u01 10000 15000 10 15 /data/7.开启磁盘配额 重启系统也可以[rootlocalhost ~]# quotaon -a给所有人可写入权限即可要在其他用户新建文件测试[rootlocalhost ~]# chmod 777 /data/[rootlocalhost ~]# su - u01 ##切换到u01[u01localhost ~]$ touch /data/{1..20}.mp3 ##新建20个文件sdb1: warning, user file quota exceeded. ##这个到达软限制有提醒sdb1: write failed, user file limit reached. ##这个到达硬限制提示写入错误touch: 无法创建/data/16.mp3: 超出磁盘限额touch: 无法创建/data/17.mp3: 超出磁盘限额touch: 无法创建/data/18.mp3: 超出磁盘限额touch: 无法创建/data/19.mp3: 超出磁盘限额touch: 无法创建/data/20.mp3: 超出磁盘限额最后查看目录发现创建了15个文件这个15是硬限制的设置[u01localhost ~]$ ls /data/10.mp3 12.mp3 14.mp3 1.mp3 3.mp3 5.mp3 7.mp3 9.mp3 aquota.user11.mp3 13.mp3 15.mp3 2.mp3 4.mp3 6.mp3 8.mp3 aquota.group lostfound[u01localhost ~]$ exitlogout给组配置额度[rootlocalhost ~]# setquota -g g01 15000 20000 15 20 /data/切换到u02测试[rootlocalhost ~]# su - u02[u02localhost ~]$ touch /data/{1..10}.txtsdb1: write failed, group file limit reached.touch: 无法创建/data/6.txt: 超出磁盘限额touch: 无法创建/data/7.txt: 超出磁盘限额touch: 无法创建/data/8.txt: 超出磁盘限额touch: 无法创建/data/9.txt: 超出磁盘限额touch: 无法创建/data/10.txt: 超出磁盘限额发现只创建了5个文件就不能再创建了。因为刚才对组进行了限制20个数量的硬限制而u01、u02都在g01组里面u01的15个文件已经存在了,所以u02只能创建五个了。[u02localhost ~]$ ls /data/10.mp3 12.mp3 14.mp3 1.mp3 2.mp3 3.mp3 4.mp3 5.mp3 6.mp3 8.mp3 aquota.group lostfound11.mp3 13.mp3 15.mp3 1.txt 2.txt 3.txt 4.txt 5.txt 7.mp3 9.mp3 aquota.user[u02localhost ~]$ exitlogout[rootlocalhost ~]#