NFSサーバの構築・管理 202

/ LPIC / Comment[0]

NFS(Network File System)はSunMicrosystem社で開発されたファイル共有ソフトウェアでUNIX版SMBといったところです。
NFSはローカルディレクトリのマウント操作をネットワークレベルに拡張したもので、同セグメント上のホスト間でディレクトリを共有することにより
アプリケーションやデータなどのリソースの共有が可能となり、データの一元管理やディスクスペースの節約などを実現できます。


NFSv3のデーモン


NFSv3サーバでは以下のデーモンが稼動します。

  • mountd マウント要求を受ける
  • nfsd マウント後のファイルアクセス
  • portmap RPCプログラム番号とポート番号のマッピング情報を提供

NFSv4ではportmapもmountdも廃止されてポートが2049固定になりました。


/etc/exports


エキスポートするディレクトリの指定は/etc/exportsに記述します。
スペースが区切り文字として認識されるため、カンマの後などにスペースを入れたくなっても入れてはいけません。

書式: ディレクトリ ホスト(オプション,オプション) ホスト(オプション,オプション)

オプション
  • ro リードオンリー
  • rw 読み書き許可
  • root_squash root権限のアクセスをanonymousユーザでのアクセスにマップ
  • no_root_squash root権限でのアクセスを許可
  • all_squash 全てのアクセスをanonymous uid/gidにマップ
  • anonuid=uid squash時にマップするuidを指定
  • anongid=gid squash時にマップするgidを指定
  • sync 同期モード
  • async 非同期モード

例:
/storage  10.0.0.1(rw,sync) 10.0.0.2(ro)
/share/storage 10.0.0.0/24(rw,sync,no_root_squash)
/share/public *(ro)
/share/work @workgroup(rw) #/etc/netgroupが参照される

exportfsコマンド


エクスポート、アンエクスポートを実行するにはexportfsコマンドを使用します。
オプションをつけずに実行するとエクスポートしているディレクトリ一覧が表示されます。
/etc/exportsを基にエクスポート
# exportfs -a

/etc/exportsを基に再エクスポート
# exportfs -r

指定ディレクトリをエクスポート
# exportfs -o ro *:/pub

指定ディレクトリをアンエクスポート
# exportfs -u /pub

全てのディレクトリをアンエクスポート
# exportfs -au

/etc/netgroup


/etc/exportsでホスト名に@グループ名とした場合は/etc/netgroupが参照されます。
書式:
グループ名 (IPアドレス,ユーザー名,NISドメイン名)
カンマは省略できません。
workgroup (10.0.0.1,user,) (10.0.0.2,,) (10.0.0.3,,) (10.0.0.4,,)

nfsstatコマンド


nfsstatコマンドによりNFSサーバの統計を表示することが出来ます。

構文: nfsstat [オプション]

オプション:
  • -s サーバの統計表示
  • -c クライアントの統計表示
  • -n NFSの統計表示
  • -r RPCの統計表示
  • -o 指定したファシリティの統計を表示
    • net ネットワーク層の統計表示
    • fh ファイルハンドルキャッシュの統計表示
    • rc サーバー応答キャッシュの統計表示
    • all 全て表示

サーバーの統計表示
# nfsstat -s
Server rpc stats:
calls badcalls badclnt badauth xdrcall
1072 0 0 0 0

Server nfs v3:
null getattr setattr lookup access readlink
9 100% 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%

Server nfs v4:
null compound
12 1% 1051 98%

Server nfs v4 operations:
op0-unused op1-unused op2-future access close commit
0 0% 0 0% 0 0% 28 0% 2 0% 1 0%
create delegpurge delegreturn getattr getfh link
0 0% 0 0% 0 0% 996 33% 35 1% 0 0%
lock lockt locku lookup lookup_root nverify
0 0% 0 0% 0 0% 31 1% 0 0% 0 0%
open openattr open_conf open_dgrd putfh putpubfh
3 0% 0 0% 1 0% 0 0% 1007 34% 0 0%
putrootfh read readdir readlink remove rename
12 0% 0 0% 1 0% 0 0% 0 0% 0 0%
renew restorefh savefh secinfo setattr setcltid
4 0% 0 0% 0 0% 9 0% 1 0% 14 0%
setcltidconf verify write rellockowner bc_ctl bind_conn
14 0% 0 0% 801 27% 0 0% 0 0% 0 0%
exchange_id create_ses destroy_ses free_stateid getdirdeleg getdevinfo
0 0% 0 0% 0 0% 0 0% 0 0% 0 0%
getdevlist layoutcommit layoutget layoutreturn secinfononam sequence
0 0% 0 0% 0 0% 0 0% 0 0% 0 0%
set_ssv test_stateid want_deleg destroy_clid reclaim_comp
0 0% 0 0% 0 0% 0 0% 0 0%

ネットワーク層の統計表示
# nfsstat -o net
Server packet stats:
packets udp tcp tcpconn
1076 0 1076 21

全ての統計情報を表示
# nfsstat -o all
Server packet stats:
packets udp tcp tcpconn
1886 0 1886 21

Server rpc stats:
calls badcalls badclnt badauth xdrcall
1886 0 0 0 0

Server reply cache:
hits misses nocache
0 1631 255

Server file handle cache:
lookup anon ncachedir ncachedir stale
0 0 0 0 0

Server nfs v3:
null getattr setattr lookup access readlink
9 100% 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%

Server nfs v4:
null compound
12 0% 1865 99%

Server nfs v4 operations:
op0-unused op1-unused op2-future access close commit
:


ここからクライアント側です。

NFSサーバディレクトリのマウント


mountコマンドを使います。-t nfsは省略可能ですが、お好みでsyncやnoatimeなどを付けてもいいと思います。
# mount 10.0.1.2:/share/storage /mnt
# mount -o async,noatime 10.0.1.2:/share/works /mnt

NFSの/etc/fstabの書式


例:
#ホスト:/dir  /mntpoint  nfs  非同期,更新日時を記録しない,ユーザにマウント許可  dump無効  fsck無効
10.0.1.2:/share/work /mnt nfs async,noatime,user 0 0

syncの場合、ネットワークの切断が起きた場合、復帰するまでファイルマネージャーやlsなどがハングしますがデータの整合性が失われるリスクは低めです。
逆にasyncの場合はネットワークの切断によりデータの整合性が失われるリスクはありますが、比較的高速になります。

showmountコマンド


NFSサーバがエクスポートしているディレクトリを表示できます。--exportfs=-e
# showmount --exportfs 10.0.1.2
Export list for 10.0.1.2:
/share/public *
/share/work @workgroup
/share/storage 10.0.0.0/24

rpcinfoコマンド


RPCサービスに関する情報を表示するコマンドです。
NFSではrpcによってポート番号をマッピングしているため、このコマンドによりNFSのポート番号を知ることが出来ます。
ほとんどの環境で2049で動いているため意味はありませんが一応。
# rpcinfo -p 10.0.1.2|grep nfs
    100003    3   tcp   2049  nfs
100003 4 tcp 2049 nfs
100227 3 tcp 2049 nfs_acl
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100227 3 udp 2049 nfs_acl
関連記事

コメント

:
:
:
:
:
管理人のみ表示を許可