国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Linux > 正文

Linux下使用quota命令管理磁盤空間的實例教程

2020-07-10 11:08:47
字體:
來源:轉載
供稿:網友

1.通過yum 方式 安裝quota

復制代碼
代碼如下:

#yum install quota

2.VirtualBox創建硬盤
如果你的Linux環境建立在VirtualBox下:
(1)關閉虛擬機鏡像
點擊setting 配置虛擬機所使用的硬件
2016412111217295.png (773×610)

(2)配置新硬盤
2016412111248895.png (660×467)

選擇Create new disk
2016412111306236.png (650×479)

選擇VHD (virtual hard disk)
2016412111427931.png (667×432)

輸入硬盤鏡像名字
2016412111446505.png (668×449)

(3)格式化硬盤
進入linux,使用命令創建硬盤進行格式化

復制代碼
代碼如下:

#mkfs -t ext4 /dev/sdb

(4)為硬盤空間尋找目錄

復制代碼
代碼如下:

#mount /dev/sdb /home

如果有需要長期掛著,請自行百度如何修改/etc/fstab,本人修改多次,讓系統多次崩潰,最終放棄,選擇在 vi /etc/rc.local 里面,業余的加入 mount /dev/sdb /home 這條命令。

3.格式化新創建的硬盤

復制代碼
代碼如下:

[root@localhost ~]# mkfs -t ext4 /dev/sdb


復制代碼
代碼如下:

mke2fs 1.41.12 (12-Apr-2016)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
524288 inodes, 2097152 blocks
104857 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2147483648
64 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

Writing inode tables: done                           
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

掛在硬盤到/home目錄

復制代碼
代碼如下:

[root@localhost ~]# mount /dev/sdb /home/
[root@localhost ~]# mount -o remount,usrquota,grpquota /home
[root@localhost ~]# 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,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/sdb on /home type ext4 (rw,usrquota,grpquota)

為系統設置啟動后自動掛載硬盤

復制代碼
代碼如下:

[root@localhost ~]#vi /etc/rc.local

添加

復制代碼
代碼如下:

mount /dev/sdb /home
mount -o remount,usrquota,grpquota /home

備注:本人并沒有采取修改/etc/fstab 的方法,因為該方法容易因為輸入的字符或格式不對導致系統崩潰,所以采取了修改用戶啟動文件的方法

4.配置quota

復制代碼
代碼如下:

[root@localhost ~]#quotacheck -avug 對整個系統含有 usrquota, grpquota 參數的文件系統進行 quotacheck 掃描

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/sdb [/home] done
quotacheck: Cannot stat old user quota file: No such file or directory
quotacheck: Cannot stat old group quota file: No such file or directory
quotacheck: Cannot stat old user quota file: No such file or directory
quotacheck: Cannot stat old group quota file: No such file or directory
quotacheck: Checked 2 directories and 0 files
quotacheck: Cannot create new quotafile /home/aquota.user.new: Permission denied
quotacheck: Cannot initialize IO on new quotafile: Permission denied
quotacheck: Cannot create new quotafile /home/aquota.group.new: Permission denied
quotacheck: Cannot initialize IO on new quotafile: Permission denied
出現報錯,報錯原因是因為沒有關閉selinux

復制代碼
代碼如下:

[root@localhost ~]# setenforce 0
[root@localhost ~]# quotacheck -avug

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/sdb [/home] done
quotacheck: Cannot stat old user quota file: No such file or directory
quotacheck: Cannot stat old group quota file: No such file or directory
quotacheck: Cannot stat old user quota file: No such file or directory
quotacheck: Cannot stat old group quota file: No such file or directory
quotacheck: Checked 2 directories and 0 files
quotacheck: Old file not found.
quotacheck: Old file not found.
成功生成

復制代碼
代碼如下:

[root@localhost ~]#quotaon -auvg 啟動quota

5.為用戶添加硬盤空間限制
創建賬戶

復制代碼
代碼如下:

[root@localhost ~]# useradd quotauser1
[root@localhost ~]# passwd quotauser1


復制代碼
代碼如下:

[root@localhost ~]# edquota -u quotauser1

Disk quotas for user quotauser1 (uid 500):
  Filesystem                   blocks       soft       hard     inodes     soft     hard
  /dev/sdb                         16     500000     600000          4        0        0

限制用戶quotauser1的使用空間為500M,最大限制是600M
參數意義參考
  soft :這是最低限制容量的意思,使用者在寬限期間之內,他的容量可以超過 soft ,但必需要寬限時間之內將磁盤容量降低到 soft 的容量限制之下!
  hard :這是『絕對不能超過』的容量!跟 soft 相比的意思為何呢?通常 hard limit 會比 soft limit 為高,例如網絡磁盤空間為 30 MB ,那么 hard limit 就設定為 30MB ,但是為了讓使用者有一定的警戒心,所以當使用空間超過 25 MB 時,例如使用者使用了 27 MB 的空間時,那么系統就會警告使用者,讓使用者可以在『寬限時間內』將他的檔案量降低至 25 MB ( 亦即是 soft limit )之內!也就是說, soft 到 hard 之間的容量其實就是寬限的容量啦!可以達到針對使用者的『警示』作用!
  寬限時間:那么寬限時間就可以很清楚的知道含意是什么了!也就是當您的使用者使用的空間超過了 soft limit ,卻還沒有到達 hard limit 時,那么在這個『寬限時間』之內,就必需要請使用者將使用的磁盤容量降低到 soft limit 之下!而當使用者將磁盤容量使用情況超過 soft limit 時,『寬限時間』就會自動被啟動,而在使用者將容量降低到 soft limit 之下,那么寬限時間就會自動的取消

主站蜘蛛池模板: 内黄县| 邻水| 丽水市| 磐安县| 新蔡县| 武城县| 沛县| 长丰县| 苗栗县| 瓦房店市| 青州市| 秭归县| 滕州市| 安新县| 顺义区| 古蔺县| 林州市| 文安县| 济南市| 淮南市| 姚安县| 东光县| 呼伦贝尔市| 吐鲁番市| 怀宁县| 大埔县| 武穴市| 攀枝花市| 青龙| 青铜峡市| 大同县| 防城港市| 中方县| 嵊泗县| 禄劝| 福海县| 永城市| 五峰| 乌恰县| 睢宁县| 体育|