源地址:http://space.itpub.net/751371/viewspace-748119
linux下,可以将另外一个远程服务器的磁盘目录,通过nfs、portmat服务,mount为本地目录,当做本服务器的一个本地目录来使用。方法如下:
一、启动服务器端服务
在源服务器端启动nfs和portmap服务:
[root@appserver ~]# service nfs start
启动NFS服务: [确定]
关掉NFS配额: [确定]
启动NFS守护进程: [确定]
启动NFS mountd: [确定]
[root@appserver ~]# service portmap start
启动portmap服务: [确定]
通过ntsysv,把nfs和portmap服务加到自启动服务中。
二、服务器端配置文件
在源服务器编辑配置文件/etc/exports。
[root@appserver~]# vi /etc/exports
/files 192.168.1.40(rw)
/files 192.168.1.23(ro)
含义:共享/files目录给IP地址为192.168.1.23的客户端。
这句话有三部分:
/files服务器共享的目录。
192.168.1.23允许这个ip访问该目录
rw读取权限
ro只读权限
三、重启服务器端服务
配置好后重启源服务器端的nfs服务。
[root@appserver ~]# service nfs restart
关闭NFS mountd: [确定]
关闭NFS守护进程: [确定]
关闭NFS quotas: [确定]
关闭NFS服务: [确定]
启动NFS服务: [确定]
关掉NFS配额: [确定]
启动NFS守护进程: [确定]
启动NFS mountd: [确定]
四、启动客户端portmap服务
[root@wh ~]#service portmap start
Starting portmap: [ OK ]
五、在客户端mount远程文件夹
[root@wh ~]# mkdir / files
[root@wh ~]# mount -t nfs 192.168.1.8:/ files /files
mount好之后,到客户端的/files目录下,即可看到服务器端/files下的所有文件,不过因为我们只赋予了只读权限,所以这里的文件只能读,不能写。
注释:
mount -t nfs:-t指定格式为nfs。
192.168.1.8:/ files:服务器地址+共享的目录,也可以用机器名代替。
/ files:客户端本机mount的目录。
六、补充
1、服务端和客户端都需要开启portmap服务。RCP是nfs mount和umount时通信的方式。
2、假如客户端portmap没有启动,mount时,会非常慢,最终会失败。umount时,即使本地的portmap是关闭的,也能umount成功。
3、挂载完成后,服务端的portmap停止后,nfs仍然工作正常,但是umout财会提示:not found / mounted or server not reachable。重启服务器的portmap也无济于事。
4、假如服务端的portmap重启了,那么nfs也要跟着重启,否则nfs工作仍然是不正常的。
5、假如服务端nfs关闭(IP是通的),这时客户端会无法umount,这时使用umount -f /nfs一般能成功,当服务端死机时,umount -f /nfs有可能会失败,这时可以使用umount -l /nfs。
最终建议:
1、使用NFS,就要使用portmap,NFS严重依赖于portmap,所以不要试图去停止portmap服务。
2、当不能umount /nfs分区时,试着使用umount -f /nfs,一般都能成功。
3、当umount -f /nfs不能umount时,可以试试umount -l /nfs,umount -l是最终级的umount。