nfs-utils

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page Nfs-utils and the translation is 82% complete.
Other languages:
これと混同しないでください: NTFS.
Resources
This article has some todo items:
  • Review systemd support in article. man nfs.systemd, /etc/nfs.conf, etc.
  • Add ss example above netstat

Network File System (NFS) は、ホストシステムが提供するネットワークアタッチドファイルシステム (エクスポートとも呼ばれます) にクライアントマシンがアクセスできるようにする、ファイルシステムプロトコルです。 NFS は Linux カーネルによってサポートされており、ユーザスペースデーモンとユーティリティは net-fs/nfs-utils パッケージにあります。

インストール

カーネル

NFS サーバサポートは NFS クライアントには不要です。逆も同様で、NFS クライアントサポートは NFS サーバには不要です。inotify サポートは NFSv4 でのみ必要です。NFSv3 はレガシークライアントとの互換性のためだけに必要です。例えば、BusyBox の mount コマンドは NFSv4 に対応していません。

クライアントサポート

クライアントカーネルサポートは、NFS エクスポートを実行するホストに接続する各システムで有効化する必要があります。

カーネル NFS クライアントサポートを有効化する
File systems --->
  [*] Inotify support for userspace
  [*] Network File Systems --->
        <*>   NFS client support
        <*>     NFS client support for NFS version 3
        <*>     NFS client support for NFS version 4
        [*]   NFS client support for NFSv4.1

サーバサポート

サーバカーネルサポートは、NFS エクスポートを提供するシステムでのみ必要です。ローカル上のテスト目的では、サーバ上でも前節で示したクライアントサポートも同様に有効化しておくと役に立つかもしれません。

カーネル NFS サーバサポートを有効化する
File systems --->
  [*] Inotify support for userspace
  [*] Network File Systems --->
        <*>   NFS server support
        [*]     NFS server support for NFS version 3
        [*]     NFS server support for NFS version 4
        [*]       NFSv4.1 server support for Parallel NFS (pNFS)

USE フラグ

USE flags for net-fs/nfs-utils NFS client and server daemons

caps Use Linux capabilities library to control privilege
junction Enable NFS junction support in nfsref
kerberos Add kerberos support
ldap Add ldap support
libmount Link mount.nfs with libmount
nfsv3 Enable support for NFSv2 and NFSv3
nfsv4 Enable support for NFSv4 (includes NFSv4.1 and NFSv4.2)
sasl Add support for the Simple Authentication and Security Layer
selinux !!internal use only!! Security Enhanced Linux support, this must be set by the selinux profile or breakage will occur
tcpd Add support for TCP wrappers
uuid Support UUID lookups in rpc.mountd

Emerge

net-fs/nfs-utils をインストールしてください:

root #emerge --ask net-fs/nfs-utils

設定

サーバ

次の表に、サーバがエクスポートしようとしているファイルシステムを示します:

デバイス マウントディレクトリ 説明
/dev/sdb1 /home ユーザのホームディレクトリを格納するファイルシステム。
/dev/sdc1 /data ユーザのデータを格納するファイルシステム。

仮想ルート

メモ
この記事では、仮想ルートを使用するベストプラクティスの NFSv4 配置を示していますが、仮想ルートを使用せずに必要なディレクトリを直接エクスポートすることも可能です。そうしたい場合は、この節の内容は飛ばして、代わりに exports ファイルを以下のような内容にすることができます:
ファイル /etc/exports
/home    192.0.2.0/24(insecure,rw,sync,no_subtree_check)

エクスポートするファイルシステム群を、単一のディレクトリの下からアクセスできるようにすることがあります。このディレクトリは仮想ルートディレクトリとして知られています:

root #mkdir /export
メモ
この記事では仮想ルートディレクトリとして /export ディレクトリを使用していますが、/nfs/srv/nfs など、好きなディレクトリを使用することができます。

仮想ルートディレクトリ内に、エクスポートしたいファイルシステムのためのディレクトリ (例えば /home/data) を作成してください:

root #mkdir /export/home
root #mkdir /export/data

エクスポートするファイルシステム群を、仮想ルートディレクトリ内の対応するディレクトリからアクセスできるようにする必要があります。これは mount コマンドの --bind オプションによって実現できます:

root #mount --bind /home /export/home
root #mount --bind /data /export/data

上のマウントを永続的なものにするには、/etc/fstab に以下を追記してください:

ファイル /etc/fstab
/home    /export/home    none    bind    0    0
/data    /export/data    none    bind    0    0

エクスポート

クライアントからアクセスできるようにするファイルシステムは /etc/exports 内で指定されます。このファイルは、エクスポートされるディレクトリ、それらのディレクトリへのアクセスが許可されるクライアント、そしてクライアントごとのオプションのリストで構成されます。NFS エクスポートの設定オプションに関するさらなる情報は、man exports を参照してください。

