WindyHana's Solanara: NFS

목차

NFS란?

기본적인 공유방법

서버(wl)

root@wl ~ # vi /etc/hosts
192.168.0.11    wl2
root@wl ~ # vi /etc/dfs/dfstab
share -F nfs -o rw=wl2 -d "WL2 SHARE" /export/home/share 1)
root@wl ~ # shareall 2)
root@wl ~ # share 3)
-               /export/home/share   rw=wl2   "WL2 SHARE"
root@wl ~ # 
1) -F는 파일 시스템을 지정하는 것으로 nfs로 고정되어있다. -o 에는 옵션을 써준다. rw=wl2의 의미는 wl2서버에서 접속시 rw(읽기/쓰기)가 가능하도록 한다는 뜻이다. -d의 문자는 단순한 설명문이다. 마지막은 공유할 디렉토리를 전체경로로 입려한다. NFS서버를 세팅하는 가장 단순한 방법이다. 다른 옵션에 대한 설명은 [man share_nfs]를 참조한다.
2) shareall은 /etc/dfs/dfstab 파일을 읽어 실행하는 명령이다. 바꿔말하면 1)의 [share ~]를 커맨드에서 실행시켜도 된다. (파일에 넣어두어야 시스템 재부팅시 자동으로 실행된다)
3) 공유된 내역을 확인할 수 있다.

클라이언트(wl2)

root@wl2 ~ # mkdir /root/share
root@wl2 ~ # vi /etc/hosts
192.168.0.3     wl
root@wl2 ~ # mount -F nfs wl:/export/home/share /root/share 1)
root@wl2 ~ # 
1) wl2에서, wl에서 공유한 /export/home/share 디렉토리를 /root/share 에 마운트한다.

클라이언트에서 부팅시 자동으로 마운트하기

vfstab파일에 등록하고 nfs client 관련 서비스가 부팅시에도 시작되어있어야 한다.
root@wl2 ~ # vi /etc/vfstab
...
wl:/export/home/share	-	/root/share	nfs	-	yes	-
...
root@wl2 ~ # svcs | grep nfs
online          3:46:12 svc:/network/nfs/cbd:default
online          3:46:12 svc:/network/nfs/mapid:default
online          3:46:12 svc:/network/nfs/status:default
online          3:46:12 svc:/network/nfs/nlockmgr:default
online          3:46:21 svc:/network/nfs/client:default
root@wl2 ~ #

NFS파일 시스템 사용시 주의사항

automount 사용하기

솔라리스10에는 automountd 라는 데몬이 있다. 요청이 들어오면 자동적으로 NFS파일 시스템을 마운트 해 주고 사용하지 않으면 일정 시간(기본값은 10분)이 지나면 접속을 끊는 것이다. 솔라리스는 리눅스와는 달리 /export/home 이 사용자의 기본 홈 베이스 디렉토리인데, 이는 /home 디렉토리는 automountd에 의해 사용되기 때문이기도 하다. /home 외에 /net 도 automountd 에 의해 사용된다. (/home, /net에 디렉토리에 일반 파일을 생성하려면, automountd를 종료해야 한다. 하지만 추천하지 않는다)
root@wl2 ~ # ps -ef | grep auto
    root  2202     1   0   10월 1 ?           0:00 /usr/lib/autofs/automountd
    root  2203  2202   0   10월 1 ?           0:30 /usr/lib/autofs/automountd
root@wl2 ~ # svcs | grep autofs
online         10월_10 svc:/system/filesystem/autofs:default
root@wl2 ~ #
automound 는 /etc/auto_master 파일로 설정한다. 솔라리스를 설치하고 별다른 수정사항이 없다면 아래와 같이 되어있을 것이다.
root@wl2 ~ # cat /etc/auto_master
+auto_master
/net            -hosts          -nosuid,nobrowse
/home           auto_home       -nobrowse
root@wl2 ~ # 
또한 /etc/auto_home 파일도 확인해보자. 이 파일에서 auto_home 이란 이름은 /etc/auto_master 파일에서 /home으로 시작하는 컬럼에 지정된 이름과 같은 것이다.
root@wl2 ~ # cat /etc/auto_home
+auto_home
root@wl2 ~ # 

