NFS 설정 · 4 min read · Dec 26, 2025

Debian Wheezy에서 NFS 서버 및 클라이언트 설정하기

이 가이드는 Debian Wheezy에서 NFS 서버와 NFS 클라이언트를 설정하는 방법을 설명합니다. NFS는 네트워크 파일 시스템을 의미하며, NFS를 통해 클라이언트는 NFS 서버의 원격 공유에 접근(읽기, 쓰기)할 수 있습니다. 이 튜토리얼에서는 파일 시스템 권한을 유지하지 않고 사용자 nobody/nogroup으로 파일을 저장하는 클라이언트 디렉토리의 두 가지 다른 NFS 내보내기와 호스팅 서버 설정에 필요한 파일의 권한과 소유권을 유지하는 /var/www 디렉토리의 내보내기를 보여드리겠습니다.

1 사전 참고

여기서는 두 개의 Debian Wheezy 시스템을 사용합니다:

  • NFS 서버: server.example.com, IP 주소: 192.168.0.100
  • NFS 클라이언트: client.example.com, IP 주소: 192.168.0.101

2 NFS 설치

서버:

NFS 서버에서 다음을 실행합니다:

apt-get install nfs-kernel-server nfs-common

그런 다음 NFS 서버의 시스템 시작 링크를 생성하고 시작합니다:

클라이언트:

클라이언트에서 NFS를 다음과 같이 설치할 수 있습니다(실제로 서버와 동일합니다):

apt-get install nfs-common

3 서버에서 디렉토리 내보내기

서버:

/home/client1 및 /var/www 디렉토리를 클라이언트가 접근할 수 있도록 설정하여 NFS 서버의 두 가지 다른 접근 모드를 보여주고자 합니다. /home/client1 디렉토리는 표준 모드로 공유되므로 이 디렉토리에 작성된 모든 파일은 사용자 nobody 및 그룹 nogroup으로 저장됩니다. /var/www 디렉토리의 경우 no_root_squash 옵션을 사용하여 NFS 서버가 파일의 권한과 소유권을 유지하도록 지시합니다. 이는 ISPConfig 3으로 관리되는 웹 서버의 /var/www 디렉토리를 내보내고자 할 때 필요합니다.

먼저 /home/client1 디렉토리를 생성하겠습니다.

mkdir /home/client1  
chown nobody:nogroup /home/client1  
chmod 755 /home/client1

/var/www 디렉토리는 서버에 존재할 가능성이 높습니다. 그렇지 않다면 생성합니다:

mkdir /var/www  
chown root:root /var/www  
chmod 755 /var/www

이제 /etc/exports를 수정해야 합니다. 여기서 NFS 공유를 “내보냅니다”. /home/client1 및 /var/www를 NFS 공유로 지정하고 NFS에 /home/client1에 대한 접근을 사용자 nobody로 설정하도록 지시합니다( /etc/exports에 대해 더 알고 싶다면, 형식 및 사용 가능한 옵션을 보려면 다음을 참조하세요:

man 5 exports

)

vi /etc/exports
/home/client1           192.168.0.101(rw,sync,no_subtree_check)
/var/www        192.168.0.101(rw,sync,fsid=0,crossmnt,no_subtree_check,no_root_squash)

(no_root_squash 옵션은 /var/www에 root로 접근할 수 있도록 합니다.)

/etc/exports의 변경 사항을 적용하기 위해 커널 NFS 서버를 재시작합니다.

/etc/init.d/nfs-kernel-server restart

4 클라이언트에서 NFS 공유 마운트하기

클라이언트:

먼저 NFS 공유를 마운트할 디렉토리를 생성합니다, 예를 들어:

mkdir -p /mnt/nfs/home/client1  
mkdir -p /var/www

서버에 /var/www 디렉토리가 이미 존재하는 경우, apache를 중지하고 디렉토리 이름을 변경한 후 새로운 빈 디렉토리를 마운트 포인트로 생성합니다.

/etc/init.d/apache2 stop  
mv /var/www /var/www_bak  
mkdir -p /var/www

그런 다음 다음과 같이 마운트할 수 있습니다:

mount 192.168.0.100:/home/client1 /mnt/nfs/home/client1  
mount 192.168.0.100:/var/www /var/www

이제 다음의 출력에서 두 개의 NFS 공유를 확인할 수 있어야 합니다:

df -h
[root@client ~]# df -h  
Filesystem            Size  Used Avail Use% Mounted on  
/dev/mapper/vg_server2-LogVol00  
                      9.7G  1.7G  7.5G  18% /  
tmpfs                 499M     0  499M   0% /dev/shm  
/dev/sda1             504M   39M  440M   9% /boot  
192.168.0.100:/home/client1   9.7G  1.7G  7.5G  19% /mnt/nfs/home/client1  
192.168.0.100:/var/www  
                      9.7G  1.7G  7.5G  19% /var/www  
