0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

NFSの設定方法(Ubuntu22.04、CentOS Stream9)

Posted at

Ubuntu22.04の場合(NFSv4に限定)

詳しくはこちらを参照

サーバー側

インストールとサービス起動

sudo apt install nfs-kernel-server
sudo systemctl start nfs-kernel-server.service

/etc/exportsに設定を記載

/etc/exports
# directory_to_share    host(share_option1,...,share_optionN)
/test              192.168.0.0/28(rw,sync,no_root_squash,no_subtree_check)

hostについて
single host: 例 example.hostname.com,192.168.0.1
wildcards: 例 *.hostname.com(IPアドレスには使用不可)
IPnetworks: 例 192.168.0.0/24

share_optionについて

option 説明
ro 読み取りのみ
rw 読み取りと書き込み可能
sync 同期
async 非同期
no_root_squash クライアントがrootの時にroot権限でファイルを編集できないようにする
no_subtree_check サブツリーのチェックを無効

設定を反映

sudo exportfs -ar

ポート開放

ポート2049/tcpを使用するのでufwを起動している場合はポートを開く

sudo ufw status # ステータス確認
sudo ufw allow nfs
sudo ufw allow from 192.168.0.0/24 to any port nfs #ipアドレスでも制限する

クライアント側

インストール

sudo apt install nfs-common

手動マウント

sudo mkdir /opt/example
sudo mount example.hostname.com:/srv /opt/example

※マウントするディレクトリがあること、そのディレクトリにはファイル、ディレクトリを入れないこと。

設定ファイル/etc/fstabに記入してマウント

/etc/fstab
# host:dir  mountPoint  FileSystemName mountOption dumpフラグ ブート時にfsckがチェックする順序
example.hostname.com:/test /opt/example nfs rw,soft,intr 0 0
  • host: マウントしたいサーバー
  • dir: サーバーが提供しているディレクトリ
  • mountPoint: クライアント側でマウントしたい位置を指定。上記の例ではtestディレクトリとexampleディレクトリが対応する。
  • FileSystemName: nfsと記入
  • mountOption:
    • rsize=n: NFS サーバからファイルを読み込む際に、 NFS が用いるバッファのバイト数 を指定する。(1024)
    • wsize=n: NFS サーバにファイルを書き込む際に、 NFS が用いるバッファのバイト数を 指定する。(1024)
    • timeo=n: タイムアウト後の再送をおこなうまでの時間
    • rw=read-wirte
    • ro=read-only
    • soft=NFS へのファイル操作がメジャータイムアウトとなった場合、呼び出したプロ グラムに対し I/O エラーを返す。
    • hard=NFS へのファイル操作がメジャータイムアウトとなった場合、コンソールに "server not responding"と表示し、ファイル操作を無期限に再試行し続ける。(defalt)
    • intr=timeout時にファイル操作の中断を許可する。
    • 詳しくはman mountman nfs
  • dumpフラグ: dumpコマンドでバックアップする=1,しない=0。(nfsはサーバ側で行うので0)
  • ブート時にfsckがチェックする順序: 0の場合はチェックしない。(nfsでは必要ないので0)

autofsで自動マウント

autofsをインストール

sudo apt install autofs

autofsの設定ファイル

/etc/auto.master
+auto.master #マウントポイントの内容をautofsサービス以外で変更不可にする。

※デフォルトのまま

/etc/auto.master.d/XXXX.autofs
/- /etc/auto.master.d/auto.XXXX

/でマウントポイント設定し、auto.XXXXでそこからの相対パスを設定。

※XXXXはわかりやすいの文字列

/etc/auto.master.d/auto.XXXX
/opt/example -rw,soft,intr "host":/test

サービス起動

sudo systemctl start autofs.service

CentOS Stream9の場合(NFSv4に限定)

詳しくはこちら

サーバー側

インストールとサービス起動

詳しくはこちら

su -
dnf install nfs-utils
systemctl start nfs-server.service

/etc/exportsに設定を記載

/etc/exports
# directory_to_share    host(share_option1,...,share_optionN)
/test              192.168.0.0/28(rw,sync,no_root_squash,no_subtree_check)

hostについて
single host: 例 example.hostname.com,192.168.0.1
wildcards: 例 *.hostname.com(IPアドレスには使用不可)
IPnetworks: 例 192.168.0.0/24

share_optionについて

option 説明
ro 読み取りのみ
rw 読み取りと書き込み可能
sync 同期
async 非同期
no_root_squash クライアントがrootの時にroot権限でファイルを編集できないようにする
no_subtree_check サブツリーのチェックを無効

設定を反映

sudo exportfs -ar

ポート開放

ポート2049/tcpを使用するのでfirewalldを起動している場合はポートを開く

firewall-cmd --list-all #現在の設定を見る
firewall-cmd --permanent --add-service nfs
firewall-cmd --reload

クライアント側

インストール

dnf install nfs-utils

手動マウント

sudo mkdir /opt/example
sudo mount example.hostname.com:/srv /opt/example

※マウントするディレクトリがあること、そのディレクトリにはファイル、ディレクトリを入れないこと。

設定ファイル/etc/fstabに記入してマウント

/etc/fstab
# host:dir  mountPoint  FileSystemName mountOption dumpフラグ ブート時にfsckがチェックする順序
example.hostname.com:/test /opt/example nfs rw,soft,intr 0 0
  • host: マウントしたいサーバー
  • dir: サーバーが提供しているディレクトリ
  • mountPoint: クライアント側でマウントしたい位置を指定。上記の例ではtestディレクトリとexampleディレクトリが対応する。
  • FileSystemName: nfsと記入
  • mountOption:
    • rsize=n: NFS サーバからファイルを読み込む際に、 NFS が用いるバッファのバイト数 を指定する。(1024)
    • wsize=n: NFS サーバにファイルを書き込む際に、 NFS が用いるバッファのバイト数を 指定する。(1024)
    • timeo=n: タイムアウト後の再送をおこなうまでの時間
    • rw=read-wirte
    • ro=read-only
    • soft=NFS へのファイル操作がメジャータイムアウトとなった場合、呼び出したプロ グラムに対し I/O エラーを返す。
    • hard=NFS へのファイル操作がメジャータイムアウトとなった場合、コンソールに "server not responding"と表示し、ファイル操作を無期限に再試行し続ける。(defalt)
    • intr=timeout時にファイル操作の中断を許可する。
    • 詳しくはman mountman nfs
  • dumpフラグ: dumpコマンドでバックアップする=1,しない=0。(nfsはサーバ側で行うので0)
  • ブート時にfsckがチェックする順序: 0の場合はチェックしない。(nfsでは必要ないので0)

autofsで自動マウント

autofsをインストール

dnf install autofs

autofsの設定ファイル

/etc/auto.master
+auto.master #マウントポイントの内容をautofsサービス以外で変更不可にする。

※デフォルトのまま

/etc/auto.master.d/XXXX.autofs
/- /etc/auto.master.d/auto.XXXX

/でマウントポイント設定し、auto.XXXXでそこからの相対パスを設定。

※XXXXはわかりやすいの文字列

/etc/auto.master.d/auto.XXXX
/opt/example -rw,soft,intr "host":/test

サービス起動

systemctl start autofs.service
0
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?