manekineko倉金家ホームページ

趣味の部屋/サーバー構築メモ その4

NFS設定

2014年10月1日
他のマシンの設定確認やデータの移行、バックアップなどのため、まずは従来どおりNFS(Network File System)をつなぎます。


前回NFS4でDomainの設定が異るとファイルなどのユーザ/グループがうまく取得できないことがわかったので、Domainの設定を合わせておきます。今回もNFSのバージョンは4です。

/etc/idmapd.conf
[General]
....
Domain = localdomain
....
ユーザ:グループの名前やIDはすでに一致させてあるので、ユーザマッピングを設定する必要はありません。

NFSはLAN内でのみ使用しますので、/etc/hosts.allow, /etc/hosts.deny をそのように設定します。
/etc/hosts.allow
ALL: 127.0.0.1
ALL: 192.168.
/etc/hosts.deny
portmap:  ALL
lockd: ALL
mountd: ALL
rquotad: ALL
statd: ALL
…NFS4では関係ないようだが。

繋ぐ相手のマシンにはすでに公開設定を施してあります。いちおう確認します。
/etc/exports …相手のマシンの
/etc  192.168.0.0/255.255.0.0(ro,no_root_squash)
/home 192.168.0.0/255.255.0.0(ro,no_root_squash)
/root 192.168.0.0/255.255.0.0(ro,no_root_squash)
no_root_squash はrootアクセスをそのまま受け入れるオプションで、LAN内のみの接続などセキュリティーが確保されていることが前提。

/mnt にマウントポイントを作成。cosmosはつなぐ相手のマシン名。
mnt]# mkdir cosmos.etc cosmos.home cosmos.root

さらにマウント/アンマウント用スクリプトを作ってデスクトップにでもおいておきます。
mountcosmos.sh
#!/bin/bash
mount -t nfs 192.168.0.6:/etc /mnt/cosmos.etc
mount -t nfs 192.168.0.6:/home /mnt/cosmos.home
mount -t nfs 192.168.0.6:/root /mnt/cosmos.root
umountcosmos.sh
#!/bin/bash
umount -t nfs /mnt/cosmos.etc
umount -t nfs /mnt/cosmos.home
umount -t nfs /mnt/cosmos.root
つなぐ相手のマシンはすでにNFSサービスは開始していますので、実際につないでみてOK。
これで設定ファイルやスクリプトなどを現行マシンから引っぱってこれますので今後の設定が楽になります。

引き続きこちらのマシンをNFS公開する設定をします。こちらの /etc/exports にも同様の設定をします。
/etc/exports
/etc  192.168.0.0/255.255.0.0(ro,no_root_squash)
/home 192.168.0.0/255.255.0.0(ro,no_root_squash)
/root 192.168.0.0/255.255.0.0(ro,no_root_squash)

ファイアウォールを設定します。
まだfirewalldコマンドの使い方がよくわからないので「ファイアウォール」GUIツールを使います。
・永続設定でゾーン public のサービス nfs をオン(チェックを入れる)。
  …通常使用するネットワーク接続はディフォルトでpublicゾーンになっている。
・永続設定でサービス nfs の 送信先 IPv4 に 192.168.0.0/16 を設定。
  …LAN内のみアクセスを有効にする。ただしなぜか一回設定すると空にはできない。バグだな。
で、firewalldを再起動。
~]# systemctl restart firewalld

サービスの起動設定をします。
~]# systemctl enable nfs-idmap.service
ln -s '/usr/lib/systemd/system/nfs-idmap.service' '/etc/systemd/system/nfs.target.wants/nfs-idmap.service'
~]# systemctl enable nfs-lock.service
~]# systemctl enable nfs-server.service
ln -s '/usr/lib/systemd/system/nfs-server.service' '/etc/systemd/system/nfs.target.wants/nfs-server.service'
~]# systemctl enable rpcbind.service
となり、必要な起動リンクが作成されました。nfs-lockとrpcbindはディフォルトでオンになっていたようです。

再起動して無事NFSがつながることを確認。OK。