/home 디렉토리(홈 디렉토리 공유)

wl2 서버의 windy 사용자는 wl서버의 홈 디렉토리와 디렉토리를 공유하려 한다. 이때는 아래와 같이 하면 된다.
root@wl ~ # useradd -d /export/home/windy -c "윈디하나" -g staff -m -u 101 -s /bin/bash windy
root@wl ~ # vi /etc/dfs/dfstab
share -F nfs -o rw=wl2 -d "windy share" /export/home/windy
root@wl ~ # shareall
root@wl ~ # 
※ 서버는 통상적인 NFS 공유 설정과 다를 것이 없다.
root@wl2 ~ # vi /etc/auto_home
windy	wl:/export/home/windy
root@wl2 ~ # useradd -d /home/windy -c "윈디하나" -g staff -u 101 -s /bin/bash windy
root@wl2 ~ # su - windy
windy@wl2 ~ $ pwd
/home/windy
windy@wl2 ~ $
※ 클라이언트는 automountd 를 위해 /etc/auto_home를 수정하고 홈 디렉토리를 automountd 가 관리하는 /home/windy를 가리키도록 한다. 평상시에는 마운트되지 않다가 windy 가 wl2에 로그인 해서 홈 디렉토리로 현재 디렉토리를 옮길 때 자동으로 마운트 될 것이다.

※ 참고
1) NFS서버 다운되면 로그인이 안된다. 홈 디렉토리가 없기 때문이다.
2) 루트는 nobody의 UID를 사용해 NFS서버에 접근하기 때문에 위와같이 해서는 안된다.
3) NFS에 접속할 때 옵션이 필요한 경우 (예를 들면 NFS 3로 접속해야 하는 경우) auto_home 파일에 [windy -proto=tcp,vers=3 wl:/export/home/windy] 처럼 설정하면 된다.

/net 디렉토리

윈도우에서 네트워크 환경을 들어가보면 공유된 서버와 공유된 디렉토리들이 보일 것이다. 솔라리스에서 이와 비슷한 역할을 하는 것이 /net 디렉토리다. (공유된 서버의 목록은 안 보인다) [/net/주소] 디렉토리에 가보면 현재 공유되는 자원을 확인할 수 있다.
root@wl2 ~ # cd /net
root@wl2 /net # ls -alF
총 4
dr-xr-xr-x   1 root     root           1 11월  6일  14:59 ./
drwxr-xr-x  25 root     root          26 11월  6일  14:59 ../
root@wl2 /net # cd /net/wl 1)
root@wl2 /net/wl # ls -alF
총 3
dr-xr-xr-x   2 root     root           2 11월  6일  15:08 ./
dr-xr-xr-x   2 root     root           2 11월  6일  14:59 ../
dr-xr-xr-x   1 root     root           1 11월  6일  15:08 export/
root@wl2 /net/wl # cd ./export/home
root@wl2 /net/wl/export/home # ls -al
...
dr-xr-xr-x   1 root     root           1 11월  3일  15:49 share
dr-xr-xr-x   1 root     root           1 11월  3일  15:49 windy
root@wl2 /net/wl/export/home #
1) [/net/wl] 대신 [/net/192.168.0.3]과 같이 wl의 IP를 써줄 수도 있고 도메인 명을 써줄수도 있다. [/net/wl2]와 같이 자신의 호스트로 접속할 수도 있다.

NFS 고급

share 명령의 옵션

NFS 로깅

