Linux 使用者 Quota 配置 說明

來源:互聯網
上載者:User

一. Linux 配額(Quota)說明
 

在 Linux 系統中,由於是多人多任務的環境,所以會有多人共同使用一個硬碟空間的情況發生,為了合理使用這些空間,管理員需要控制使用者對磁碟空間的使用,這個就是Linux 下的配額管理。

推薦閱讀:

  • Linux學習筆記:磁碟配額(Quota)與進階檔案系統管理
  • RHCE培訓筆記——磁碟配額
  • Linux下磁碟配額(quota)應用與實戰教程
  • RHEL5.5中建立softRaid10並使用quota限制磁碟配額
  • VMware下RedHat 5.4磁碟配額(Quota)

配額管理是對某個磁碟分割進行限制。這裡的限制包括2個方面:

1.單個使用者對某個目錄下空間大小的限制。

2.單個使用者對某個目錄下檔案個數的限制。

 

1.1 Quota 常用在如下幾種情況
1)  針對 WWW server ,例如:每個人的網頁空間的容量限制。

2)  針對 mail server,例如:每個人的郵件空間限制。

3)  針對 file server,例如:每個人最大的可用網路硬碟空間。

 

1.2 Quota 的2個注意事項
(1)僅針對整個 partition:

quota針對『整個 partition』進行限制, 例如:如果/dev/hda5 是掛載在 /dave 目錄下,那麼在 /dave 目錄下的所有目錄都會受到限制。

 

(2)只對一般身份使用者有效:

不是所有在 Linux 上面的帳號都可以設定 quota,例如 root 就不能設定quota 。

 

 

1.3 Quota 的三種限制類型
(1)soft limit:

這是最低限制容量的意思,使用者在寬限期間之內,他的容量可以超過 soft ,但必需要寬限時間之內將磁碟容量降低到 soft 的容量限制之下。

 

(2)hard limit:

這是『絕對不能超過』的容量。通常hard limit 會比 soft limit 為高,例如網路磁碟機空間為 30 MB ,那麼 hard limit 就設定為 30MB ,但是為了讓使用者有一定的警戒心,所以當使用空間超過 25 MB 時,例如使用者使用了 27 MB 的空間時,那麼系統就會警告使用者, 讓使用者可以在『寬限時間內』將他的檔案量降低至 25 MB ( 亦即是 soft limit )之內。也就是說, soft 到 hard 之間的容量其實就是寬限的容量,可以達到針對使用者的『警示』作用。

 

(3)寬限時間:

寬限時間就是當使用者使用的空間超過了 soft limit ,卻還沒有到達 hard limit 時,那麼在這個『寬限時間』之內,就必需要請使用者將使用的磁碟容量降低到 soft limit 之下。而當使用者將磁碟容量使用方式超過 soft limit 時,『寬限時間』就會自動被啟動,而在使用者將容量降低到 softlimit 之下,那麼寬限時間就會自動的取消。

 

1.4 Quota 的安裝包
    Quota也需要安裝,安裝包如下:

 

[root@rhce /]# rpm -q quota

quota-3.17-16.el6.x86_64

[root@rhce /]#

 

1.5 Quota 相關的命令
 

與Quota 相關的幾個命令如下。

 

1.5.1 啟用quota:quotaon
[root@rhce /]# quotaon

Bad number of arguments.

quotaon: Usage:

      quotaon [-guvp] [-F quotaformat] [-x state] -a

      quotaon [-guvp] [-F quotaformat] [-x state] filesys ...

 

-a, --all                turn quotas on for all filesystems

-f, --off                turn quotas off

-u, --user              operate on user quotas

-g, --group              operate on group quotas

-p, --print-state        print whether quotas are on or off

-x, --xfs-command=cmd    perform XFS quota command

-F, --format=formatname  operate on specific quota format

-v, --verbose            print more messages

-h, --help              display this help text and exit

-V, --version            display version information andexit

[root@rhce /]#

 

 

1.5.2 關閉quota:quotaoff
[root@rhce /]# quotaoff

Bad number of arguments.

quotaoff: Usage:

      quotaoff [-guvp] [-F quotaformat] [-x state] -a

      quotaoff [-guvp] [-F quotaformat] [-x state] filesys ...

 

-a, --all                turn quotas off for allfilesystems

-f, --off                turn quotas off

-u, --user              operate on user quotas

-g, --group              operate on group quotas

-p, --print-state        print whether quotas are on or off

-x, --xfs-command=cmd    perform XFS quota command

-F, --format=formatname  operate on specific quota format

-v, --verbose            print more messages

-h, --help              display this help text and exit

-V, --version            display version information andexit

 

1.5.3 配額發送警告:warnquota
[root@rhce /]# warnquota -h

warnquota: Usage:

 warnquota [-ugsid] [-F quotaformat] [-c configfile] [-q quotatabfile][-a adminsfile]

 

-u, --user                      warn users

-g, --group                    warn groups

-s, --human-readable            send information in more humanfriendly units

-i, --no-autofs                avoid autofs mountpoints

-d, --no-details                do not send quota informationitself

-F, --format=formatname        use quotafiles of specific format

-c, --config=config-file        non-default config file

-q, --quota-tab=quotatab-file  non-default quotatab

-a, --admins-file=admins-file  non-default admins file

-h, --help                      display this help messageand exit

-v, --version                  display version informationand exit

 

Bugs to jack@SUSE.cz

[root@rhce /]#

 