次の表は、以降の設定で使用されているサーバオプションの簡単な説明です:

オプション 説明
insecure サーバは、クライアントリクエストが非特権ポート (1024 より大きい番号のポート) から発せられていることを要求します。このオプションは、エクスポートされたディレクトリを OS X からマウントするとき、または KDE 内で nfs:/ kioslave によってマウントするときには、必須です。デフォルトは特権ポートを使用します。
rw クライアントは、エクスポートされたディレクトリへの読み込みおよび書き込みアクセスを得ます。デフォルトは読み込み専用アクセスを許可します。
sync サーバは、ファイルシステムの変更がストレージにコミットされるまで待ってから、クライアントからのさらなる要求に応答しなくてはなりません。これはデフォルトです。
no_subtree_check サーバは、クライアントから要求されたファイルが適切なファイルシステムおよびエクスポートされたツリー内にあることを検証しません。これはデフォルトです。
crossmnt サーバは、この仮想ルートディレクトリ下にマウントされているファイルシステムを公開します。このオプションを使用しないと、クライアントがこの仮想ルートディレクトリをマウントするときに、ファイルシステムは隠されるでしょう。
fsid=0 このオプションは仮想ルートディレクトリを一意に識別するために必要です。

NFS サーバが開始した後に /etc/exports に変更が加えられた場合、クライアントに変更を伝えるには次のコマンドを実行してください:

root #exportfs -rv
IPv4

この設定はエクスポートされたローカルの共有へのアクセスを許可し、192.0.2.0/24 IP ネットワーク内のクライアントに対してアクセスを許可します。クライアントのアクセスは、単一ホスト (IP アドレスまたは完全修飾ドメイン名) として、NIS netgroup として、またはすべてのクライアントアクセスを許可する * 一文字を使って指定することもできます。

ファイル /etc/exports
/export         192.0.2.0/24(insecure,rw,sync,no_subtree_check,crossmnt,fsid=0)
/export/home    192.0.2.0/24(insecure,rw,sync,no_subtree_check)
/export/data    192.0.2.0/24(insecure,rw,sync,no_subtree_check)
IPv6

IPv6 専用設定。IPv6 プリフィクスは既存の IPv4 ネットワーク設定の後に置くことができます。 上の設定は、エクスポートされたディレクトリへのアクセスを IP ネットワーク、 この場合では 2001:db8:1::/64 によって、許可します。 これらの IP ネットワークは NFS サーバ上のエクスポートされた共有へのアクセスが許可されます:

ファイル /etc/exports
/export         2001:db8:1::/64(insecure,rw,sync,no_subtree_check,crossmnt,fsid=0)
/export/home    2001:db8:1::/64(insecure,rw,sync,no_subtree_check)
/export/data    2001:db8:1::/64(insecure,rw,sync,no_subtree_check)
デュアルスタック構成

NFS サーバ上のエクスポートされた共有へのアクセスが許可される IPv4 および IPv6 ネットワーク、ここでは 192.0.2.0/24 および 2001:db8:1::/64

ファイル /etc/exports
/export         192.0.2.0/24(insecure,rw,sync,no_subtree_check,crossmnt,fsid=0) 2001:db8:1::/64(insecure,rw,sync,no_subtree_check,crossmnt,fsid=0)
/export/home    192.0.2.0/24(insecure,rw,sync,no_subtree_check) 2001:db8:1::/64(insecure,rw,sync,no_subtree_check)
/export/data    192.0.2.0/24(insecure,rw,sync,no_subtree_check) 2001:db8:1::/64(insecure,rw,sync,no_subtree_check)

デーモン

OpenRC

OpenRC では、NFS デーモンは OPTS_RPC_NFSD 変数を利用して設定されます:

ファイル /etc/conf.d/nfs
OPTS_RPC_NFSD="8 -V 3 -V 4 -V 4.1"
systemd

systemd では、NFS デーモンは RPCNFSDARGS 変数を利用して設定されます:

ファイル /etc/conf.d/nfs
RPCNFSDARGS="8 -V 3 -V 4 -V 4.1"

オプション 8 は起動する NFS サーバスレッドの数です。デフォルトでは 1 スレッドしか起動されないので、最適なパフォーマンスのためにはスレッド数を増やすべきです。オプション -V 3-V 4 および -V 4.1 は NFS バージョン 3、4、および 4.1 を有効化します。NFS デーモンの構成オプションに関するさらなる情報については man nfsd を参照してください。NFS メジャーバージョン間の技術的な差異は wikipedia の記事で説明されています

サービス

OpenRC

NFS サーバを開始するには:

root #rc-service nfs start
 * Starting rpcbind ...                                                   [ ok ]
 * Starting NFS statd ...                                                 [ ok ]
 * Starting idmapd ...                                                    [ ok ]
 * Exporting NFS directories ...                                          [ ok ]
 * Starting NFS mountd ...                                                [ ok ]
 * Starting NFS daemon ...                                                [ ok ]
 * Starting NFS smnotify ...                                              [ ok ]

上の出力は、他の多数のサービスも nfs サービスとあわせて開始されていることを示しています。すべての NFS サービスを停止するには、rpcbind サービスを停止してください:

root #rc-service rpcbind stop

ブート時に NFS サーバを開始するには:

root #rc-update add nfs default
systemd

NFS サーバを開始するには:

root #systemctl start rpcbind nfs-server

ブート時に NFS サーバを開始するには:

root #systemctl enable rpcbind nfs-server

クライアント

サービス

OpenRC

エクスポートされたディレクトリをマウントできるようにするためには、NFS クライアントを開始してください:

root #rc-service nfsclient start
 * Starting rpcbind                                                       [ ok ]
 * Starting NFS statd                                                     [ ok ]
 * Starting NFS sm-notify                                                 [ ok ]

ブート時に NFS クライアントを開始するには:

root #rc-update add nfsclient default

systemd

エクスポートされるディレクトリをマウントしようとしていることを systemd が検出したとき、nfs-client サービスは自動的に開始されるでしょう。

エクスポートされたディレクトリをマウントする

メモ
以下のコマンドと設定ファイルでは NFS サーバを表すために IPv4 アドレス 192.0.2.1 および IPv6 アドレス 2001:db8:1::1 を使用しています。

エクスポートされたディレクトリをマウントしてください:

root #mount 192.0.2.1:/home /home
root #mount 192.0.2.1:/data /data

上のマウントを永続的なものにするには、/etc/fstab に以下を追加してください:

ファイル /etc/fstab
192.0.2.1:/home    /home    nfs    rw,_netdev    0    0
192.0.2.1:/data    /data    nfs    rw,_netdev    0    0


root #mount 192.0.2.1:/home -t nfs4 -o _netdev,rsize=1048576,wsize=1048576,vers=4

The virtual root directory can be mounted instead of each individual exported directory. This will make all exported directories available to the client:

root #mount 192.0.2.1:/ /mnt

上のマウントを永続的なものにするには、/etc/fstab に以下を追加してください:

ファイル /etc/fstab
192.0.2.1:/        /mnt     nfs    rw,_netdev    0    0

When using /etc/fstab to mount the exported directories, add the netmount service to the default runlevel:

root #rc-update add netmount default
メモ
It will probably be necessary to specify the network management dependencies in /etc/conf.d/netmount.

If the NFS server or client support NFSv3 only, the full path to the exported directory (e.g. /export/home or /export/data) needs to be specified when mounting:

root #mount 192.0.2.1:/export/home /home
root #mount 192.0.2.1:/export/data /data

The same applies when mounting the virtual root directory:

root #mount 192.0.2.1:/export /mnt

IPv6 ネットワーク上にエクスポートされたディレクトリをマウントするときは、IPv6 NFS サーバアドレスを角かっこで囲ってください:

root #mount [2001:db8:1::1]:/home /home
root #mount [2001:db8:1::1]:/data /data

リンクローカル IPv6 アドレスをマウントするときは、出て行くためのローカルネットワークインターフェースも指定しなくてはなりません:

root #mount [fe80::215:c5ff:fb3e:e2b1%eth0]:/home /home
root #mount [fe80::215:c5ff:fb3e:e2b1%eth0]:/data /data

NFSv4 を使用する場合、仮想ルートディレクトリはサーバの構成によってはむしろ「不可視」にすることができます; 相対パスを使用する必要があるかもしれません:

root #mount -t nfs4 192.0.2.1:home /home
root #mount -t nfs4 192.0.2.1:data /data
重要
NFSv4 を介した大きなファイルの I/O は、読み込みおよび書き込みの最大サイズを 1024^2 バイト (1MB) に増加させる以下のオプションによって、*大幅に* 改善できます。
root #mount 192.0.2.1:/home /home rsize=1048576,wsize=1048576,vers=4

永続化のためには:

ファイル /etc/fstab
192.0.2.1:/data   /data nfs4 _netdev,rw,rsize=1048576,wsize=1048576,vers=4

Kerberos

It is possible to identify NFS client using Kerberos GSS. This will require a few modifications. In the following instruction, it is supposed that Kerberos is already installed on the same server as NFS (which hostname is server.domain.tld) and that the client (client.domain.tld) is able to kinit to it. The Kerberos default realm it DOMAIN_REALM.TLD.

First, enable the following kernel option (CONFIG_RPCSEC_GSS_KRB5) for both server and client. Note that this option may not appear if all cryptographic dependencies are not selected. See kernel option dependencies for more information:

カーネル Enabling Kerberos for RPC
File systems --->
  [*] Network File Systems --->
        <*>   Secure RPC: Kerberos V mechanism

Then, create principals for the NFS service for both the server and the client. On the server, execute:

root #kadmin.local add_principal -randkey nfs/server.domain.tld
root #kadmin.local add_principal -randkey nfs/client.domain.tld

Each computer must have its password saved in a local keytab. The easiest way to do it is (on the server):

root #kadmin.local ktadd nfs/server.domain.tld
root #kadmin.local ktadd -k /root/krb5.keytab nfs/client.domain.tld

and then transfer the /root/krb5.keytab to the client, with the name /etc/krb5.keytab. Note that the file should be owned by root with 0600 mode.

The service rpc.gssd must run at client side. The following line must appear in /etc/conf.d/nfsclient of the client:

ファイル /etc/conf.d/nfsclient
rc_need="!rpc.statd rpc.gssd"

The services rpc.idmapd and rpc.svcgssd must run at server side. The following line must appear in /etc/conf.d/nfs of the server:

ファイル /etc/conf.d/nfs
NFS_NEEDED_SERVICES="rpc.idmapd rpc.svcgssd"

The rpc.idmapd service must be correctly configured (on the server):

ファイル /etc/idmapd.conf
[General]
 
Domain = domain.tld
Local-Realms = DOMAIN_REALM.TLD

Add sec=krb5 to the export options.

ファイル /etc/exports
/home    192.0.2.0/24(insecure,rw,sync,no_subtree_check,sec=krb5)

It is also possible to increase security with sec=krb5i (user authentication and integrity checking) or even sec=krb5p (user authentication, integrity checking and NFS traffic encryption). The more security, the more resources are needed.

The same option must be added to the mount command at client side.

トラブルシューティング

  • Verify that the NFS server is running and listening for connections:
root #netstat -tupan | egrep 'rpc|Active|Proto'
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:34950           0.0.0.0:*               LISTEN      1891/rpc.statd
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1875/rpcbind
udp        0      0 0.0.0.0:111             0.0.0.0:*                           1875/rpcbind
udp        0      0 0.0.0.0:57655           0.0.0.0:*                           1891/rpc.statd
udp        0      0 0.0.0.0:774             0.0.0.0:*                           1875/rpcbind
udp        0      0 0.0.0.0:795             0.0.0.0:*                           1891/rpc.statd
  • Verify which NFS daemons are running:
root #rpcinfo -p
   program vers proto   port  service
    100000    4   tcp    111  portmapper
    100000    3   tcp    111  portmapper
    100000    2   tcp    111  portmapper
    100000    4   udp    111  portmapper
    100000    3   udp    111  portmapper
    100000    2   udp    111  portmapper
    100024    1   udp  57655  status
    100024    1   tcp  34950  status
    100003    2   tcp   2049  nfs
    100003    3   tcp   2049  nfs
    100003    4   tcp   2049  nfs
    100003    2   udp   2049  nfs
    100003    3   udp   2049  nfs
    100003    4   udp   2049  nfs
    100021    1   udp  44208  nlockmgr
    100021    3   udp  44208  nlockmgr
    100021    4   udp  44208  nlockmgr
    100021    1   tcp  44043  nlockmgr
    100021    3   tcp  44043  nlockmgr
    100021    4   tcp  44043  nlockmgr
  • List the exported directories from the NFS server:
root #exportfs -v
/export       	192.0.2.0/24(rw,wdelay,crossmnt,insecure,root_squash,no_subtree_check,fsid=0,sec=sys,no_all_squash)
/export/home  	192.0.2.0/24(rw,wdelay,insecure,root_squash,no_subtree_check,sec=sys,no_all_squash)
/export/data  	192.0.2.0/24(rw,wdelay,insecure,root_squash,no_subtree_check,sec=sys,no_all_squash)
  • List the current open connections to the NFS server:
user $netstat -tn | egrep '2049|Active|Proto'
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 192.0.2.1:2049       192.0.2.10:884        ESTABLISHED
  • Verify that the exported directories are mounted by the NFS client:
user $netstat -tn | egrep '2049|Active|Proto'
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 192.0.2.10:997        192.0.2.1:2049        ESTABLISHED

Unresponsiveness of the system

The system may become unresponsive during shutdown when the NFS client attempts to unmount exported directories after udev has stopped. To prevent this a local.d script can be used to forcibly unmount the exported directories during shutdown.

Create the file nfs.stop:

ファイル /etc/local.d/nfs.stop
/bin/umount -a -f -t nfs,nfs4

Set the according file bits:

root #chmod a+x /etc/local.d/nfs.stop

関連項目

  • Samba — a re-implementation of the SMB/CIFS networking protocol, a Microsoft Windows alternative to Network File System (NFS).

外部資料