linux class 1 페이지

본문 바로가기
사이트 내 전체검색


회원로그인

linux class

디스크 쿼터(Quota)

페이지 정보

작성자 admin 작성일15-12-23 15:16 조회131회 댓글0건

본문

quota - 사용자 또는 그룹이 가질 수 있는 파일 갯수나 디스크 사용량을 제한하는것이다.
특정 사용자가 디스크 공간을 무제한 사용하는 것을 방지한다.

먼저 quota 를 사용하려면 quota 패키지가 설치되어 있어야 한다.
아래와 같이 rpm으로 확인해본다.
[qtuser1@star ~]$ rpm -qa | grep quota
quota-3.12-6 <= 설치되어 있다.

그리고 커널에서도 quota를 지원해야 한다. 커널이 지원하지 않는다면
quota 명령 실행시 kernel not supported 라는 에러 메시지가 출력될것이다.
그런 경우 커널을 quota 를 지원하도록 새로 컴파일 해야 한다.
(대부분의 커널에서 quota를 지원하도록 되어 있으므로 신경 안써도 될듯)

Quata 설정 방법(아래와 같은 순서로 한다)
1. 용량을 제한할 파티션을 정한다.
2. /etc/fstab 에 용량을 제한할 파티션을 등록하고 쿼터옵션을 설정한다.
3. 리부팅하거나 /etc/fstab 를 다시 읽을수 있게 'remount' 옵션으로 다시 마운트한다.
4.쿼터 db file을 만든다.
5. 쿼터를 활성화 시킨다.
6. 사용자별 쿼터 설정을 한다.

참고예제)
/dev/sdc1 을 디스크 사용량을 제한할 파티션으로 정하고
마운트포인터는 /qthome 으로 한다.
그리고 /qthome에 있는 사용자들중 qtuser1 계정에 쿼터 설정을 한다.

1. 쿼터 설정을 제한할 파티션을 정한다.
[root@star test_vg]# mkdir /qthome
[root@star test_vg]# mount -t ext3 /dev/sdc1 /qthome

2. /etc/fstab 에 용량을 제한할 파티션을 등록하고 쿼터옵션을 설정한다.
테스트를 위해 qtuser1 계정이 없다면 생성한다.
[root@star test_vg]# useradd -d /qthome/qtuser1 qtuser1

/etc/fstab 파일에 /dev/sdc1 장치에 아래출력결과처럼 usrquota 옵션을 추가한다.

[root@star ~]# grep sdc1 /etc/fstab
/dev/sdc1 /qthome ext3 defaults,usrquota 1 2
[root@star ~]#

3.리부팅하거나 /etc/fstab 를 다시 읽을수 있게 'remount' 옵션으로 다시 마운트한다.
[root@star ~]# mount -o remount /qthome

[root@star ~]# mount | grep qthome
/dev/sdc1 on /qthome type ext3 (rw,usrquota)
[root@star ~]#
usrquota 옵션이 적용된것을 확인할 수 있다. 이 옵션이 적용되지 않으면
쿼터 설정을 할 수 없다.

4. quota db 파일 생성
[root@star ~]# touch aquota.user ; quota.user 파일 생성
(quota 를 적용할 계정 설정을 위한 파일.
그룹에도 quota 를 적용하려면 aquota.user 파일도 생성하면 된다.)

*. quota version 1 에서는 quota.user, quota,group 이다
version1 형식을 버전2 형식(커널 2.6.x 에서 지원)으로 변환하는 경우에는
convertquota 명령을 사용하면 된다.
(ex. convertquota /qthome)

[root@star qthome]# quotacheck -v /qthome =>( quotacheck 명령은 quota 가 비활성화 되어 있는 상태에서 하는것이 안전하다. 만약 활성화 되어 있다면 quotaoff -v /qthome 하고 나서 실행)
(* quotacheck -a 옵션을 사용한다면 target 을 지정하는대신 /etc/fstab 에 usrquota 옵션이 설정되어 있는 파티션에 다 적용하겠다는 의미)

quotacheck: WARNING - Quotafile /qthome/aquota.user was probably truncated. Can't save quota settings...
quotacheck: Scanning /dev/sdc1 [/qthome] quotacheck: Old group file not found. Usage will not be substracted.
done
quotacheck: Checked 5 directories and 11 files
[root@star qthome]#

(*. 출력된 경고 메시지나 Old group file 이 없다는것은 무시하기 바람.)

5. 쿼터 활성화
quotaon -v /qthome 또는 리부팅.( 비활성화 시킬때는 quotaoff -v /qthome)

