1. 필수 프로그램 및 nfs-server 설치

아래 커맨드를 실행하여 설치한다.

$ yum -y install nfs-utils rpcbind
systemctl start rpcbind
systemctl start nfs-server
systemctl start rpc-statd
systemctl enable rpcbind
systemctl enable nfs-server

# 상태 확인
$ systemctl status nfs-server

 

2. 볼륨으로 사용할 디렉토리 설정

볼륨으로 지정할 디렉토리를 만들고, nfs-server 가 그 디렉토리를 볼륨으로 사용하도록 설정한다. /etc/exports 파일에 설정하면 nfs-server 서버가 적용하는 구조이다.

아래 설정은, /file-storage 디렉토리를 어느 출발지에서나 읽기/쓰기 허용이다.

 

"/file-storage *(rw,sync,no_root_squash)"

 

즉 아래와 같은 구조인데, 간단히 표로 정리해본다.

<볼륨 디렉토리> <출발지 주소/CIDR>(<rw|ro>,<sync|async>,<no_root_squash|root_squash>)

항목 내용 예시
볼륨 디렉토리 볼륨으로 사용할 디렉토리 절대경로 /file-storage
출발지 주소/CIDR 볼륨에 접근하는 출발지 주소. CIDR 대역으로도 설정 가능 - 특정 IP만 허용: 192.168.56.30
- IP 대역으로 허용: 192.168.56.0/24

rw|ro 읽기 쓰기 or 읽기 전용 설정 - 읽기 쓰기: rw
- 읽기 전용: ro
sync|async 쓰기 작업을 동기적으로 or 비동기적으로 설정. 동기적으로 설정하면 하나의 쓰기가 모두 끝나야 응답을 하게 됨. 비동기적으로 설정하면 쓰기 요청 후 바로 응답을 하게 됨. - 동기: sync
- 비동기: async
no_root_squash|root_squash 클라이언트에서 root 사용자로 nfs-server 에 접근할 때 허용할지 설정. root_squash 로 설정하면 root 로 접근할 때 "anonymous" 사용자로 매핑하여 권한이 제한됨 - root 권한 제한: root_squash
- root 권한 허용: no_root_squash

 

// 디렉토리 생성
mkdir /file-storage

// exports 파일 설정
vi /etc/exports

// 아래 내용을 /etc/exports 에 추가
/file-storage *(rw,sync,no_root_squash)

// 설정 반영
exportfs -r

// 재시작
systemctl restart nfs-server

 

이렇게 nfs-server 를 설치하면 nfs 서버가 구축된 것이고, nfs-client 가 설치된 서버에서 이 nfs-server 를 호출하여 사용할 수 있게 된다. 리눅스에서 기본적으로 nfs-client 가 설치되어 있을텐데, 확인하기 위해서는 아래 명령어를 사용하면 된다.

$ yum list installed | grep nfs-utils
nfs-utils.x86_64                   1:2.3.3-59.el8                             @anaconda
블로그 이미지

망원동똑똑이

프로그래밍 지식을 자유롭게 모아두는 곳입니다.

,