yumyum
[Linux] QUOTA 본문
QUOTA : 사용자별 공간할당
- 파일 시스템마다 사용자나 그룹이 생성할 수 있는 파일의 용량 및 개수를 제한하는 것
- 파일시스템을 "/"(root)로 지정하는 것보다는, 별도의 파일 시스템을 지정해서 해당부분을 쓰도록 하는 것이 좋음
- "/" 파일시스템을 많은 사용자가 동시에 사용하게 되면, CentOS 서버를 운영하기 위해서 디스크를 읽고 쓰는 작업과 일반 사용자가 디스크를 읽고 쓰는 작업이 동시에 발생하므로 전반적으로 시스템의 성능이 저하됨
______________________________________________________________________
실습
[centos@localhost ~]$ su -
암호:
마지막 로그인: 화 8월 29 13:56:30 KST 2023 일시 pts/0
[root@localhost ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xe83de979.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-104857599, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599):
Using default value 104857599
Partition 1 of type Linux and of size 50 GiB is set
Command (m for help): p
Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xe83de979
Device Boot Start End Blocks Id System
/dev/sdb1 2048 104857599 52427776 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# mkfs -t ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
3276800 inodes, 13106944 blocks
655347 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2162163712
400 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, 2654208,
4096000, 7962624, 11239424
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[root@localhost ~]# mkdir /quota
[root@localhost ~]# vim /etc/fstab
[root@localhost ~]# mount -a
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 480808 0 480808 0% /dev
tmpfs 497836 0 497836 0% /dev/shm
tmpfs 497836 8576 489260 2% /run
tmpfs 497836 0 497836 0% /sys/fs/cgroup
/dev/mapper/centos-root 17811456 5566256 12245200 32% /
/dev/sda1 1038336 176880 861456 18% /boot
tmpfs 99568 20 99548 1% /run/user/1000
/dev/sr0 4600876 4600876 0 100% /run/media/centos/CentOS 7 x86_64
/dev/sdb1 51473888 53272 48782844 1% /quota
[root@localhost ~]# useradd -d /quota/jhon jhon
[root@localhost ~]# useradd -d /quota/ben ben
[root@localhost ~]# cd /quota/
[root@localhost quota]# ls
ben jhon lost+found
[root@localhost quota]# cd
[root@localhost ~]# passwd john
passwd: 알 수 없는 사용자 이름 'john'.
[root@localhost ~]# passwd john
passwd: 알 수 없는 사용자 이름 'john'.
[root@localhost ~]# jhon
bash: jhon: 명령을 찾을 수 없습니다...
[root@localhost ~]# passwd jhon
jhon 사용자의 비밀 번호 변경 중
새 암호:
잘못된 암호: 암호는 8 개의 문자 보다 짧습니다
새 암호 재입력:
passwd: 모든 인증 토큰이 성공적으로 업데이트 되었습니다.
[root@localhost ~]# passwd ben
ben 사용자의 비밀 번호 변경 중
새 암호:
잘못된 암호: 암호는 8 개의 문자 보다 짧습니다
새 암호 재입력:
passwd: 모든 인증 토큰이 성공적으로 업데이트 되었습니다.
[root@localhost ~]# vim /etc/fstab
[root@localhost ~]# useradd -d /quota/jhon jhon
[root@localhost ~]# useradd -d /quota/ben ben
[root@localhost ~]# cd /quota/
[root@localhost quota]# ls
ben jhon lost+found
[root@localhost quota]# cd
[root@localhost ~]# passwd john
passwd: 알 수 없는 사용자 이름 'john'.
[root@localhost ~]# passwd john
passwd: 알 수 없는 사용자 이름 'john'.
[root@localhost ~]# jhon
bash: jhon: 명령을 찾을 수 없습니다...
[root@localhost ~]# passwd jhon
jhon 사용자의 비밀 번호 변경 중
새 암호:
잘못된 암호: 암호는 8 개의 문자 보다 짧습니다
새 암호 재입력:
passwd: 모든 인증 토큰이 성공적으로 업데이트 되었습니다.
[root@localhost ~]# passwd ben
ben 사용자의 비밀 번호 변경 중
새 암호:
잘못된 암호: 암호는 8 개의 문자 보다 짧습니다
새 암호 재입력:
passwd: 모든 인증 토큰이 성공적으로 업데이트 되었습니다.
[root@localhost ~]# vim /etc/fstab
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# mount -o remount /quota/
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 480808 0 480808 0% /dev
tmpfs 497836 0 497836 0% /dev/shm
tmpfs 497836 8572 489264 2% /run
tmpfs 497836 0 497836 0% /sys/fs/cgroup
/dev/mapper/centos-root 17811456 5565740 12245716 32% /
/dev/sda1 1038336 176880 861456 18% /boot
tmpfs 99568 20 99548 1% /run/user/1000
/dev/sr0 4600876 4600876 0 100% /run/media/centos/CentOS 7 x86_64
/dev/sdb1 51473888 53328 48782788 1% /quota
[root@localhost ~]# mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,size=480808k,nr_inodes=120202,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_prio,net_cls)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
configfs on /sys/kernel/config type configfs (rw,relatime)
/dev/mapper/centos-root on / type xfs (rw,relatime,attr2,inode64,noquota)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=22,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=13958)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime)
mqueue on /dev/mqueue type mqueue (rw,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
/dev/sda1 on /boot type xfs (rw,relatime,attr2,inode64,noquota)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)
tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,size=99568k,mode=700,uid=1000,gid=1000)
gvfsd-fuse on /run/user/1000/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000)
/dev/sr0 on /run/media/centos/CentOS 7 x86_64 type iso9660 (ro,nosuid,nodev,relatime,uid=1000,gid=1000,iocharset=utf8,dmode=0500,mode=0400,uhelper=udisks2)
/dev/sdb1 on /quota type ext4 (rw,relatime,data=ordered,jqfmt=vfsv0,usrjquota=aquota.user)
[root@localhost ~]# cd /quota/
[root@localhost quota]# quotaoff -avug
/dev/sdb1 [/quota]: user quotas turned off
[root@localhost quota]# quotacheck -augmn
[root@localhost quota]# rm -rf aquota.user
[root@localhost quota]# quotacheck -augmn
[root@localhost quota]# touch aquota.user aquota.group
[root@localhost quota]# chmod 600 aquota.*
[root@localhost quota]# quotacheck -augmn
[root@localhost quota]# quotaon -avug
/dev/sdb1 [/quota]: user quotas turned on
[root@localhost quota]# ll
합계 32
-rw------- 1 root root 0 9월 4 11:46 aquota.group
-rw------- 1 root root 7168 9월 4 11:47 aquota.user
drwx------ 3 ben ben 4096 9월 4 11:40 ben
drwx------ 3 jhon jhon 4096 9월 4 11:39 jhon
drwx------ 2 root root 16384 9월 4 11:34 lost+found
[root@localhost quota]# edquota -u
[root@localhost quota]# edquota -u ben
[root@localhost quota]# edquota -u ben
edquota: WARNING - /dev/sdb1: cannot change current inode allocation
[root@localhost quota]# edquota -u ben
[root@localhost quota]# su ben
[ben@localhost quota]$
[ben@localhost quota]$ pwd
/quota
[ben@localhost quota]$ cd /ben
bash: cd: /ben: 그런 파일이나 디렉터리가 없습니다
[ben@localhost quota]$ cd
[ben@localhost ~]$ cp /boot/vmlinuz-0-rescue-f6a3f0adda7a470ba04717ff611dbe4c test2
[ben@localhost ~]$ ll
합계 6612
-rwxr-xr-x 1 ben ben 6769256 9월 4 12:03 test2
[ben@localhost ~]$ cp /boot/vmlinuz-0-rescue-f6a3f0adda7a470ba04717ff611dbe4c test1
sdb1: warning, user block quota exceeded.
[ben@localhost ~]$ cp /boot/vmlinuz-0-rescue-f6a3f0adda7a470ba04717ff611dbe4c test3
sdb1: write failed, user block limit reached.
cp: `test3'에 쓰는 도중 오류 발생: 디스크 할당량이 초과됨
cp: failed to extend `test3': 디스크 할당량이 초과됨
[ben@localhost ~]$ ll
합계 15312
-rwxr-xr-x 1 ben ben 6769256 9월 4 12:03 test1
-rwxr-xr-x 1 ben ben 6769256 9월 4 12:03 test2
-rwxr-xr-x 1 ben ben 2138112 9월 4 12:03 test3
[ben@localhost ~]$ cd ..
[ben@localhost quota]$ ls
aquota.group aquota.user ben jhon lost+found
[ben@localhost quota]$ cd jhon
bash: cd: jhon: 허가 거부
[ben@localhost quota]$ exit
exit
[root@localhost quota]# logout
[centos@localhost ~]$
[centos@localhost ~]$ su -
암호:
마지막 로그인: 월 9월 4 11:33:12 KST 2023 일시 pts/0
[root@localhost ~]# repquota /quota/
*** Report for user quotas on device /dev/sdb1
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 3 0 0
jhon -- 28 0 0 7 0 0
ben +- 15360 10240 15360 6days 16 0 0
[root@localhost ~]# edquota -p ben jhon
[root@localhost ~]# repquota /quota/
*** Report for user quotas on device /dev/sdb1
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 3 0 0
jhon -- 28 10240 15360 7 0 0
ben +- 15360 10240 15360 6days 16 0 0
# useradd -d/quota/john john -> 유저 생성, 디렉토리 생성, 소유자
# passwd john -> 'john'의 패스워드 설정
# mount --options remount /quota -> 리붓과 같은 효과
# mount -> 마운트 정보확인
# quota-avug -> 쿼타 off
# quotacheck-aumn -> 쿼타 관련 파일시스템 체크
# rm -rf aquota.* -> 쿼타 관련 파일 삭제
# quotacheck-augmn -> 삭제 후 다시 체크
# touch aquota.user aquota.group -> 쿼타 관련 파일 생성
# chmod 600 aquota.* -> root만 접근 가능
# quotacheck-augmn -> 파일 생성후 다시 체크
# quotaon-avug -> 쿼타 시작
# ls -l -> 소유주, 권한, 쿼타 관련 파일 생성 확인
#edquota -u john -> vi과 같은 역할 (john의 할당량을 편집할 수 있다)
Filesystem blocks soft hard inodes soft hard
/dev/sdb1 15360 10240 15360 17 0 0
- Filesystem : 사용자별 쿼터를 할당하는 파일 시스템 (쿼터를 적용할 하드디스크)
- block : 사용량(KB)
- soft : 임시제한 (넘어가면 7일 유예)
- hard : 리얼 제한
** soft / hard : blocks에 대한 소프트 한도와 하드 한도. 소프트는 실제 사용가능 할당량이고 소프트 한도를 넘어서는 하드 한도라고 한다. 다만 하드한도는 사용할 수 잇는 기간(유예기간)이 정해져있어, 기간이 넘어가면 이 구간에 있는 파일은 사용할 수 없다. 0이라는 것은 현재 한도가 설정되어 있지 않다는 뜻.
- inodes : 파일 수
- inodes뒤의 soft /hard : inodes에 대한 소프트한도와 하드한도
# su-john -> 사용자 전환
________________________________________________________________________
쿼터 명령어
edquota_ 쿼터(할당량)를 설정하는 명령
-u [사용자] : 사용자의 할당량을 수정
-g [그룹] : 그룹의 할당량을 수정
-p [복사대상] [적용대상] : [복사대상]에 설정된 할당량을 복사해서 [적용대상]에 적용함
-t :grace(유예기간)값을 수정 {단위 : days, hours, minutes, seconds}
quotacheck_ 파일시스템에서 쿼터 관련 체크를 하는 명령 (설정한 쿼터가 실제로 적용됨)
-a(all) : 모든 파일 시스템을 체크
-u(user) : 사용자 쿼터 관련 체크
-g(group) : 그룹 쿼터 관련 체크
-m(no-remount) : 재마운트 생략
-n(use-first) : 첫 번재 검색된 것을 사용
-p(print-state) : 처리 결과를 출력
-v(Verbose) : 파일 시스템의 상태를 보여줌
requota_ 사용자별 현재 사용량을 확인할 수 있는 명령
-a : /etc/filesystem 에 잇는 모든 파일시스템에 관한 할당량을 출력
-c : 결과물을 콜론으로 분리하여 출력
-g : 그룹 할당량만 출력
-l : 긴 이름도 출력될 수 잇게 설정. 디폴트는 9자에서 절단하는데 이 옵션을 사용하면 전체 사용자 이름을 볼 수 있다
-u : 사용자 할당량만 출력
-v : 할당량 요약 앞에 해더행 출력
__________________________________________________________________________________
[쿼터 DB 생성]
# cd /userHome
# quotaoff -avug 쿼터 끄기
# quotacheck -augmn 파일시스템의 쿼터 관련 체크
# rm -rf aquota.* 생성된 쿼터 파일 일단 삭제
# quotacheck -augmn
# touch aquota.user aquota.group 쿼터 관련 파일 생성
# chmod 600 aquota.* 보안을 위해 소유자만 접근할 수 있도록 설정
# quotacheck -augmn
# quotaon -avug 설정된 쿼터 시작
'ICT기반 클라우드 네트워크 해킹 침해대응전문가 > Linux' 카테고리의 다른 글
[Linux] APM (0) | 2023.09.04 |
---|---|
[Linux] telnet (0) | 2023.09.04 |
[Linux] LVM (0) | 2023.09.04 |
[Linux] io 테스트 (0) | 2023.09.01 |
[Linux] RAID 실습 (0) | 2023.09.01 |