본문 바로가기
OS 운영체제/LINUX

/etc/exports (export 관리 파일)

by yororing 2024. 4. 25.

00 개요

  • 리눅스에는 여러 디렉토리가 있다 (참조: 2024.03.20 - [LINUX] - Linux 디렉토리 구조)
  • 그 중 구성 (Configuration) 파일들이 모여있는 etc 폴더 안에는 exports이라는 파일이 있는데 이 파일은 원격 호스트에 내보내지는 파일 시스템을 제어하고 옵션을 지정한다
  • NFS 사용 시 사용됨

1. NFS란

  • 'Network File System'의 약자
  • 파일 공유 시스템
  • 분산된 파일 시스템 프로토콜 (통신규약)
  • 클라이언트 컴퓨터의 사용자가 로컬 저장소와 유사하게 컴퓨터 네트워크 상의 파일에 액세스할 수 있도록 허용하는 프로토콜

1) nfs 사용하기

# yum install nfs-utils		# nfs 설치
# systemctl start nfs-server	# nfs 시작
# systemctl enable nfs-server
# systemctl status nfs-server   # nfs 상태 확인

01 /etc/exports 파일

1. /etc/exports 파일이란?

  • NFS server export table
  • NFS Server에서 NFS Client에게 접근 가능하도록 export하는 로컬 파일 시스템 경로의 테이블을 포함
  • 즉, NSF Server가 NFS Client들에게 export하는 모든 경로들을 지정하는 파일
  • 이 테이블의 각 파일 시스템 경로는 옵션 목록과 접근 제어 목록이 함께함. 이 테이블은 exportfs(8)가 mountd(8)에 정보를 제공하기 위해 사용됨
  • 원격 호스트에 내보내지는 (export) 파일 시스템을 옵션과 함께 지정하는 파일 (controls which file systems are exported to remote hosts and specifies options)

2. /etc/exports 내용

# 문법
exported_file_system_directory hostname_1(options) hostname_n(options) ...
  • 각 줄: export할 경로와 해당 경로에서 파일 시스템을 마운트할 수 있는 NFS Client 목록 + 옵션이 공백으로 구분됨
    • 각 목록된 NFS Client 다음에는 그 NFS Client를 위한 export 옵션 목록이 괄호() 안에 쉼표(,)로 구분되어 있음
    • NFS Client와 옵션 목록 사이에는 공백이 없음
  • '#'으로 주석 처리, 공백 줄은 무시, 긴 줄은 backslash(\)로 감싸질 수 있음
  • 내보내기 이름에 공백이 포함된 경우 큰따옴표(" ")를 사용하여 인용 필수
  • 파일 변경 사항 적용하려면 exportsfs -ra를 실행하거나 NFS 서버를 재시작해야 함

1) 필드 설명

  • 첫번째 필드: exported file system directory
  • 두번째 필드: hostname + 공백 없이 () 안에 옵션들
    • hostname에 다음과 같은 메소드 사용 가능:
      • single host - 하나의 호스트 이름 지정 가능 - domain name이나 hostname이나 IP주소
      • wildcards - * 또는 ? character can be used to take into account a grouping of fully qualified domain names that match a particular string of letters. wildcards shouldn't be used with IP 주소 
      • IP networks - allows the matching of hosts based on their IP 주소 within a larger network (e.g., 192.168.0.0/28 allows the first 16 IP 주소들, from 192.168.0.0 to 192.168.0.15 to access the exported file system, but not 192.168.0.16 and higher)
      • netgroups - permits an NIS netgroup name, written as @<group-name>, to be used. 

3. options 종류

# 가장 간단한 형태 예시 - 옵션 없음
/u1/exports siserver

# 옵션 있는 예시
/u1/exports *(rw,sync,no_root_squash)
  • 기본값 (옵션이 지정되지 않은 경우 기본값으로 다음이 설정됨)
    • ro → ro를 해제하려면 rw를 넣어줘야됨
    • wdelay → wdelay를 해재하려면 no_wdelay를 넣어줘야 됨, 그러나 이 옵션은 sync 옵션을 사용할 때에만 가능
    • root_squash → root_squash를 해제하려면 no_root_squash 또는 all_squash 또는 anonuid=<uid-value>, anongid=<gid-value>를 넣어줘야됨

1) ro | rw

  • ro: remote hosts are unable to make changes to the data shared on the file system - read-only (default)
  • rw: allows remote hosts to read and write the file system

2) wdelay | no_wdelay

  • wdelay: causes the NFS server to delay writing to the disk if it suspects another write request is imminent
    • this can improve performance by reducing the number of times the disk must be accessed by separate write commands, reducing write overhead
    • the no_wdelay option turns off this feature, but is only available when using sync option
  • no_wdelay: allows multiple write requests to be committed to disc with the one operation which can improve performance
    • has no effect if async is also set
    • The NFS server will normally delay committing a  write  request to disc slightly if it suspects that another related write request may be in progress or may arrive soon.  This allows multiple write requests to be committed to disc with the one operation which can improve performance.  
    • If an NFS server received mainly small unrelated requests, this behaviour could actually reduce performance, so no_wdelay is available to turn it off.

3) async | sync

  • async: allows the NFS server to violate the NFS protocol and reply to requests before any changes made by that request have been committed to stable storage (e.g. disc drive)
    • 사용 시 성능은 향상되나 an unclean server restart (i.e. a crash) can cause data loss or corruption
  • sync: reply to requests only after the changes have been committed to stable storage

4)  User ID Mapping: root_squash | no_root_squash | all_squash | no_all_squash | anonuid=<uid-value>, anongid=<gid-value>

  • root_squash: prevents root users connected remotely from having root privileges and assigns them the user ID and group ID for the user nfsnobody.
    • this effectively "squashes" the power of the remote root user to the lowest local user, preventing unauthorized alteration of files on the remote server
    • maps requests from uid/gid 0 to the anonymous (or nfsnobody?) uid/gid
    • Note: this does  not  apply  to  any other uids or gids that might be equally sensitive, such as user bin or group staff
  • no_root_squash: turns off root squashing
    • 즉 NFS 서버와 클라이언트의 root 사용자가 같도록 설정하여 lets root users connected remotely to have root privileges
    • useful for diskless clients
  • all_squash: squashes every remote user, including root.
    • maps all uids and gids to the anonymous user
    • useful for NFS-exported public FTP directories, news spool directories, etc.
    • the opposite option is no_all_squash, which is the  default  set‐ ting.
  • anonuid and anongid: squashes remote users with specified user ID and group ID
    • explicitly sets the uid and gid of the anonymous account
    • useful for PC/NFS clients, where you might want all requests appear to be from one user

5) 외 다양한 옵션들 있음 (man exports 참조)

 

참조

  1. https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/5/html/deployment_guide/s1-nfs-server-config-exports
  2. https://www.ibm.com/docs/en/aix/7.2?topic=system-etcexports-file 
  3. https://www.ibm.com/docs/en/aix/7.2?topic=files-exports-file-nfs 
  4. https://www.ehostidc.co.kr/cscenter/technical.php?ptype=view&code=technical&idx=180&category=
  5. man exports
  6.