==Ubuntu NFS構成==
*https://www.codeflow.site/ja/article/how-to-set-up-an-nfs-mount-on-ubuntu-18-04
*https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/7/html/storage_administration_guide/nfs-serverconfig
==コンポーネントのインストール==
===サーバー===
====コンポーネントのインストール====
<pre>
$ sudo apt update
$ sudo apt install nfs-kernel-server
</pre>
===クライアント===
====仮想環境 [[Multipass]] にクライアント [[Ubuntu]] を作成====
*仮想環境 [[Multipass]] にクライアント [[Ubuntu]] を作成する
<pre>
$ multipass launch --mem 2G --disk 15G --name nfs-client
$ multipass sh nfs-client
Welcome to Ubuntu 20.04.1 LTS (GNU/Linux 5.4.0-53-generic x86_64)
ubuntu@nfs-client:~$
</pre>
====コンポーネントのインストール====
<pre>
ubuntu@nfs-client:~$ sudo apt update
ubuntu@nfs-client:~$sudo apt install nfs-common
</pre>
==サーバーでのマウントポイントの作成==
===ディレクトリのエクスポート準備===
<pre>
$ sudo mkdir /var/nfs/general -p
$ ls -al /var/nfs | grep "general"
drwxr-xr-x 2 root root 4096 Nov 23 22:42 general
</pre>
<blockquote>
NFSは、セキュリティ対策として、* client 上の root *操作を `+ nobody:nogroup +`資格情報に変換します。 したがって、これらの資格情報と一致するようにディレクトリの所有権を変更する必要があります。
</blockquote>
<pre>
$ sudo chown nobody:nogroup /var/nfs/general
$ ls -al /var/nfs | grep "general"
drwxr-xr-x 2 nobody nogroup 4096 Nov 23 22:42 general
</pre>
===NFSエクスポートの構成===
*/etc/exportsの編集
*/etc/exports ファイルは、リモートホストにどのファイルシステムをエクスポートするかを制御し、オプションを指定します。以下の構文ルールに従います。
**空白行は無視する。
**コメント行は、ハッシュ記号 (#) で始める。
**長い行はバックスラッシュ (\) を使って折り返す。
**エクスポートするファイルシステムは、それぞれ 1 行で指定する。
**許可するホストの一覧は、エクスポートするファイルシステムの後に空白文字を追加し、その後に追加する。
**各ホストのオプションは、ホスト識別子の直後に括弧を追加し、その中に指定する。ホストと最初の括弧の間には空白を入れない。
<pre>
$ sudo vi /etc/exports
</pre>
*no_subtree_check :サブツリーのチェックを防ぎます
*no_root_squash :デフォルトでは、NFSは* root ユーザーからのリクエストをリモートでサーバー上の非特権ユーザーに変換します。 no_root_squash は特定の共有に対してこの動作を無効にします
<pre>
# /etc/exports: the access control list for filesystems which may be exported
# to NFS clients. See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check)
#
/var/nfs/general *(rw)
/home *(rw,sync,no_root_squash,no_subtree_check)
</pre>
*再起動
<pre>
$ sudo systemctl restart nfs-kernel-server
$ sudo systemctl status nfs-kernel-server
● nfs-server.service - NFS server and services
Loaded: loaded (/lib/systemd/system/nfs-server.service; enabled; vendor preset: enabled)
Active: active (exited) since Mon 2020-11-23 23:11:37 JST; 2s ago
Process: 6405 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
Process: 6406 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS)
Main PID: 6406 (code=exited, status=0/SUCCESS)
11月 23 23:11:36 bombay.local systemd[1]: Starting NFS server and services...
11月 23 23:11:36 bombay.local exportfs[6405]: exportfs: /etc/exports [1]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/var/nfs/general".
11月 23 23:11:36 bombay.local exportfs[6405]: Assuming default behaviour ('no_subtree_check').
11月 23 23:11:36 bombay.local exportfs[6405]: NOTE: this default has changed since nfs-utils version 1.0.x
11月 23 23:11:36 bombay.local exportfs[6405]: exportfs: /etc/exports [2]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/home".
11月 23 23:11:36 bombay.local exportfs[6405]: Assuming default behaviour ('no_subtree_check').
11月 23 23:11:36 bombay.local exportfs[6405]: NOTE: this default has changed since nfs-utils version 1.0.x
11月 23 23:11:37 bombay.local systemd[1]: Finished NFS server and services.
</pre>
====ファイアウォールの設定====
<pre>
$ sudo ufw allow from to any port nfs
</pre>
==クライアントでのマウントポイントの作成==
===mDNSのインストール===
* *.localの名前解決
<pre>
ubuntu@nfs-client:~$ sudo apt install -y avahi-daemon
ubuntu@nfs-client:~$ sudo systemctl start avahi-daemon
ubuntu@nfs-client:~$ sudo systemctl enable avahi-daemon
ubuntu@nfs-client:~$ ping bombay.local
PING bombay.local (192.168.0.47) 56(84) bytes of data.
64 bytes from 192.168.0.47 (192.168.0.47): icmp_seq=1 ttl=64 time=2.31 ms
</pre>
===マウントポイントの作成===
<pre>
ubuntu@nfs-client:/$ sudo mkdir -p /nfs/general
ubuntu@nfs-client:/$ sudo mkdir -p /nfs/home
</pre>
===マウント===
<pre>
ubuntu@nfs-client:/$ sudo mount bombay.local:/var/nfs/general /nfs/general
</pre>
===確認===
<pre>
$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 978M 0 978M 0% /dev
tmpfs 199M 972K 198M 1% /run
/dev/sda1 15G 1.4G 13G 10% /
tmpfs 994M 0 994M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 994M 0 994M 0% /sys/fs/cgroup
/dev/sda15 105M 3.9M 101M 4% /boot/efi
/dev/loop0 56M 56M 0 100% /snap/core18/1932
/dev/loop1 68M 68M 0 100% /snap/lxd/18150
/dev/loop2 31M 31M 0 100% /snap/snapd/9721
tmpfs 199M 0 199M 0% /run/user/1000
bombay.local:/var/nfs/general 228G 69G 148G 32% /nfs/general
</pre>
===起動時にリモートNFSディレクトリをマウント===
*https://linuc.org/study/knowledge/505/
*https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/7/html/storage_administration_guide/nfs-clientconfig#s2-nfs-fstab
*/etc/fstab
*一般的な構文
<pre>
server:/usr/local/pub /pub nfs defaults 0 0
</pre>
<pre>
bombay.local:/var/nfs/general /nfs/general nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0
</pre>
===共有のアンマウント===
<pre>
umount /nfs/general
</pre>