OS X El Capitan <-> NFS Server on CentOS 7 64bit
必要に迫られ,自VPSのCentOS 7上にNFSサーバを用意した.そのときの備忘録として,手順および詰まった点を共有する.
目的
- Mac OS X El Capitanからマウント出来るNFSサーバを構築
- automounterの機能を使ったマウントも可能とする
作業手順
パッケージのインストール
$ sudo yum install nfs-utils
NFSサーバの設定
自ドメインの登録
/etc/idmapd.conf
を編集する.5行目のDomainの値を自ドメインにする.
$ sudo cp /etc/idmapd.conf /etc/idmapd.conf.org $ sudo vi /etc/idmapd.conf Domain = YOUR-SERVER-DOMAIN-NAME $ diff /etc/idmapd.conf /etc/idmapd.conf.org 5c5 < Domain = YOUR-SERVER-DOMAIN-NAME --- > #Domain = local.domain.edu
マウントポイントの設定
/etc/exports
を編集する.ここでは,/imports
を外部マウント可能なディレクトリポイントにする.
マウントに関する詳しい設定オプションは,man 5 exports
を参照すること.
$ sudo mkdir /imports $ touch /etc/exports $ vi /etc/exports /imports *(insecure) $
- Macからマウントする場合は,
insecure
オプションが必要 /etc/exports
のファイルは,最後に改行を入れること
バージョンの指定
Macにおけるmount
コマンドは,NFSのバージョン4でマウント可能だが,automounterの方はNFSのバージョン4ではマウントが出来ない.
CentOS 7で導入したNFSサーバは,デフォルトではバージョン4で通信を行うため,明示的にバージョンを下げる必要がある.
/etc/sysconfig/nfs
のRPCNFSDARGS
を書き換える.
$ sudo cp /etc/sysconfig/nfs{,.org} $ sudo vi /etc/sysconfig/nfs # ... RPCNFSDARGS="-N4 -N4.1 -V3" # ...
-N4 -N4.1
は,4および4.1のバージョンを使用しないという意味-V3
は,バージョン3で通信するという意味
ファイアウォールの設定(firewalldを有効にしてる場合)
add-service
を使い,NFS用のポートを開けた場合,TCPのみしか開いてくれない.
automounterではUDPを使うため,下記のどちらかの対応を要する.
ここでは,前者の対応をする.
/usr/lib/firewalld/services
以下にfirewalld
で使用される各サービスの定義ファイルが存在する.
$ sudo cp /usr/lib/firewalld/services/nfs.xml{,.org} $ sudo vi /usr/lib/firewalld/services/nfs.xml # 追記 # ... <port protocol="udp" port="2049"/> # ... $ $ sudo cat /usr/lib/firewalld/services/nfs.xml <?xml version="1.0" encoding="utf-8"?> <service> <short>NFS4</short> <description>The NFS4 protocol is used to share files via TCP networking. You will need to have the NFS tools installed and properly configure your NFS server for this option to be useful.</description> <port protocol="tcp" port="2049"/> <port protocol="udp" port="2049"/> </service> $ $ sudo firewall-cmd --permanent --add-service=nfs $ sudo firewall-cmd --permanent --add-service=mountd $ sudo firewall-cmd --permanent --add-service=rpc-bind $ sudo firewall-cmd --reload
NFSサーバの起動
$ sudo systemctl start rpcbind $ sudo systemctl start nfs
MacからのNFSサーバのディレクトリをマウント
mount
コマンドを利用して特定のディレクトリにマウントする方法と,automounterの機能を使い/net
以下にディレクトリをオートマウントする方法を下記に記す.
$ mkdir ~/mnt $ sudo mount_nfs YOUR-SERVER-DOMAIN-NAME:/imports ~/mnt $ cd /net/YOUR-SERVER-DOMAIN-NAME/imports/
参考
- http://www.server-world.info/query?os=CentOS_7&p=nfs
- http://qiita.com/tanuki-project/items/5c706b2eab6e7eed71fd
- http://blog.radler.jp/2015/08/31/vsphere-home-lab-%E5%90%91%E3%81%91%E3%81%AE-centos-7-x-nfs-server/
- https://access.redhat.com/documentation/ja-JP/Red_Hat_Enterprise_Linux/6/html/Storage_Administration_Guide/s2-nfs-nfs-firewall-config.html
- http://unix.stackexchange.com/questions/243756/nfs-servers-and-firewalld
- https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-using-firewalld-on-centos-7