linux class(new) 1 페이지

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


회원로그인

linux class(new)

디스크 Quota

페이지 정보

작성자 admin 작성일16-02-10 23:14 조회1,332회 댓글0건

본문

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

quota 를 사용하려면 quota 패키지가 설치되어 있어야 한다.
아래와 같이 패키지 관리툴 rpm으로 확인해본다.

/root# rpm -qa | grep quota
quota-3.17-23.el6.x86_64

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

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

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

1. 쿼터 설정을 제한할 파티션을 정한다.
/dev/sdc 를 주 파티션 하나를 전체 크기로 잡는다.
그리고 sdc1 을 포맷하고 마운트 한다음 테스트 할 계정을 만든다.

/root# mkfs.ext4 /dev/sdc1 > /dev/null
mke2fs 1.41.12 (17-May-2010)
/root#
/root# mkdir /bloghome
/root# mount /dev/sdc1 /bloghome
/root# useradd -d /bloghome/bluser1 bluser1
/root# useradd -d /bloghome/bluser2 bluser2
....
/root# useradd -d /bloghome/bluser5 bluser5

2. /etc/fstab 에 용량을 제한할 파티션을 등록하고 쿼터옵션을 설정한다.
/etc/fstab 파일 맨 끝에 다음 한줄을 추가한다.
/dev/sdc1 /bloghome ext4 defaults,usrquota,grpquota 1 2


3. sdc1 을 마운트 해제하고 quota 옵션으로 다시 마운트한다.
umont /bloghome --> mount -a 또는
sdc1 을 마운트 해제 하지 않은 상태로 다음과 같이 다시 마운트 할 수도 있다.

/root# mount -o remount /bloghome
/root# mount | grep bloghome
/dev/sdc1 on /bloghome type ext4 (rw,usrquota,grpquota)
/root#


usrquota 옵션과 grpquota 옵션이 적용된것을 확인할 수 있다.
이 옵션없이 마운트하게 되면 쿼터설정을 할수 없다.

4. quota db 파일 생성
* selinux 설정이 되어 있는 경우에는 quota db 파일을 생성하기전에
다음 명령을 먼저 실행해야 한다.
아래 명령은 selinux 사용 여부 확인

/root# setenforce
Enforcing 으로 출력되면 selinux 를 사용중이라는 의미이며, Enforcing mode 는 Selinux 정책을 위반할 경우
selinux 가 정책을 위반한 프로세스를 차단하고 audit 파일에 프로세스 기록을 남긴다.

아래는 selinux mode 가 enforcing 인 경우이다.

/root# quotacheck -ug /bloghome
quotacheck: Cannot create new quotafile /bloghome/aquota.user.new: 허가 거부
quotacheck: Cannot initialize IO on new quotafile: 허가 거부
quotacheck: Cannot create new quotafile /bloghome/aquota.group.new: 허가 거부
quotacheck: Cannot initialize IO on new quotafile: 허가 거부

selinux 설정 때문에 에러발생.
selinux 가 enable 상태이면 아래 명령어 실행후 quota db 파일을 생성해야 함.

/root# chcon --reference /var /bloghome

또는 보안상 권장되지는 않지만 selinux 를 잠시 Permsive 모드로 변경후
quotacheck 를 실행하면 된다.
selinux 를 Permissive 로 변경하려면
setenfor 0 또는 setenforce permissive

/root# quotacheck -ug /bloghome (u : 계정쿼터지원옵션, g: group 쿼터 지원옵션)
/root# ls -l *quota*
ls: cannot access *quota*: 그런 파일이나 디렉터리가 없습니다
/root# ls -l /bloghome/*quota*
-rw-------. 1 root root 7168 2016-02-10 21:54 /bloghome/aquota.group
-rw-------. 1 root root 7168 2016-02-10 21:54 /bloghome/aquota.user
/root#


5. 쿼터 활성화 ; 쿼터를 활성화 하지 않으면 쿼터가 적용되지 않는다.

