본문 바로가기

Linux Server 구축/2-2. NFS Server

NFS


NFS(Network File System ) Server


- NFS (Network File System) Server
리눅스 및 유닉스 시스템등의 동일 온영체제에서 TCP/IP 네트워크를 통해 파일 시스템과 서버자원 공유를 위해
Sun microsystems에서 NIS(Network Information Service)와 함께 개발된 프로토콜 서비스이다.
보안에 취약하므로 사용에 주의 해야 한다.

-------------------------------------------------------------------

1. NFS관련 데몬

1-1. portmap

- portmapper 서버 데몬으로 RPC(Remote Procedure Call) 서비스 (NIS, NFS 등)를 TCP/UDP 포트에 연결시켜 준다.
- RPC 프로그램 번호를 TCP/IP(UDP/IP) 프로토콜 port번호로 변경해 주는 서버로 RPC 서비스를 위해서 반드시 실행되어 있어야 한다.
- RPC 서버가 시작되면 portmap은 해당 RPC 서버가 어떤 포트에 Listen하고 있는지를 알려준다.

- 구동 방법 : service portmap start/stop/restart

portmap 확인

[root@localhost ~]# ps aux | grep portmap
rpc       4518  0.0  0.0   1808   460 ?        Ss   08:29   0:00 portmap
root     23183  0.0  0.0   5192   756 pts/4    S+   17:14   0:00 grep portmap
[root@localhost ~]# rpcinfo -p  - RPC(Remote Procedure Call) 서버의 상태를 출력한다.
   프로그램 버전 원형   포트
    100000    2   tcp    111  portmapper
    100000    2   udp    111  portmapper
    100024    1   udp    910  status
    100024    1   tcp    913  status
[root@localhost ~]#

-------------------------------------------------------------------

- 참고
[root@server3 ~]# service portmap stop
portmap 를 정지 중:                                        [  OK  ]
[root@server3 ~]# rpcinfo -p  - portmap 서비스가 동작하지 않으면 RPC(Remote Procedure Call) 서버의 상태를 출력할 수 없다.
rpcinfo: 포트매퍼에 연결할 수 없습니다: RPC: 원격 시스템 오류 - 연결이 거부됨

-------------------------------------------------------------------

1-2. NFS

- nfs 서비스를 구동하기 위한 데몬으로 nfsd, rpc.mountd, rpc.statd, lockd, rpc.rquotad 데몬들이 구동된다.
- nfs 서버에서는 nfsd, rpc.mountd, rpc.stad, lockd 데몬이 작업을 수행한다.
- nfs 클라이언트는 rpc.statd, lockd, rpc.rquotad 데몬이 작업을 수행한다.

- 구동 방법 : service nfs start/stop/restart

- 참고
rpc.nfsd : RPC요청 처리와 서버측에서 rpc.mountd에 의해 마운트되면 클라이언트는 rpc.nfsd로 서버에 요청 처리와 명령 실행등을 포함한 적업을 수행한다.
rpc.mountd : 클라이언트가 마운트 요청을 하면 /etc/exports 파일 설정에 따라 마운트 요청을 처리한다.
rpc.statd : rpc.lockd와 함께 작동하여 파일 잠금 해제와 비정상적으로 종료시 복구를 담당한다.
rpc.lockd : 파일 잠금을 통해 클라이언트에서 여러 사용자가 한 파일을 수정하는 것을 방지한다.
rpc.rquotad : NFS파일 시스템을 마운트한 로컬사용자에 대해 quota를 처리한다.



[root@server3 ~]# rpm -qa | grep nfs - nfs패키지 확인
nfs-utils-lib-1.0.8-7.2.z2
system-config-nfs-1.3.23-1.el5
nfs-utils-1.0.9-33.el5
[root@server3 ~]# rpm -qi nfs-utils 
Name        : nfs-utils                    Relocations: (not relocatable)
Version     : 1.0.9                             Vendor: CentOS
Release     : 33.el5                        Build Date:
Install Date:       Build Host: builder16.centos.org
Group       : System Environment/Daemons    Source RPM: nfs-utils-1.0.9-33.el5.src.rpm
Size        : 756884                           License: GPL
Signature   : DSA/SHA1, 2008년 06월 15일 (일) 오전 08시 37분 11초, Key ID a8a447dce8562897
Summary     : NFS utlilities and supporting clients and daemons for the kernel NFS server.
Description :
The nfs-utils package provides a daemon for the kernel NFS server and
related tools, which provides a much higher level of performance than the
traditional Linux NFS server used by most users.

This package also contains the showmount program.  Showmount queries the
mount daemon on a remote host for information about the NFS (Network File
System) server on the remote host.  For example, showmount can display the
clients which are mounted on that host.

This package also contains the mount.nfs and umount.nfs program.

-------------------------------------------------------------------

2. NFS 서버 설정

/etc/exports
- NFS 서비스의 주요 설정 파일로 rpc.mountd, rpc.nfsd는 이 파일의 설정에 따라 구동된다.

-형식
[디렉토리] [클라이언트] (options)

- options
ro : 읽기 전용 모드
rw : 읽기 쓰기 모드
secure : 클라이언트 마운트 요청시 포트를 1024 이하로 설정한다.
noaccess : 액세스 거부
root_squash : 클라이언트의 root를 서버의 nobody 권한으로 설정
no_root_squash : 클라이언트의 root를 서버의 root 권한으로 설정
all_squach : root를 제외하고 서버와 클라이언트의 사용자를 동일한 권한 으로 설정 한다.
no_all_squach : root를 제외하고 서버와 클라이언트의 사용자들을 하나의 권한을 가지도록 설정한다.
lnsecure : 인증되지 않은 엑세스도 가능
sync : 클라이언트가 파일 쓰기 완료후 디스크 동기화