NFS서버에서 무슨일이 일어나고 있는지 로깅할 수 있다. /etc/default/nfslogd 파일과 /etc/nfs/nfslog.conf 파일로 설정할 수 있다. 아래는 이 두개의 파일을 그대로 두고 로그를 사용하는 방법에 대해 설명한다.
root@wl ~ # vi /etc/dfs/dfstab
share -F nfs -o rw=wl2,log=global -d "WL2 SHARE" /export/home/share
root@wl ~ # shareall
root@wl ~ # share
-               /export/home/share   rw=wl2,log=global   "WL2 SHARE"
root@wl ~ # svcadm restart network/nfs/server:default 1)
root@wl2 ~ # mount -F nfs -o vers=3 wl:/export/home/share /root/share 2)
root@wl ~ # cat /var/nfs/nfslog 3)
메시지 생략
Mon Nov  3 17:13:05 2008 0 wl2 0 /export/home/share/source/top-3.7/m_sunos5.o b _ remove r 60001 nfs3-tcp 0 *
메시지 생략
1) /etc/nfs/nfslogtab 파일이 있어야 nfslogd 데몬이 실행된다. 없다면 shareall부터 다시하자.
2) 현재의 솔라리스 10 버전(u6)는 NFSv4 인 경우 로그가 쌓이지 않는다. (nfslogd MAN페이지에 나와있다) 따라서 NFSv3를 사용한다.
3) FTP로그 쌓이듯 로그가 저장된다. 그런데 처음에는 아마 안 보일 것이다. 일정한 양이 쌓여야 파일에 쓰기 때문이고, 파일이 전송된것만 보이기 때문이다. 디렉토리를 만드는 것은 안 보인다. 이를 해결하려면 nfslogd 의 설정을 바꿔야 한다. (버퍼 파일이 없거나, 버퍼 값이 너무 작으면 NFS 성능이 매우 많이 떨어진다. 테스트할 목적으로만 사용하자)
root@wl ~ # vi /etc/nfs/nfslog.conf
global  defaultdir=/var/nfs \
        log=nfslog fhtable=fhtable buffer=nfslog_workbuffer logformat=extended
root@wl ~ # vi /etc/default/nfslogd
MIN_PROCESSING_SIZE=1024
root@wl ~ # svcadm restart network/nfs/server:default

NFS 마운트 옵션

NFS Replication

nfsstat 명령

NFS 서버 및 클라이언트의 상태를 보여주는 명령이다. 각 항목의 의미는 [man nfsstat]페이지를 참고하자.
root@wl # nfsstat
Server rpc:
Connection oriented:
calls      badcalls   nullrecv   badlen     xdrcall    dupchecks  dupreqs
0          0          0          0          0          0          0
Connectionless:
calls      badcalls   nullrecv   badlen     xdrcall    dupchecks  dupreqs
0          0          0          0          0          0          0

Server nfs:
calls     badcalls
0         0
Version 2: (0 calls)
null     getattr  setattr  root     lookup   readlink read     wrcache
0 0%     0 0%     0 0%     0 0%     0 0%     0 0%     0 0%     0 0%
write    create   remove   rename   link     symlink  mkdir    rmdir
0 0%     0 0%     0 0%     0 0%     0 0%     0 0%     0 0%     0 0%
readdir  statfs
0 0%     0 0%
Version 3: (0 calls)
null        getattr     setattr     lookup      access      readlink
0 0%        0 0%        0 0%        0 0%        0 0%        0 0%
read        write       create      mkdir       symlink     mknod
0 0%        0 0%        0 0%        0 0%        0 0%        0 0%
remove      rmdir       rename      link        readdir     readdirplus
0 0%        0 0%        0 0%        0 0%        0 0%        0 0%
fsstat      fsinfo      pathconf    commit
0 0%        0 0%        0 0%        0 0%
Version 4: (0 calls)
null                compound
0 0%                0 0%
Version 4: (0 operations)
reserved            access              close               commit
0 0%                0 0%                0 0%                0 0%
create              delegpurge          delegreturn         getattr
0 0%                0 0%                0 0%                0 0%
getfh               link                lock                lockt
0 0%                0 0%                0 0%                0 0%
locku               lookup              lookupp             nverify
0 0%                0 0%                0 0%                0 0%
open                openattr            open_confirm        open_downgrade
0 0%                0 0%                0 0%                0 0%
putfh               putpubfh            putrootfh           read
0 0%                0 0%                0 0%                0 0%
readdir             readlink            remove              rename
0 0%                0 0%                0 0%                0 0%
renew               restorefh           savefh              secinfo
0 0%                0 0%                0 0%                0 0%
setattr             setclientid         setclientid_confirm verify
0 0%                0 0%                0 0%                0 0%
write               release_lockowner   illegal
0 0%                0 0%                0 0%

