본문 바로가기

Operating Systems/Linux

[ Linux ] Quota 활용

쿼터 (Quota)

파일시스템의 사용자나 그룹이 생성할 수 있는 파일의 용량 및 갯수를 제한

 

1. CentOS7

# quota 설치 확인
rpm -qa quota

# quota 설치
yum -y install quota

# root 시스템 quota 설정 확인 
mount | grep ' / '

# "noquota"는 기본 커널 설치 옵션이기 때문에, 커널 부팅 옵션에서 변경
sed -i "s/rhgb quiet/rhgb quiet rootflags=uquota,pquota/g" /etc/default/grub

# 커널 설정 파일을 백업
cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg.orig

# 커널 부팅 옵션 반영
grub2-mkconfig -o /boot/grub2/grub.cfg

# 설정파일 반영 확인
diff -c /boot/grub2/grub.cfg /boot/grub2/grub.cfg.orig

# 재부팅
reboot

# root 시스템 quota 설정 확인 ("noquota" 가 없어진 것 확인)
mount | grep ' / '

# r : 시스템 유저 생성(메일 디렉터리와 홈 디렉터리가 생성되지 않음)
useradd -r -u 1500 quser1

# 소유자가 quser1 인 파일 검색
find / -user quser1

# 현재 쿼터 설정 확인
quota -v quser1

Block grace period : soft 설정 되어있는 용량을 초과한 파일의 생성 유예기간 설정 
Inode grace period : soft 설정 되어있는 파일수 유예기간 설정
# edquota 로 실행할 경우 텍스트 에디터로 유예기간을 설정할 수 있음
# edquota -t 
# 용량 및 파일수 유예기간을 각각 30초로 설정
setquota -t 15 15 /

# 작업 폴더 생성
mkdir -p /app/tmp

chmod 777 /app/tmp

# quser1 의 용량 및 파일수 제한(용량의 단위는 kb)
# blocks, idodes 는 자동으로 설정됨(변경 x)
# soft 및 hard 를 설정할 수있음
# edquota 로 실행할 경우 텍스트 에디터로 제한설정할 수 있음
# edquota -u quser1
setquota -u quser1 0 0 0 5 /

# 쿼터 시작
quotaon -avug

# 접속 유저 변경 - quser1 
su - quser1

# 5개 이상에서 에러가나는 것 확인
touch /app/tmp/a
touch /app/tmp/b
touch /app/tmp/c
touch /app/tmp/d
touch /app/tmp/e
touch /app/tmp/f

rm -rf /app/tmp/*

exit

setquota -u quser1 0 0 5 10 /

su - quser1

# 8개 생성하고 30초 대기
touch /app/tmp/a
touch /app/tmp/b
touch /app/tmp/c
touch /app/tmp/d
touch /app/tmp/e
touch /app/tmp/f
touch /app/tmp/g
touch /app/tmp/h

# 15초 동안 대기
sleep 15

# 생성이 안되는 것 확인
touch /app/tmp/i

rm -rf /app/tmp/*

exit

setquota -u quser1 1000 2000 0 0 /

su - quser1

# 1984 byte 이상부터 파일이 생성되지 않는 것을 확인
# fallocate : 임시 파일을 생성하는 명령어
fallocate -l 1000k /app/tmp/file01
fallocate -l 984k /app/tmp/file02

# 더이상 생성되지 않는것을 확인
fallocate -l 1000k /app/tmp/file03

exit

# 현재 쿼터 설정 확인
repquota /

 

2. Ubuntu20

dpkg -l | grep quota

apt-get -y install lvm2

# root 시스템 quota 설정 확인 
mount | grep ' / '

TMP=$(cat /etc/fstab | grep -n -E "^UUID" | awk '$2 == "/"  { str=$1; for (i=2; i <= NF; i++) str=str"\t"((i==4)?$i",usrquota":$i); print str }' | sed 's/\//\\\//g')

sed -i "${TMP%%:*}s/.*/${TMP#*:}/g" /etc/fstab

mount -a

# 재부팅
reboot

# root 시스템 quota 설정 확인 ("usrquota" 생성 확인)
mount | grep ' / '

# r : 시스템 유저 생성(메일 디렉터리와 홈 디렉터리가 생성되지 않음)
useradd -r -u 1500 quser1

# 소유자가 quser1 인 파일 검색
find / -user quser1

# 루트 폴더 이동
cd /

# 쿼터 종료
quotaoff -avug 

# 쿼터 관련 설정 파일 삭제
rm -rf /aquota.*

# 쿼터 관련 체크 및 쿼터 DB 파일 생성
quotacheck -augmn

# 쿼터 DB 파일 생성 확인
ls -l /aquota.user

# 권한 변경
chmod 600 /aquota.*

# 쿼터 시작
quotaon -avug

# 기본 프로그램 실행 에디터 vi로 변경
export EDITOR=`which vi`

quota -v quser1

Block grace period : soft 설정 되어있는 용량을 초과한 파일의 생성 유예기간 설정 
Inode grace period : soft 설정 되어있는 파일수 유예기간 설정
# edquota 로 실행할 경우 텍스트 에디터로 유예기간을 설정할 수 있음
# edquota -t 
# 용량 및 파일수 유예기간을 각각 30초로 설정
setquota -t 15 15 /

# 작업 폴더 생성
mkdir -p /app/tmp

chmod 777 /app/tmp

# quser1 의 용량 및 파일수 제한(용량의 단위는 kb)
# blocks, idodes 는 자동으로 설정됨(변경 x)
# soft 및 hard 를 설정할 수있음
# edquota 로 실행할 경우 텍스트 에디터로 제한설정할 수 있음
# edquota -u quser1
setquota -u quser1 0 0 0 5 /

# 접속 유저 변경 - quser1 
su - quser1

# 5개 이상에서 에러가나는 것 확인
touch /app/tmp/a
touch /app/tmp/b
touch /app/tmp/c
touch /app/tmp/d
touch /app/tmp/e
touch /app/tmp/f

rm -rf /app/tmp/*

exit

setquota -u quser1 0 0 5 10 /

su - quser1

# 8개 생성하고 30초 대기
touch /app/tmp/a
touch /app/tmp/b
touch /app/tmp/c
touch /app/tmp/d
touch /app/tmp/e
touch /app/tmp/f
touch /app/tmp/g
touch /app/tmp/h

# 15초 동안 대기
sleep 15

# 생성이 안되는 것 확인
touch /app/tmp/i

rm -rf /app/tmp/*

exit

setquota -u quser1 1000 2000 0 0 /

su - quser1

# 1984 byte 이상부터 파일이 생성되지 않는 것을 확인
# fallocate : 임시 파일을 생성하는 명령어
fallocate -l 1000k /app/tmp/file01
fallocate -l 984k /app/tmp/file02

# 더이상 생성되지 않는것을 확인
fallocate -l 1000k /app/tmp/file03

exit

# 현재 쿼터 설정 확인
repquota /

'Operating Systems > Linux' 카테고리의 다른 글

[ Linux ] FTP 서버 설치  (0) 2021.10.15
[ Linux ] TFTP 서버 설치  (0) 2021.10.15
[ Linux ] LVM 활용  (0) 2021.10.01
[ Linux ] ORACLE 19c 서버 설치  (0) 2021.09.30
[ Linux ] GIT 서버 설치  (0) 2021.09.26