NFS网络文件系统的实现

原理图如下:

NFS网络文件系统的实现

30.120nfs server 30.100 client

1.[[email protected] ~]# rpcinfo -p (查看自己的rpc

   程序 版本 协议   端口

    100000    2   tcp    111  portmapper

    100000    2   udp    111  portmapper

    100024    1   udp    866  status

100024    1   tcp    869  status

[[email protected] ~]# rpcinfo -p 192.168.30.100 (查看对方的)

2.编译共享的清单在server

[[email protected] ~]# mkdir /hua (物理路径和共享名是一样的)

[[email protected] ~]# vim /etc/exports 

/hua  192.168.30.0/24(ro)  (要实现可写,必须是网络权限和本地权限都要有可写的操作)

   物理文件夹  来源(权限,参数)

   /public     *(ro)  1.1.1.1(rw,sync) *.abc.com(ro)  192.168.1.0/24(ro)

[[email protected] ~]# rpm -qa |grep nfs (确定已经安装此服务,默认安装)

[[email protected] ~]# service nfs start

[[email protected] ~]# chkconfig nfs on

[[email protected] ~]# rpcinfo -p

NFS网络文件系统的实现

[[email protected] ~]# exportfs -rv (对以后配置导出详细信息)

exporting 192.168.30.0/24:/hua

3.客户机测试是否可以访问

需要[[email protected] ~]# rpcinfo -p 确定客户机已经开启了这个服务

然后看是否有权限访问

[[email protected] ~]# showmount -e 192.168.30.120 -e表示对方的exports文件)

Export list for 192.168.30.120:

/hua 192.168.30.0/24

4.如何把共享文件挂载到本地

[[email protected] ~]# mkdir /mnt/hua

[[email protected] hua]# mount 192.168.30.120:/hua /mnt/hua/ (和smaba有些不一样)

[[email protected] hua]# mount 就可以看到了

[[email protected] hua]# cd /mnt/hua/ 就可以看到server共享的东西了

5.如何实现开机自动的挂载

[[email protected] hua]# vim /etc/fstab

NFS网络文件系统的实现

客户机测试

[[email protected] hua]# umount /mnt/hua/

umount: /mnt/hua: device is busy

umount: /mnt/hua: device is busy   (出错,主要是你现在已经在这个目录了,需要退出这个目录)

[[email protected] hua]# fuser -v /mnt/hua/ (查看哪个用户在这个目录下)

[[email protected] hua]# fuser -km /mnt/hua  (强制杀死在这个目录下的人)

[[email protected] ~]# mount -a

[[email protected] ~]# mount 就可以看到了

6.因为nfs有一个status状态,如果经常连接着而不做任何事,这样是非常消耗资源的,为了解决这个问题,需要一个自动auto服务,超过一定的时间挂断,要想在连接,hia可以直接连接上。

[[email protected] ~]# rpm -qa |grep auto

autofs-5.0.1-0.rc2.131.el5 (自动挂载文件系统)确保安装上 客户机

[[email protected] ~]# chkconfig --list |grep auto 

autofs          0:关闭 1:关闭 2:关闭 3:启用 4:启用 5:启用 6:关闭

要实现自动挂载需要改auto的一些脚本

[[email protected] ~]# vim /etc/auto.master 

 10 /mnt/hua  /etc/auto.nfs  --timeout=60

[[email protected] ~]# cp -p /etc/auto.misc /etc/auto.nfs

[[email protected] ~]# vim /etc/auto.nfs 

server          -ro,soft.intr           192.168.30.120:/hua

[[email protected] ~]# service autofs restart

[[email protected] ~]# cd /mnt/hua/

[[email protected] hua]# cd server  (执行这个动作后然后就自动挂载上去了)

[[email protected] server]# mount  (可以看到已经被挂载上了)

NFS网络文件系统的实现

60秒后查看,可以看到已经没有挂载了,失去了连接,要想再次挂载,在cd server 即可

转载于:https://blog.51cto.com/yudonghua/1094486

相关文章:

  • 2021-05-04
  • 2022-02-08
  • 2022-12-23
猜你喜欢
  • 2021-09-03
  • 2021-04-19
  • 2021-10-07
  • 2021-07-22
  • 2021-10-17
  • 2022-01-06
相关资源
相似解决方案