/root# quotaon -v /bloghome(비활성화 시킬때는 quotaoff -v /qthome)
/dev/sdc1 [/bloghome]: group quotas turned on
/dev/sdc1 [/bloghome]: user quotas turned on


6. 사용자별 쿼터 설정 ; EDITOR 환경변수가 설정되어 있지 않으면 default 로 vi 편집기에서 설정해야 한다.

/root# echo $EDITOR
; 빈줄만 출력되었으므로 EDITOR 변수 설정 안되어 있음.
/root#
root# edquota -u bluser1
Disk quotas for user bluser1 (uid 533):
Filesystem blocks soft hard inodes soft hard
/dev/sdc1 36 0 0 9 0 0


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

Disk quotas for user bluser1 (uid 533):
Filesystem blocks soft hard inodes soft hard
/dev/sdc1 36 10000 15000 9 0 0

위에 보이는 쿼터 설정은 아래와 같다.
디스크 사용량 제한 : soft limit - 10 MB
hard limit - 15 MB (hard limit 는 soft limit 값 이상으로 설정한다)
저장할 수 있는 파일 갯수 제한 : soft limit - 0 ( 0은 설정안함을 의미, 즉 무제한)
hard limit - 0

/root# repquota -u /bloghome
*** 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 -- 20 0 0 2 0 0
bluser1 -- 36 10000 15000 9 0 0
bluser2 -- 36 0 0 9 0 0
bluser3 -- 36 0 0 9 0 0
bluser4 -- 36 0 0 9 0 0
bluser5 -- 36 0 0 9 0 0

/root#

아직 설정 되지 않은 계정들(bluser2 ~ bluser5)은 디스크 사용량이 무제한이다.

설정이 다 완료되었으면 아래처럼 쿼터 설정이 된 계정으로 바꿔서 테스트를 해서 확인한다.