1.5.4 編輯配額屬性:edquota
[root@rhce /]# edquota

edquota: Usage:

      edquota [-rm] [-u] [-F formatname] [-p username] [-f filesystem]username ...

        edquota [-rm] -g [-F formatname] [-pgroupname] [-f filesystem] groupname ...

      edquota [-rm] [-u|g] [-F formatname] [-f filesystem] -t

      edquota [-rm] [-u|g] [-F formatname] [-f filesystem] -Tusername|groupname ...

 

-u, --user                    edit user data

-g, --group                  edit group data

-r, --remote                  edit remote quota (via RPC)

-m, --no-mixed-pathnames      trim leading slashes from NFSv4mountpoints

-F, --format=formatname      edit quotas of a specific format

-p, --prototype=name          copy data from a prototype user/group

  --always-resolve          alwaystry to resolve name, even if it is

                              composed only ofdigits

-f, --filesystem=filesystem  edit data only on a specific filesystem

-t, --edit-period            edit grace period

-T, --edit-times              edit grace time of a user/group

-h, --help                    display this help text andexit

-V, --version                display version informationand exit

 

Bugs to: jack@suse.cz

[root@rhce /]#

 

1.5.5 顯示配額資訊:repquota
[root@rhce /]# repquota -h

repquota: Utility for reporting quotas.

Usage:

repquota [-vugsi] [-c|C] [-t|n] [-Fquotaformat] (-a | mntpoint)

 

-v, --verbose              display also users/groups withoutany usage

-u, --user                  display information aboutusers

-g, --group                display information aboutgroups

-s, --human-readable        show numbers in human friendly units(MB, GB, ...)

-t, --truncate-names        truncate names to 8 characters

-p, --raw-grace            print grace time in seconds sinceepoch

-n, --no-names              do not translate uid/gid to name

-i, --no-autofs            avoid autofs mountpoints

-c, --batch-translation    translate big number of ids at once

-C, --no-batch-translation  translate ids one by one

-F, --format=formatname    report information for specific format

-h, --help                  display this help message andexit

-V, --version              display version information andexit

 

Bugs to jack@suse.cz

[root@rhce /]#

 

1.5.6 檢查並修複quota 設定檔:quotacheck
#quotacheck –cvug/tmp

 

[root@rhce ~]# quotacheck -h

Utility for checking and repairing quotafiles.

quotacheck [-gucbfinvdmMR] [-F<quota-format>] filesystem|-a

 

-u, --user                check user files

-g, --group              check group files

-c, --create-files        create new quota files

-b, --backup              create backups of old quota files

-f, --force              force check even if quotas areenabled

-i, --interactive        interactive mode

-n, --use-first-dquot    use the first copy of duplicated structure

-v, --verbose            print more information

-d, --debug              print even more messages

-m, --no-remount          do not remount filesystem read-only

-M, --try-remount        try remounting filesystem read-only,

                          continue even if itfails

-R, --exclude-root        exclude root when checking allfilesystems

-F, --format=formatname  check quota files of specific format

-a, --all                check all filesystems

-h, --help                display this message and exit

-V, --version            display version information andexit

 

Bugs to jack@suse.cz

[root@rhce ~]#

 

[root@rhce ~]#  quotacheck -cvug /dave

quotacheck: Your kernel probably supportsjournaled quota but you are not using it. Consider switching to journaled quotato avoid running quotacheck after an unclean shutdown.

quotacheck: Scanning /dev/sdc1 [/dave] done

quotacheck: Cannot stat old user quotafile: No such file or directory

quotacheck: Cannot stat old group quotafile: No such file or directory

quotacheck: Cannot stat old user quotafile: No such file or directory

quotacheck: Cannot stat old group quota file:No such file or directory

quotacheck: Checked 3 directories and 2files

quotacheck: Old file not found.

 

1.5.7 直接設定配額:setquota
[root@rhce ~]# setquota -h

setquota: Usage:

 setquota [-u|-g] [-rm] [-F quotaformat] <user|group>

      <block-softlimit> <block-hardlimit> <inode-softlimit><inode-hardlimit> -a|<filesystem>...

 setquota [-u|-g] [-rm] [-F quotaformat] <-p protouser|protogroup><user|group> -a|<filesystem>...

 setquota [-u|-g] [-rm] [-F quotaformat] -b [-c] -a|<filesystem>...

 setquota [-u|-g] [-F quotaformat] -t <blockgrace><inodegrace> -a|<filesystem>...

 setquota [-u|-g] [-F quotaformat] <user|group> -T<blockgrace> <inodegrace> -a|<filesystem>...

 

-u, --user                set limits for user

-g, --group                set limits for group

-a, --all                  set limits for allfilesystems

  --always-resolve      always tryto resolve name, even if is

                          composed only ofdigits

-F, --format=formatname    operate on specific quota format

-p, --prototype=protoname  copy limits from user/group

-b, --batch                read limits from standard input

-c, --continue-batch      continue in input processing in case ofan error

-r, --remote              set remote quota (via RPC)

-m, --no-mixed-pathnames      trim leading slashes from NFSv4mountpoints

-t, --edit-period          edit grace period

-T, --edit-times          edit grace times for user/group

-h, --help                display this help text andexit

-V, --version              display version information andexit

 

Bugs to: jack@suse.cz

[root@rhce ~]#

接下來請看第2頁精彩內容:

  • 1
  • 2
  • 3
  • 4
  • 下一頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.