0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Linuc 202「NFSサーバーの設定と管理」を見てNFSマウントしてみる

Last updated at Posted at 2020-08-30

LinuC 202「2.11.2 NFSサーバーの設定と管理」を読んで、NFSマウントしてみた。

この記事のアジェンダ

  • NFSを構成するportmap, nfsd, mountdプロセスの役割について
  • NFSの設定ファイル (/etc/exports) を編集してみる
  • NFSクライアントから共有領域をmountしてみる

NFSを構成するportmap, nfsd, mountdプロセスの役割について

postmap

  • RPC(Remote Procedure Call)プログラム番号をTCPポート番号に変更するプロセス
  • RPCはN/W上にあるリモートホストの機能を別ホストで使えるようにする仕組み
  • NFSサーバ、NFSクライアント両方で必要なプロセス
  • rpcinfo
    • RPCプログラム番号とTCPポート番号の紐付けを表示する
    • オプション
      • -p 稼働中のRPCサービスのみ表示
# 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  40054  status
    100005    1   udp  20048  mountd
    100024    1   tcp  44991  status
    100005    1   tcp  20048  mountd
    100005    2   udp  20048  mountd
    100005    2   tcp  20048  mountd
    100005    3   udp  20048  mountd
    100005    3   tcp  20048  mountd
    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
    100021    1   udp  34009  nlockmgr
    100021    3   udp  34009  nlockmgr
    100021    4   udp  34009  nlockmgr
    100021    1   tcp  46262  nlockmgr
    100021    3   tcp  46262  nlockmgr
    100021    4   tcp  46262  nlockmgr

program ・・・ RPCプログラム番号
vers ・・・ RPCバージョン
proto ・・・ プロトコル
port ・・・TCP/IPポート番号
service ・・・ サービス名

nfsd

  • ファイルシステムのエクスポートとNFSクライアントからのリクエストを処理するプロセス
  • NFSサーバのみに必要なプロセス

mountd

  • リモートファイルシステムのmount/umountを行うプロセス
  • NFSサーバのみに必要なプロセス
  • portmap, mountdはTCPWrapperでアクセス制御する
/etc/hosts.allow
rpcbind: xxx.xxx.xxx.xxx
mountd: xxx.xxx.xxx.xxx

NFSの設定ファイル (/etc/exports) を編集してみる

/etc/exports

  • NFSサーバで特定のディレクトリを公開することを**エクスポート(export)**という。
    • エクスポートするディレクトリは /etc/exports で設定する
    • オプションで細かいアクセス制御が設定できる
/home/nfs xxx.xxx.xxx.xxx(rw,all_squash)
  • 書式

    • <共有ディレクトリ> \(オプション)
  • 設定オプション

    • ro 読み取り専用でエクスポート (デフォルト)
    • rw 読み書き可能でエクスポート
    • no_root_squash rootアクセス時にroot権限で実行
    • root_squash rootアクセス時に匿名アカウント権限で実行 (デフォルト)
    • all_squash 全てのアクセスで匿名アカウント権限で実行

NFSクライアントからNFSサーバへのアクセス時、NFSクライアントのUIDが使用される。
NFSクライアント-NFSサーバ間でUIDが異なると別ユーザとして認識されるので注意する。
UIDが違うなら、all_squashオプションで匿名アカウントにマッピングされるようにする。

exportfs /etc/exportsの設定反映

# exportfs -ar

showmount NFSサーバでエクスポートしているディレクトリを調べる

# showmount -e buzz
Export list for buzz:
/home/nfs xxx.xxx.xxx.xxx

NFSクライアントから共有領域をmountしてみる

# mount -t nfs xxx.xxx.xxx.xxx:/home/nfs /mnt/nfs/share
# df /mnt/nfs/share
ファイルシス               1K-ブロック    使用   使用可 使用% マウント位置
xxx.xxx.xxx.xxx:/home/nfs    21110400 2923136 17095680   15% /mnt/nfs/share
  • soft mount と hard moutn
    soft mountとhard moutnはNFSサーバがクラッシュしたり、N/Wに障害発生した時の挙動が異なる。
    soft mountの場合は、NFSサーバから応答がないとタイムアウトする。
    hard mountの場合は、NFSから応答があるまで再試行し続ける。

  • soft mount と hard moutnの使い分け
    NFSサーバダウン、N/Wの障害が頻繁に発生する可能性があるならsoft mount
    ただ、中断された処理が起因してファイルシステム障害が発生するリスクがある。
    hard mountを使う場合は、再試行を続けるプログラムを中断するようにintrオプションを指定しておく。
    intrオプションがないとSIGHUPで停止できなくなるリスクがある。

  • FNS固有のmountオプション

    • -o mountオプションを使う宣言オプション
    • bg mountに失敗してもバックグラウンドで再試行
    • fg マウントはフォアグランドで実行
    • soft soft mountで実行
    • hard hard mountで実行
    • intr hard mount時に割り込みを許可
    • retrans soft mount時の再試行回数
    • nolock ファイルロックを行わない
    • rsize=byte数 読み取りブロックサイズ
    • wsize=byte数 書き込みブロックサイズ

rsize, wsizeオプションはチューニングに使えるらしい。
N/W帯域が広い環境であったら、rsize, wsizeの値を上げるとスループットの向上が期待できる。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?