리눅스 NFS 원격 공유

  • systemddc
  • Linux
  • 1127
  • 0

리눅스에서 NFS 공유 방법


<서버>

# exports 내용 보기
 cat /etc/exports
  /home 26.1.22.*(rw)


# exportfs 구동 상태 확인.
 /usr/sbin/exportfs
  /home           26.1.22.*


# /etc/rc.d/init.d/portmap 및 nfs 시작.
 /etc/rc.d/init.d/portmap start
  Starting portmapper:  [  OK  ]
 /etc/rc.d/init.d/nfs stop
  Shutting down NFS mountd: [  OK  ]
  Shutting down NFS daemon: [  OK  ]
  Shutting down NFS services: [  OK  ]
  Shutting down NFS quotas: [  OK  ]
 /etc/rc.d/init.d/nfs start
  Starting NFS services:  [  OK  ]
  Starting NFS quotas:  [  OK  ]
  Starting NFS mountd:  [  OK  ]
  Starting NFS daemon:  [  OK  ]


# nfs 구동 상태 확인.
 /etc/rc.d/init.d/nfs status
  rpc.mountd (pid 1852) is running...
  nfsd (pid 1864 1863 1862 1861 1860 1859 1858 1857) is running...
  rpc.rquotad (pid 1847) is running...




< 원격서버(클라이언트)>



# 원격서버에 MOUNT 하기 (마운트는 원하는 위티에 원하는 만큼 하세요)
 mount -t nfs 26.1.22.17:/home        /home_backup/Engine 
 mount -t nfs 26.1.22.17:/home/share  /home/share


 


 


 


 


요즘 리눅스는 설치할 때 디폴트로 파이어월 (iptables)이 설치되어 대부분의 포트를 막아버린다. 따라서 NFS (Network File System)를 리눅스에서 사용하려면 몇몇 포트들을 열어주도록 설정해야 한다.

(요즘은 한 번 해도 조금 지나면 다 까먹기 때문에 이렇게 정리를 해줘야 한다. ㅠ.ㅠ)

이 작업은 FC4에서 하였다. 다른 버전에서도 되리라 믿는다. 안되면 알아서...
'bar'에서 'foo'의 "/home" 디렉토리를 NFS로 연결한다고 하자.

1. NFS 설정
/etc/exports 파일에 마운트를 허용할 파일시스템을 명시한다.


foo# cat >> /etc/exports
/home     bar(rw)
^D



NFS 옵션을 설정한다. rpc.statd 옵션은 설정할 필요없다 (FC4의 경우).


foo# vi /etc/sysconfig/nfs
# Number of servers to be started up by default
RPCNFSDCOUNT=8

# Options to pass to rpc.rquotad
RPCRQUOTADOPTS="-p 32766"

# Options to pass to rpc.mountd
RPCMOUNTDOPTS="-p 32767"

# Options to pass to rpc.statd
#RPCSTATDOPTS="-p 32768 -o 32769"



NFS 시작


foo# /sbin/service nfs start



RPC 정보를 확인해 보면 포트가 위에서 설정한 대로 사용됨을 확인할 수 있다.


foo$ /usr/sbin/rpcinfo -p
  program vers proto  port
   100000   2  tcp   111 portmapper
   100000   2  udp   111 portmapper
   100024   1  udp 32768 status
   100024   1  tcp 32769 status
   100011   1  udp 32766 rquotad
   100011   2  udp 32766 rquotad
   100011   1  tcp 32766 rquotad
   100011   2  tcp 32766 rquotad
   100003   2  udp  2049 nfs
   100003   3  udp  2049 nfs
   100003   4  udp  2049 nfs
   100003   2  tcp  2049 nfs
   100003   3  tcp  2049 nfs
   100003   4  tcp  2049 nfs
   100021   1  udp 41531 nlockmgr
   100021   3  udp 41531 nlockmgr
   100021   4  udp 41531 nlockmgr
   100021   1  tcp 43855 nlockmgr
   100021   3  tcp 43855 nlockmgr
   100021   4  tcp 43855 nlockmgr
   100005   1  udp 32767 mountd
   100005   1  tcp 32767 mountd
   100005   2  udp 32767 mountd
   100005   2  tcp 32767 mountd
   100005   3  udp 32767 mountd
   100005   3  tcp 32767 mountd




2. iptables 설정
NFS가 사용하는 포트들을 iptables rule chain에 추가한다.


foo# /sbin/iptables -A INPUT -p tcp --dport 111 -j ACCEPT
foo# /sbin/iptables -A INPUT -p udp --dport 111 -j ACCEPT
foo# /sbin/iptables -A INPUT -p tcp --dport 2049 -j ACCEPT
foo# /sbin/iptables -A INPUT -p udp --dport 2049 -j ACCEPT
foo# /sbin/iptables -A INPUT -p tcp --dport 32766 -j ACCEPT
foo# /sbin/iptables -A INPUT -p tcp --dport 32767 -j ACCEPT
foo# /sbin/iptables -A INPUT -p tcp --dport 32769 -j ACCEPT



새로 추가한 rule을 저장하고 싶은 경우 다음과 같이 /etc/sysconfig/iptables에 저장한다.


foo# /etc/init.d/iptables save




3. 클라이언트에서 연결
이제 'bar'에서 마운트하는 일만 남았다.


bar# mount foo:/home /mnt



에러가 발생한다면 에러 메시지를 확인해 본다.
다음 에러는 iptables가 제대로 설정되지 않았을 때 발생한다. 2번으로 돌아가 확인할 것.


mount to NFS server 'foo' failed: server is down.



다음과 같은 에러가 난다면 NFS 설정이 잘못된 경우이다. 1번으로 돌아가 확인할 것.


mount: foo:/home failed, reason given by server: Permission denied



- 명령 한 번에 내리기


<서버 >
cat /etc/exports
/usr/sbin/exportfs
/etc/rc.d/init.d/portmap start
/etc/rc.d/init.d/nfs stop
/etc/rc.d/init.d/nfs start
/etc/rc.d/init.d/nfs status


 


<클라이언트>

마운트 설정
mount -t nfs 26.1.22.17:/home        /home_backup/Engine
mount -t nfs 26.1.22.17:/home/share  /home/share

 

마운트 해제

umount /home_backup/Engine

umount /home/share