6. 사용자별 쿼터 설정

edquota -u qtuser1 => 쿼터 설정을 위한 vi 편집기가 실행된다.

Disk quotas for user qtuser1 (uid 506):
Filesystem blocks soft hard inodes soft hard
/dev/sdc1 5 0 0 5 0 0

===> 테스트를 위해 이것을 아래처럼 변경후 확인해본다.

Filesystem blocks soft hard inodes soft hard
/dev/sdc1 5 2000 3000 5 20 30


[root@star ~]# repquota /qthome
*** Report for user quotas on device /dev/sdc1
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 5664 0 0 4 0 0
qtuser1 -+ 6 2000 3000 40 30 40 6days
qtuser2 -- 5 0 0 5 0 0
qtuser5 -- 5 0 0 5 0 0

[root@star qthome]# edquota -u qtuser1

Disk quotas for user qtuser1 (uid 506):
Filesystem blocks soft hard inodes soft hard
/dev/sdc1 5 0 0 5 0 0


[root@star qthome]# ls
lost+found/ qtuser1/ qtuser2/ quota.user
[root@star qthome]#
[root@star qthome]# touch quota.user
[root@star qthome]# chmod 600 quota.user


[root@star qthome]# quotacheck -v /qthome
(* quotacheck -a 옵션을 사용한다면 target 을 지정하는대신 /etc/fstab 에 usr.quota 옵션이 설정되어 있는
파티션에 다 적용하겠다는 의미)

quotacheck: WARNING - Quotafile /qthome/aquota.user was probably truncated. Can't save quota settings...
quotacheck: Scanning /dev/sdc1 [/qthome] quotacheck: Old group file not found. Usage will not be substracted.
done
quotacheck: Checked 5 directories and 11 files
[root@star qthome]#

* quotacheck
- 타겟으로 지정된 파일시스템의 쿼터를 검사하고 aquota.user 와 aquota.group 파일에 필요한 설정을 저장한다.
그리고 손상된 쿼터 파일이 있다면 복구한다.

아래의 repquota 명령의 출력결과는 qtuser1 계정이 파일을 몇개 생성한후의 결과이다.
* repquota 명령어는 quota report 를 작성해서 보여준다.
[root@star qthome]# repquota /qthome
*** Report for user quotas on device /dev/sdc1
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 5664 0 0 4 0 0
qtuser1 -- 6 2000 3000 11 30 40 6days
qtuser2 -- 5 0 0 5 0 0


* 출력결과중
used 는 사용중인 디스크 용량 및 inode 갯수(생성할 수 있는 파일수로 보면 된다)
soft 는 soft limit 로서 grace time 동안에는 soft limt 값에 도달하더라도 파일이 생성된다.
그러나 grace (유예기간) 이 되면 더 이상 파일이 만들어 지지 않는다.

hard limit 는 grace time과 관계없다. hard limit 에 도달하면 파일은 생성되지 않는다.
quota 설정으로 제한 할 수 있는 것은 디스크 사용량 및 파일 생성 갯수이다.



[qtuser1@star test]$ touch 6 7 8 9 10 11 12 13 14 15 16 17 18 19 21 22 23 24 25 26 27
sdc1: warning, user file quota exceeded. => soft 값 초과에 따른 에러
[qtuser1@star test]$

[qtuser1@star test]$ touch 28 29 30 31 => hard limit 에는 도달하지 않았으므로 파일은 생성된다.

그러나 grace time을 초과하게 되면...
[qtuser1@star ~]$ touch aa
sdc1: write failed, user file quota exceeded too long.
touch: cannot touch `aa': 디스크 할당량이 초과됨


[qtuser1@star test]$ touch 32 33 34 35
sdc1: write failed, user file limit reached. => hard limit 에 도달하게 되면 파일은 생성되지 않는다.
touch: cannot touch `35': 디스크 할당량이 초과됨
[qtuser1@star test]$


*. 쿼터 설정 제거

제거하려면 quota 를 비활성화 시킨다음에 제거해야 한다.

rm: cannot remove `aquota.user': Operation not permitted => 쿼터가 활성화 되어 있어서 안됨.
[root@star qthome]# ls -l
[root@star qthome]# quotaoff -v /qthome
/dev/sdc1 [/qthome]: user quotas turned off
[root@star qthome]# rm aquota.user
rm: remove regular file `aquota.user'? y
[root@star qthome]#

그다음 /etc/fstab 에서 usr.quota 옵션을 제거한다음 reboot 또는 remount 하면 끝.

