トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS

LinuxとUnix間でのnfsファイル共有について のバックアップソース(No.1)

*LinuxとUnix間でのnfsファイル共有について [#v0e64e0b]

LinuxとUnix間で、ファイル共有したいときがあるじゃないですか。

今、事情があって、ホント共有したいんですよ。

というわけで、今回はLinux側のファイルを公開し、Unix側からmountしてファイル共有させてみます。

両OSのバージョンは以下の通り。
-Linux:RHEL4.5(債権更改DBサーバ)
-Unix :HP-UX11(現行債権DBサーバ)

さてさて、nfsでファイル共有する際には、主に以下の作業が必要となります。
+【Linux】TCP Wrapperによるアクセス制御の設定
--/etc/hosts.allow の設定
--/etc/hosts.deny の設定
+【Linux】共有させるファイルの設定(/etc/exportsの設定)
+【Linux】nfsサービスの起動
+【Unix】nfsクライアントの設定
--/sbin/init.d/nfs.client start を実行
--マウントポイントの作成
--mountコマンドでnfsマウント実行
--接続の確認

まあ、こんなもんです。

そして、別に難しいところはありませんでした。

*1.【Linux】TCP Wrapperによるアクセス制御の設定 [#w8d9aac3]
手元の解説本によれば、
--/etc/hosts.allow
--/etc/hosts.deny
を適切に設定する、と書いてありました。笑

まあ、今回は特に外部に公開するわけでもないので、/etc/hosts.allowに以下の設定を追記します。

 #
 # hosts.allow	This file describes the names of the hosts which are
 #		allowed to use the local INET services, as decided
 #		by the '/usr/sbin/tcpd' server.
 #
 ALL:ALL   ←これを追加

追加した'''ALL:ALL'''は、全部OKって意味です。

また、/etc/hosts.denyについては、特に必要がないと判断し、設定してないです。
 
これで、TCP Wrapperを経由するすべての通信が通るようになりました。

*2.【Linux】共有させるファイルの設定(/etc/exportsの設定) [#md059820]
共有する対象のディレクトリを'''/etc/exports'''ファイルに記述します。

'''/etc/exports'''の記述方法については、別なサイトに譲るとして、今回記述した内容を以下に示します。

 #
 /work/work01 *(rw) ←これを追記 
 

なんと、一行しか追記していない笑

まあ、上記の要領で、Unixに見せたいディレクトリを追記していけば、そのディレクトリを公開できます。

意味としては、
-第1要素:公開するディレクトリ
-第2要素の*:公開する対象のIPアドレス/ホスト名&br;
→つまり、すべてのホストに公開する、という意味
-第2要素の*の後ろ(rw):読み出しと書き込みを許可する、という意味

つまり、先の1分の設定は、'''/work/work01'''ディレクトリについて、'''すべてのホスト'''に対して'''読み書き権限'''を付与する、という意味となります。


*3.【Linux】nfsサービスの起動 [#h2bf3b1f]
exports等の設定が完了したら、いよいよnfsサービスを起動します。

起動については以下のコマンドを実行します。
-service portmap start
-sercvice nfs start

実行結果は以下の通り
 # service portmap start
 portmap を起動中: [  OK  ]
 # sercvice nfs start
 NFS サービスを起動中:  [  OK  ]
 NFS クォータを起動中: [  OK  ]
 NFS デーモンを起動中: [  OK  ]
 NFS mountd を起動中:  [  OK  ]
 Starting RPC idmapd: [  OK  ]
 # 

起動が完了したら、「showmount -e」コマンドで公開されているかを確認します。
 # showmount -e
 Export list for <サーバ名>:
 /work/work01 *
 
おお、「/work/work01」が見れてますね。これで公開は完了です。



*4.【Unix】nfsクライアントの設定 [#af8110fd]
Unixでのnfsクライアント設定は、以下の動作を実施するたけです。
--/sbin/init.d/nfs.client start を実行
--マウントポイントの作成
--mountコマンドでnfsマウント実行
--接続の確認

まず、nfsクライアントを実行します。すると、つれ~と以下の標準出力が出力されます。

 # /sbin/init.d/nfs.client start
     starting NFS CLIENT networking 
 
 killing nfsd
 killing rpc.mountd
     starting up the rpcbind
         rpcbind already started, using pid: 605
     starting up the BIO daemons
         biod(s) already started, using pid(s): 631 630 629 632 633 634 635 636 6
 37 638 639 640 641 642 643 644
     Reading in /etc/exports
     starting up the Status Monitor daemon
         rpc.statd already started, using pid: 653
     starting up the Lock Manager daemon
         rpc.lockd already started, using pid: 659
     starting up the Automount daemon
         automount already started, using pid: 670
     mounting remote NFS file systems ...
     mounting CacheFS file systems ...
     starting NFS SERVER networking 
 
     starting up the rpcbind daemon
         rpcbind already started, using pid: 605
     Reading in /etc/exports
     starting up the mount daemon
         /usr/sbin/rpc.mountd
     starting up the NFS daemons
         /usr/sbin/nfsd 16
     starting up the Status Monitor daemon
         rpc.statd already started, using pid: 653
     starting up the Lock Manager daemon
         rpc.lockd already started, using pid: 659
 

次に、マウントポイントを作成します。
ここでは、ルート直下に「nfs_test」というディレクトリを作成し、マウントポイントとします。

 # cd /
 # mkdir nfs_test

最後に、mountコマンドでLinuxサーバの公開ディレクトリをマウントします。
 # mount 10.132.52.23:/work/work01 /nfs_test

これでマウントできました!

あら、あっさり終了しちゃうのね笑

というわけで、接続テストをします。

 # cd nfs_test
 # ls
 1           lost+found  testdir
 #
 #
 # cd testdir
 # ls
 2
 #
 #
 # touch 3
 #
 #
 # ls
 2  3

ここで、Linux側でファイルが出来たことを確認。
 # ll
 合計 321608
 drw-rw-rw-  2 root root      4096  9月 19 19:47 ./
 drwxr-xr-x  4 root root      4096  9月 19 17:25 ../
 -rw-r--r--  1 root root         0  9月 19 17:31 2
 -rw-rw-r--  1 root sys          0  9月 19 19:23 3

うむ!成功!

なんて簡単なんだ笑

ちなみに、Linux同士のnfsによるファイル共有の場合も同じような感じでいけます。