본문 바로가기

리눅스

[리눅스] NFS(Network File Service) Server 설치

728x90

NFS(Network File Service) Server 설치

테스트 환경

$ cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.5 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.5 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

nfs 서버 설치

sudo apt update

nfs 서버 패키지 설치

sudo apt install -y nfs-kernel-server
sudo systemctl --now enable nfs-server.service
sudo systemctl status nfs-server
$ sudo systemctl status nfs-server
● nfs-server.service - NFS server and services
     Loaded: loaded (/lib/systemd/system/nfs-server.service; enabled; vendor preset: enabled)
     Active: active (exited) since Fri 2022-10-07 22:27:17 KST; 1min 12s ago
   Main PID: 3357495 (code=exited, status=0/SUCCESS)
      Tasks: 0 (limit: 4677)
     Memory: 0B
     CGroup: /system.slice/nfs-server.service

Oct 07 22:27:16 kube-control1 systemd[1]: Starting NFS server and services...
Oct 07 22:27:17 kube-control1 systemd[1]: Finished NFS server and services.

nfs 공유 디렉토리 생성

sudo mkdir -p /nfs-directory/shares-data1
sudo chown nobody:nogroup /nfs-directory/shares-data1
sudo chmod -R 777 /nfs-directory/shares-data1

nfs 서버 엑세스 권한 부여

sudo vim /etc/exports
$ sudo vim /etc/exports
# /etc/exports: the access control list for filesystems which may be exported
#               to NFS clients.  See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes       hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4        gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes  gss/krb5i(rw,sync,no_subtree_check)

/nfs-directory/shares-data1	0.0.0.0/0(rw,sync,no_subtree_check)
sudo exportfs -av
$ sudo exportfs -av
exporting 0.0.0.0/0:/nfs-directory/shares-data1
$ sudo exportfs -s
/nfs-directory/shares-data1  0.0.0.0/0(rw,wdelay,root_squash,no_subtree_check,sec=sys,rw,secure,root_squash,no_all_squash)

nfs 클라이언트 설정

showmount -e 127.0.0.1
$ showmount -e 127.0.0.1
Export list for 127.0.0.1:
/nfs-directory/shares-data1 0.0.0.0/0
728x90