linux class 1 페이지

본문 바로가기
사이트 내 전체검색


회원로그인

linux class

NFS(Network Filesytem)

페이지 정보

작성자 admin 작성일15-12-23 15:35 조회218회 댓글0건

본문

NFS 서비스
NFS 
- unix 또는 리눅스 host 간의 파일시스템 및 디렉토리 공유.
단. 파일은 공유 대상이 아니다. 공유대상은 파일시스템의
 마운트 포인터이거나 단순한 디렉토리이다.

서버에서 공유자원을 걸어두면 nfs 클라이언트가 공유자원에
 주어진 권한을 가지고 접근할 수 있다.

nfs 서비스 연결 과정
nfs 서비스 image 
1. client 는 mount 가 mount 데몬의 포트 넘버를 알려달라고
portmap 데몬(111번 포트사용)에게 요청한다.
 (rpc.mountd 는 동적포트를 사용하는 서비스이므로 포트넘버가 고정되어 있지 않고
올라올때 마다 바뀔수 있다)

- 대부분의 서비스는 미리정해진 정적포트를 사용하지만 mount 데몬같은 일부 서비스는
동적포트를 사용한다.
- 동적포트를 사용하는 서비스는 services 파일에 등록되어 있지 않다.
- 그래서 클라이언트는 동적포트를 사용하는 서비스에 접속하기위해서는 포트 넘버를
먼저 알수 있어야 하며 그래서 모든 동적 포트를 사용하는 서비스에 접속하는 클라이언트는
portmap 데몬에 먼저 접속하게 된다.

*. 연결되어있는 port 나 대기중인(listen)상태인 port를 확인하려면
netstat를 사용하면 된다.

netstat -tp ; 연결되어 있는 port 주소(서비스명)를 출력한다.
netstat -ntp ; 연결되어 있는 port 주소를 숫자로 출력한다.
netstat -ltp ; 대기중인 port 주소를 출력한다.
netstat -nltp ; 대기중인 port 주소를 숫자로 출력한다.
*. p 옵션은 프로세스이름을 출력하기 위한 옵션
*. t 옵션은 연결되어 있는 포트를 출력하기 위한 옵션
*. lt 옵션은 대기중인 포트를 출력하기 위한 옵션

2. 서버측에서는 portmap 데몬이 mount데몬(rpc.mountd)의 포트넘버를 확인해서 알려준다.

3. client 는 mount 가 서버측에서 알려준 port 번호로 다시 접속을 시도한다.

4. 서버측의 mount 데몬은 client 가 mount 를 할 수 있도록 허용받은 주소인지를 확인하고
허용받은 주소라면 공유자원을 마운트 되게 한다. 그렇지 않으면 mount 를 거부한다.

5. 클라이언트는 마운트 한 서버측 자원을 읽기 또는 읽기/쓰기 권한으로 접근하여 파일을
읽거나 만들 수 있다.


nfs 서버 설정

nfs 서버는 standalone 방식으로 구동되며 /etc/init.d/nfs 스크립트 파일을 실행하면 된다.


- 설정파일은 /etc/exports 파일이며 설정 방법은 단순하다.

[root@star init.d]# cat /etc/exports
/share 192.168.37.10 => /share 자원을 마운트 할수 있는 클라이언트는 192.168.37.10 만 가능하다.
/share2 192.168.37.10(rw,sync) => 괄호안에 있는 것은 권한과 옵션이다. rw - 읽기쓰기권한.
sync 는 클라언트와 동기화 하기 위한 옵션. 디폴트값이다.
/share3 192.168.37.0/255.255.255.0(rw)
/share4 192.168.37.10(rw,no_root_squash) /share4 디렉토리는 192.168.37.10 에서 읽기 쓰기권한으로
마운트 할수 있으며 클라이언트의 root 가 공유자원에 접근시 root 권한을 가지고 접근할 수 있다.
디폴트 옵션은 root_squash 로서 root 가 공유자원에 접근시 nfsnobody 권한으로 접근하게 된다.

공유자원 확인(서버측에서)
[root@star init.d]# showmount -e
Export list for star:
/share3 192.168.37.0/255.255.255.0
/share 192.168.37.10
/share4 192.168.37.10
/share2 192.168.37.10
[root@star init.d]#

공유자원사용(클라이언트측에서)

mount -t nfs 서버ip(또는 도메인이나 host명):/share /mnt/nfs1
이렇게 mount 해서 사용하면 된다.
ex 1) mount -t nfs centos:/var/share /mnt/nfs
ex 2) mount -t nfs -o nolock centos:/var/share /mnt/nfs

리부팅후에도 계속 공유자원을 사용하려면 /etc/fstab 파일에

server1:/share /mnt/nfs1 nfs defaults 0 0