[root@client ~]#

그리고

mount
[root@client ~]# mount  
/dev/mapper/vg_server2-LogVol00 on / type ext4 (rw)  
proc on /proc type proc (rw)  
sysfs on /sys type sysfs (rw)  
devpts on /dev/pts type devpts (rw,gid=5,mode=620)  
tmpfs on /dev/shm type tmpfs (rw)  
/dev/sda1 on /boot type ext4 (rw)  
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)  
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)  
192.168.0.100:/home/client1 on /mnt/nfs/home/client1 type nfs (rw,vers=4,addr=192.168.0.100,clientaddr=192.168.0.101)  
192.168.0.100:/var/www on /var/www type nfs (rw,vers=4,addr=192.168.0.100,clientaddr=192.168.0.101)  
[root@client ~]#

5 테스트

클라이언트에서 이제 NFS 공유에 테스트 파일을 생성해 볼 수 있습니다:

클라이언트:

touch /mnt/nfs/home/client1/test.txt  
touch /var/www/test.txt

이제 서버로 가서 두 개의 테스트 파일이 보이는지 확인합니다:

서버:

ls -l /home/client1/
[root@server ~]# ls -l /home/client1  
total 0  
-rw-r--r-- 1 nobody nogroup 0 Feb 02 16:58 test.txt  
[root@server ~]#
ls -l /var/nfs
[root@server ~]# ls -l /var/www  
total 0  
-rw-r--r-- 1 root root 0 Feb 02 16:58 test.txt  
[root@server ~]#

(테스트 파일의 소유권이 다르다는 점에 유의하세요: /home/client1 NFS 공유는 nobody / nogroup으로 접근되며 nobody / nogroup이 소유합니다; /var/www 공유는 root로 접근되므로 /var/www/test.txt는 사용자 및 그룹 root가 소유합니다.)

6 부팅 시 NFS 공유 마운트하기

클라이언트에서 NFS 공유를 수동으로 마운트하는 대신, /etc/fstab을 수정하여 클라이언트가 부팅할 때 NFS 공유가 자동으로 마운트되도록 할 수 있습니다.

클라이언트:

/etc/fstab을 열고 다음 줄을 추가합니다:

vi /etc/fstab
[...]  
192.168.0.100:/home/client1  /mnt/nfs/home/client1   nfs      rw,sync,hard,intr  0     0  
192.168.0.100:/var/www  /var/www   nfs      rw,sync,hard,intr  0     0

rw,sync,hard,intr 대신 다른 마운트 옵션을 사용할 수 있습니다. 사용 가능한 옵션에 대해 더 알고 싶다면 다음을 참조하세요:

man nfs

수정된 /etc/fstab이 작동하는지 테스트하려면, 공유를 언마운트하고 mount -a를 실행합니다:

umount /mnt/nfs/home/client1  
umount /var/www  
mount -a

이제 다음의 출력에서 두 개의 NFS 공유를 확인할 수 있어야 합니다:

df -h
[root@client ~]# df -h  
Filesystem            Size  Used Avail Use% Mounted on  
/dev/mapper/vg_server2-LogVol00  
                      9.7G  1.7G  7.5G  18% /  
tmpfs                 499M     0  499M   0% /dev/shm  
/dev/sda1             504M   39M  440M   9% /boot  
192.168.0.100:/home/client1   9.7G  1.7G  7.5G  19% /mnt/nfs/home/client1  
192.168.0.100:/var/www  
                      9.7G  1.7G  7.5G  19% /var/www  
[root@client ~]#

그리고

mount
[root@client ~]# mount  
/dev/mapper/vg_server2-LogVol00 on / type ext4 (rw)  
proc on /proc type proc (rw)  
sysfs on /sys type sysfs (rw)  
devpts on /dev/pts type devpts (rw,gid=5,mode=620)  
tmpfs on /dev/shm type tmpfs (rw)  
/dev/sda1 on /boot type ext4 (rw)  
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)  
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)  
192.168.0.100:/home/client1 on /mnt/nfs/home/client1 type nfs (rw,vers=4,addr=192.168.0.100,clientaddr=192.168.0.101)  
192.168.0.100:/var/www on /var/www type nfs (rw,vers=4,addr=192.168.0.100,clientaddr=192.168.0.101)  
[root@client ~]#

7 크레딧

이 튜토리얼은 Falko Timme의 Centos NFS 서버 튜토리얼을 기반으로 합니다.

8 링크

Share: X/Twitter LinkedIn

새 게시물을 받은 편지함에서 받기

스팸은 없습니다. 언제든지 구독 해지 가능합니다.