Server nfs_acl:
Version 2: (0 calls)
null        getacl      setacl      getattr     access      getxattrdir
0 0%        0 0%        0 0%        0 0%        0 0%        0 0%
Version 3: (0 calls)
null        getacl      setacl      getxattrdir
0 0%        0 0%        0 0%        0 0%

Client rpc:
Connection oriented:
calls      badcalls   badxids    timeouts   newcreds   badverfs   timers
17         0          0          0          0          0          0
cantconn   nomem      interrupts
0          0          0
Connectionless:
calls      badcalls   retrans    badxids    timeouts   newcreds   badverfs
4          1          0          0          0          0          0
timers     nomem      cantsend
1          0          0

Client nfs:
calls     badcalls  clgets    cltoomany
4         1         4         2
Version 2: (3 calls)
null     getattr  setattr  root     lookup   readlink read     wrcache
0 0%     1 33%    0 0%     0 0%     0 0%     0 0%     0 0%     0 0%
write    create   remove   rename   link     symlink  mkdir    rmdir
0 0%     0 0%     0 0%     0 0%     0 0%     0 0%     0 0%     0 0%
readdir  statfs
0 0%     2 66%
Version 3: (0 calls)
null        getattr     setattr     lookup      access      readlink
0 0%        0 0%        0 0%        0 0%        0 0%        0 0%
read        write       create      mkdir       symlink     mknod
0 0%        0 0%        0 0%        0 0%        0 0%        0 0%
remove      rmdir       rename      link        readdir     readdirplus
0 0%        0 0%        0 0%        0 0%        0 0%        0 0%
fsstat      fsinfo      pathconf    commit
0 0%        0 0%        0 0%        0 0%
Version 4: (0 calls)
null                compound
0 0%                0 0%
Version 4: (0 operations)
reserved            access              close               commit
0 0%                0 0%                0 0%                0 0%
create              delegpurge          delegreturn         getattr
0 0%                0 0%                0 0%                0 0%
getfh               link                lock                lockt
0 0%                0 0%                0 0%                0 0%
locku               lookup              lookupp             nverify
0 0%                0 0%                0 0%                0 0%
open                openattr            open_confirm        open_downgrade
0 0%                0 0%                0 0%                0 0%
putfh               putpubfh            putrootfh           read
0 0%                0 0%                0 0%                0 0%
readdir             readlink            remove              rename
0 0%                0 0%                0 0%                0 0%
renew               restorefh           savefh              secinfo
0 0%                0 0%                0 0%                0 0%
setattr             setclientid         setclientid_confirm verify
0 0%                0 0%                0 0%                0 0%
write
0 0%

Client nfs_acl:
Version 2: (1 calls)
null        getacl      setacl      getattr     access      getxattrdir
0 0%        0 0%        0 0%        1 100%      0 0%        0 0%
Version 3: (0 calls)
null        getacl      setacl      getxattrdir
0 0%        0 0%        0 0%        0 0%
Twitter RSS IconTexto 올바른 XHTML 1.0 Transitional 입니다 올바른 CSS입니다!