<= 맨 끝에는 0 0 으로 한다. 이것은 nfs 자원은 자신의 것이 아니므로
부팅시 파일시스템 체크를 할 필요가 없기때문이다.


그리고 사용하지 않으려면 간단히 마운트 해제 하면 된다.

umount /mnt/nfs1

[root@star init.d]

===========================================
추가사항

sync : Reply to requests only after the changes have been committed to stable storage
nfs 마운트 포인터에 파일생성시 파일생성을 동기화 한후에 다음 요청을 받아들이게 한다.

async : This option allows the NFS server to violate the NFS protocol and reply to requests before any
 changes made by that request have been committed to stable storage (e.g. disc drive).
 Using this option might improve performance with version 2 only, but at the cost that an unclean
 server restart (i.e. a crash) can cause data to be lost or corrupted.

nfs 마운트 포인터에 파일생성시 파일생성이 동기화 되기전에도 다음 요청을 받아들인다.
이럴경우 데이터 기록에 대한 안정성이 떨어진다.
그리고 nfs 서버 버전2일때만 성능향상을 기대할 수 있다.
그러므로 nfs 서버버전이 2 버전이 아니라면 이 옵션을 사용할 이유가 없다.

*. 현재 centos5.x 버전이라면 디폴트 nfs 서버버전은 3 버전이다.


all_squash : nfs 서버의 공유자원에 접근하는 모든 nfs 클라이언트 계정을 anonymous user 로 취급한다.
anonuid / anongid : anonymous 의 계정이나 그룹을 특정 uid 권한 또는 특정 gid 권한을 가지게 한다.

공유자원 설정예제.
 # sample /etc/exports file
 / master(rw) trusty(rw,no_root_squash)
 /projects proj*.local.domain(rw)
 /usr *.local.domain(ro) trusted(rw)
 /home/joe pc001(rw,all_squash,anonuid=150,anongid=100)
 /pub (ro,all_squash)

 no_wdelay
 This option has no effect if async is also set. The NFS server will normally delay committing a write
 request to disc slightly if it suspects that another related write request may be in progress or may arrive
 soon. This allows multiple write requests to be committed to disc with the one operation which can improve
 performance. If an NFS server received mainly small unrelated requests, this behaviour could actually reduce
 performance, so no_wdelay is available to turn it off. The default can be explicitly requested with the wde-
 lay option.

이 옵션은 async 옵션과 같이 사용할 수 없다.
NFS 서버는 쓰기 요청에 대해 일반적으로 작은 크기의 데이터가 들어오면 그것을 모아두었다가
한번에 기록을 하는것이 성능상 유리할 것이다. nfs 는 실제로 디스크에 데이터를 쓸때까지 잠시
지연시간을 두기도 하는데 no_wdelay 옵션은 데이터가 오면 즉시 기록하는 방식이다.

*. 공유자원 정보 갱신 및 확인
exportfs(8) exportfs(8)

NAME
 exportfs - maintain list of NFS exported file systems

SYNOPSIS
 /usr/sbin/exportfs [-avi] [-o options,..] [client:/path ..]
 /usr/sbin/exportfs -r [-v]
 /usr/sbin/exportfs [-av] -u [client:/path ..]
 /usr/sbin/exportfs [-v]
 /usr/sbin/exportfs -f

/etc/exportfs 내용을 수정한 경우
nfs 서비스 재시작 하지 않고도 exportfs 명령으로 수정한 내용을
바로 적용할 수 있다.
-r Reexport all directories. It synchronizes /var/lib/nfs/xtab with /etc/exports. It
 removes entries in /var/lib/nfs/xtab which are deleted from /etc/exports, and remove any
 entries from the kernel export table which are no longer valid.

서버의 공유자원 정보는 showmount 또는 exportfs 명령어로 확인할 수 있다.
[root@centos100 ~]# showmount -e server
Export list for server:
/var/share 192.168.203.100/255.255.255.0

[root@centos1 ~]# exportfs
/var/share 192.168.203.100/255.255.255.0
[root@centos1 ~]# exportfs -v
/var/share 192.168.203.100/255.255.255.0(ro,wdelay,root_squash,no_subtree_check,anonuid=65534,anongid=65534)
[root@centos1 ~]#

공유자원을 해제 하고 싶을때는
exportfs -u 옵션을 사용하면 된다.
-u Unexport one or more directories.

[root@centos1 ~]# showmount -d [server] ; 클라이언트에 의해 마운트되어 있는 디렉토리만 출력해준다.
Directories on centos1:
/var/share2
 -d or --directories
 List only the directories mounted by some client.

댓글목록

등록된 댓글이 없습니다.


접속자집계

오늘
25
어제
75
최대
611
전체
448,075
개인정보취급방침 서비스이용약관 twoseven.kr All rights reserved.
상단으로