/root# su - bluser1
[bluser1@vega ~]$ mkdir test
[bluser1@vega ~]$ cd test
[bluser1@vega test]$ pwd
/bloghome/bluser1/test
[bluser1@vega test]$ dd if=/dev/zero of=./testfile1 bs=1024k count=2
2+0 records in
2+0 records out
2097152 bytes (2.1 MB) copied, 0.111582 s, 18.8 MB/s
[bluser1@vega test]$ ls -lh testfile1
-rw-rw-r--. 1 bluser1 bluser1 2.0M 2016-02-10 22:52 testfile1
[bluser1@vega test]$ cp testfile1 testfile2
[bluser1@vega test]$ cp testfile1 testfile3
[bluser1@vega test]$ cp testfile1 testfile4
[bluser1@vega test]$ cp testfile1 testfile5
sdc1: warning, user block quota exceeded.
[bluser1@vega test]$ cp testfile1 testfile6
[bluser1@vega test]$ cp testfile1 testfile7
[bluser1@vega test]$ cp testfile1 testfile8
sdc1: write failed, user block limit reached.
cp: writing `testfile8': 디스크 할당량이 초과됨
[bluser1@vega test]$ ls -lh testfile*
-rw-rw-r--. 1 bluser1 bluser1 2.0M 2016-02-10 22:52 testfile1
-rw-rw-r--. 1 bluser1 bluser1 2.0M 2016-02-10 22:52 testfile2
-rw-rw-r--. 1 bluser1 bluser1 2.0M 2016-02-10 22:52 testfile3
-rw-rw-r--. 1 bluser1 bluser1 2.0M 2016-02-10 22:52 testfile4
-rw-rw-r--. 1 bluser1 bluser1 2.0M 2016-02-10 22:52 testfile5
-rw-rw-r--. 1 bluser1 bluser1 2.0M 2016-02-10 22:52 testfile6
-rw-rw-r--. 1 bluser1 bluser1 2.0M 2016-02-10 22:52 testfile7
-rw-rw-r--. 1 bluser1 bluser1 624K 2016-02-10 22:52 testfile8
[bluser1@vega test]$

마지막에 복사한 파일은 용량제한에 걸려서 제대로 복사되지 못했음을 알수 있다.
쿼터 보고서를 출력해서 확인 -->

/root# repquota /bloghome | grep bluser1
bluser1 +- 15000 10000 15000 6days 19 0 0

bluser1 은 빈파일(0 byte)외에는 파일을 저장할 수 없다.
6day 라고 표시된 부분은 soft limit 를 초과하는 용량에 대해서는 6일간 유효하며
6일이 경과하기전에 용량은 10MB 이하로 낮춰야 함을 의미한다

-- group quota 설정 --

/root# groupadd qtgroup
/root# useradd -g qtgroup -d /bloghome/bluser10 bluser10
/root# useradd -g qtgroup -d /bloghome/bluser11 bluser11
/root# useradd -G qtgroup -d /bloghome/bluser12 bluser12
/root# groups bluser10 bluser11 bluser12
bluser10 : qtgroup
bluser11 : qtgroup
bluser12 : bluser12 qtgroup
/root# edquota -g qtgroup
Disk quotas for group qtgroup (gid 539):
Filesystem blocks soft hard inodes soft hard
/dev/sdc1 72 30000 40000 18 0 0
~
~
:wq
/root#
/root# repquota -g /bloghome
*** 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 -- 20 0 0 2 0 0
bluser1 -- 15000 0 0 19 0 0
bluser2 -- 36 0 0 9 0 0
bluser3 -- 36 0 0 9 0 0
bluser4 -- 36 0 0 9 0 0
bluser5 -- 36 0 0 9 0 0
qtgroup -- 72 30000 40000 18 0 0
bluser12 -- 36 0 0 9 0 0
/root#

출력된것은 계정이 아니라 모두 group 명이다.
계정쿼터 및 그룹쿼터 설정까지 출력하려면


/root# repquota -ug /bloghome
*** 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 -- 20 0 0 2 0 0
bluser1 +- 15000 10000 15000 31:26 19 0 0
bluser2 -- 36 0 0 9 0 0
bluser3 -- 36 0 0 9 0 0
bluser4 -- 36 0 0 9 0 0
bluser5 -- 36 0 0 9 0 0
bluser10 -- 36 0 0 9 0 0
bluser11 -- 36 0 0 9 0 0
bluser12 -- 36 0 0 9 0 0


*** 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 -- 20 0 0 2 0 0
bluser1 -- 15000 0 0 19 0 0
bluser2 -- 36 0 0 9 0 0
bluser3 -- 36 0 0 9 0 0
bluser4 -- 36 0 0 9 0 0
bluser5 -- 36 0 0 9 0 0
qtgroup -- 72 30000 40000 18 0 0
bluser12 -- 36 0 0 9 0 0
/root#


이제 qtgroup 에 속해 있는 bluser10,bluser11,bluser12 는 쿼터설정이 적용된다.
세명의 계정이 합쳐서 최대 40메가까지 사용할 수 있다.(*주의 : 한계정당 40메가가 아님)

*. 쿼터 설정 제거
- 제거하려면 quota 를 비활성화 시킨다음에 제거해야 한다.

/root# rm /bloghome/aquota.user
rm: remove 일반 파일 `/bloghome/aquota.user'? y
rm: cannot remove `/bloghome/aquota.user': 명령을 허용하지 않음 - (쿼터가 활성화된 상태라서)
/root#
/root# quotaoff -v /bloghome
/dev/sdc1 [/bloghome]: group quotas turned off
/dev/sdc1 [/bloghome]: user quotas turned off
/root# rm /bloghome/*quota*

그다음 /etc/fstab 에서 usrquota,gropquota 옵션을 제거하고 remount 하면 됨.k

댓글목록

등록된 댓글이 없습니다.


접속자집계

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