-------------------------------------------------------------------

PC0 에서의 설정

[root@localhost  ~]# vi /etc/exports


1 /nfs_share      10.10.0.0/255.255.0.0(rw,no_root_squash,sync)

- pc0의 /nfs_share 디렉토리를 10.10.0.0 대역에서 root의 권한으로 읽기, 쓰기를 허락한다는 뜻이다.

[root@server3 nfs_client]# service portmap restart  - 기본적으로 실행되어 있지만 nfs 서비스를 하기 전에 항상 확인한다.
portmap 를 정지 중:                                        [  OK  ]
portmap (을)를 시작 중:                                    [  OK  ]

[root@server3 ~]# service nfs restart
NFS mountd를 종료 중:                                      [  OK  ]
NFS 데몬을 종료 중:                                        [  OK  ]
NFS 서비스를 종료 중:                                      [  OK  ]
NFS 서비스를 시작 중:                                      [  OK  ]
NFS 쿼터를 시작 중:                                        [  OK  ]
NFS 데몬을 시작 중:                                        [  OK  ]
NFS mountd를 시작 중:                                      [  OK  ]
[root@server3 ~]# rpcinfo -p
   프로그램 버전 원형   포트
    100000    2   tcp    111  portmapper
    100000    2   udp    111  portmapper
    100011    1   udp    621  rquotad
    100011    2   udp    621  rquotad
    100011    1   tcp    624  rquotad
    100011    2   tcp    624  rquotad
    100003    2   udp   2049  nfs
    100003    3   udp   2049  nfs
    100003    4   udp   2049  nfs
    100021    1   udp  32775  nlockmgr
    100021    3   udp  32775  nlockmgr
    100021    4   udp  32775  nlockmgr
    100003    2   tcp   2049  nfs
    100003    3   tcp   2049  nfs
    100003    4   tcp   2049  nfs
    100021    1   tcp  43956  nlockmgr
    100021    3   tcp  43956  nlockmgr
    100021    4   tcp  43956  nlockmgr
    100005    1   udp    673  mountd
    100005    1   tcp    676  mountd
    100005    2   udp    673  mountd
    100005    2   tcp    676  mountd
    100005    3   udp    673  mountd
    100005    3   tcp    676  mountd

-------------------------------------------------------------------

PC1 에서의 설정

[root@localhost  nfs]# mkdir /nfs_client  - /nfs_client 폴더를 생성한다.
[root@localhost  nfs]# mount -t nfs 10.10.33.100:/nfs_share /nfs_client  - 10.10.33.100:/nfs_share 폴더를 /nfs_client 폴더에 마운트시킨다.
[root@localhost  nfs]# mount  - 마운트가 되었는지 확인
/dev/sda7 on / type ext3 (rw)

- 중략

none on /proc/fs/vmblock/mountPoint type vmblock (rw)
10.10.33.100:/nfs_share on /nfs_client type nfs (rw,addr=10.10.33.100)

[root@localhost  nfs]# cd /nfs_client 
[root@localhost  nfs_client]# ls  - /nfs_share 폴더의 내용을 확인할 수 있다.
100.txt  100dir
[root@localhost  nfs_client]# touch 7.txt - root의 권한으로 읽기, 쓰기 기능이 있으므로 파일 생성이 가능하다.
[root@localhost  nfs_client]# ls
100.txt  100dir  7.txt

-------------------------------------------------------------------

3. NFS 서버의 설정 파일 출력

[root@server3 nfs_client]# exportfs  - NFS서버의 exporting 정보를 출력하거나 설정을 변경할수 있다.
/nfs            10.10.0.0/255.255.0.0
[root@server3 nfs_client]# exportfs -v
/nfs            10.10.0.0/255.255.0.0(rw,wdelay,no_root_squash,no_subtree_check,anonuid=65534,anongid=65534)

- options
-a : /etc/exports 파일을 읽어 들인다.
-r :
/etc/exports 파일을 다시 읽어 들인다. (nfs 데몬의 종료 없이)

-u IP:/디렉토리 : 입력한 디렉토리를 공유목록에서 제외한다.
-v :
현재의 공유 목록을 확인한다.
-i :
/etc/exports 파일을 무시하고 설정한다.

-------------------------------------------------------------------

4. 현재 마운트 된 사용자의 정보를 확인

[root@localhost ~]# vi /var/lib/nfs/rmtab
[root@localhost ~]# cat /var/lib/nfs/rmtab
10.10.33.2:/nfs:0x00000001   - 10.10.33.2 사용자가 /nfs 에 접속

-------------------------------------------------------------------

5. /etc/fstab 등록

[root@localhost ~]# vi /etc/fstab
[root@localhost ~]# cat /etc/fstab
10.10.33.100:/nfs_share                   /nfs_client                nfs   defaults        0 0 
10.10.33.2:/root/vmware                  /nfs_client                nfs   timeo=25,intr        0 0 
 
- options
rsize : NFS서버로 부터 읽어들이는 바이트 수 지정 (기본 값: 1024byte)
wsize : NFS서버에 기록할 때 사용하는 바이트 수 지정 (기본 값 : 1024byte)
timeo : 클라이언트에서 타임아웃이 발생되고 나서, 다시 재전송 요구를 보낼때의 시간
retrans : 재전송 횟수 지정
port : NFS 서버에 연결시 사용포트 번호 지정
fg : NFS 서버에 타임아웃이 발생되면 즉각 접속 중지
intr : 인터럽트 허용
hard: 타임아웃 발생시 "server not responding" 메세지 표시 후 계속 재시도
soft : 타임아웃 발생시 I/O 에러 표시

- nefts 데몬이 동작시에만 자동으로 NFS 마운트 가능