======================================================
그룹쿼터 설정 및 test

/etc/fstab 파일에서 아래처럼 해당 파티션에 grpquota 옵션을 추가한다.
[root@star qthome]# tail -1 /etc/fstab
/dev/sdc1 /qthome ext3 defaults,usrquota,grpquota 1 1
그런다음
[root@star qthome]# mount -o remount /qthome

[root@star qthome]# touch aquota.group
[root@star qthome]# quotacheck -v /qthome
quotacheck: Scanning /dev/sdc1 [/qthome] done
quotacheck: Checked 7 directories and 47 files

(*. 주의 - quotacheck 명령을 사용하기전에 쿼터는 비활성화 되어 있어야한다.
그렇지 않으면 쿼터로 지정된 파일시스템에 손상을 입힐 수 있다.)
아래는 메뉴얼 페이지에 있는 내용
It is strongly recommended to run quotacheck with quotas turned off for the filesystem. Otherwise, possible damage or loss to data in
the quota files can result.
그래서 쿼터가 활성화 되어 있는 상태이라면 quotaoff -v /qthome. 그리고 quotacheck 가
끝나면 quotaon 으로 다시 활성화 시켜주면 된다)


[root@star qthome]# quotacheck -ugv /qthome => 여기서 g 옵션은 생략하면 안된다.
quotacheck: WARNING - Quotafile /qthome/aquota.group was probably truncated. Can't save quota settings...
quotacheck: Scanning /dev/sdc1 [/qthome] done
quotacheck: Checked 9 directories and 55 files
[root@star qthome]# quotaon -v /qthome
/dev/sdc1 [/qthome]: group quotas turned on
/dev/sdc1 [/qthome]: user quotas turned on

*. quotacheck 옵션
-v verbose의 의미 체크중 옵션 사용하지 않았을때보다 자세한 내용 출력
-u 특정 uid가 사용하는 파일과 디렉토리를 카운트하게한다 (디폴트 옵션)
-g 특정 gid가 사용하는 파일과 디렉토리를 카운트하게한다
-a /etc/fstab 파일에 usrquota,grpquota 옵션이 포함된 파일 시스템을 모두 체크한다
(타겟을 지정하지 않고 모두 체크할때 이 옵션 사용)


edquota -g qtgroup

Disk quotas for group qtgroup (gid 509):
Filesystem blocks soft hard inodes soft hard
/dev/sdc1 0 3000 4000 0 0 0
~
==> 테스트를 위해 3000 과 4000 으로 지정하였다

[root@star qthome]# repquota -g -v /qthome
*** Report for group quotas on device /dev/sdc1
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
Group used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 5664 0 0 4 0 0
qtuser1 -- 8 0 0 37 0 0
qtuser2 -- 5 0 0 5 0 0
qtuser5 -- 5 0 0 5 0 0
qtgroup -- 1 3000 4000 6days 1 0 0
qtuser10 -- 6313 0 0 13 0 0
qtuser11 -- 5 0 0 5 0 0
qtuser12 -- 5 0 0 5 0 0

==> 왼쪽에 출력된것은 계정명이 아니라 그룹명이다.
==> 계정과 그룹 쿼터 정보를 다 출력해 보려면 repquota -ugv /qthome 으로 실행하면 된다.

[root@star qthome]#

[root@star qthome]# usermod -G qtgroup qtuser10 =>
qtuser10 사용자는 그룹쿼터 적용을 받지 못한다.
(위에 repquota 의 출력결과를 보면 qtuser11 그룹에 속한 사용자는 쿼터 설정이 되어 있지 않다.
즉, 그룹 쿼터 설정을 적용받으려면 primary group 만 영향을 미친다)

[root@star qthome]# usermod -g qtgroup qtuser11 =>
qtuser11 사용자는 그룹쿼터 적용을 받는다.

설정이 다 되었으므로 테스트 해보면
[root@star qthome]# su - qtuser11
[qtuser11@star ~]$ cp /bin/ksh 1
[qtuser11@star ~]$ cp /bin/ksh 2
[qtuser11@star ~]$ cp /bin/ksh 3
[qtuser11@star ~]$ cp /bin/ksh 5
sdc1: warning, group block quota exceeded. <= 쿼터가 적용되고 있음을 알 수 있다.
[qtuser11@star ~]$

댓글목록

등록된 댓글이 없습니다.


접속자집계

오늘
137
어제
75
최대
611
전체
448,187
개인정보취급방침 서비스이용약관 twoseven.kr All rights reserved.
상단으로