Linux NFS文件共享

NFS


NFS(Network File System)即网络文件系统,是FreeBSD支持的文件系统中的一种,它允许网络中的计算机之间通过TCP/IP网络共享资源。在NFS的应用中,本地NFS的客户端应用可以透明地读写位于远端NFS服务器上的文件,就像访问本地文件一样。

nfs的启动


虚拟机IP:172.25.254.125(服务器)

 yum install nfs-utils -y
 systemctl start nfs-server
 systemctl enable nfs-server
 systemctl stop firewalld 

测试

虚拟机IP:172.25.254.225(客户端)

 [root@nfs-client ~]# showmount -e 172.25.254.125                     ###检查是否配好
 Export list for 172.25.254.125:

配置共享


虚拟机IP:172.25.254.125(服务器)

 mkdir /dream
 vim /etc/exports
 /dream  172.25.254.0/24(sync)                                        ###实时同步
 exportfs -rv                                                         ###r:刷新  v:显示
 touch /dream/dream

测试

虚拟机IP:172.25.254.225(客户端)

 [root@nfs-client ~]# mount 172.25.254.125:/dream /mnt
 [root@nfs-client ~]# ls /mnt
 dream

NFS参数


虚拟机IP:172.25.254.125(服务器)

 vim /etc/exports
 /dream  172.25.254.0/24(sync) 172.25.254.225(rw,anonuid=1001,anongid=1001)
 exportfs -rv   
 chmod 777 /nfsdir 或 chown nfsnobody.nfsnobody /nfsdir 

测试

虚拟机IP:172.25.254.225(客户端)

 umount /mnt
 mount 172.25.254.125:/dream /mnt
 touch /mnt/aa
 ll /mnt
开机自动挂载:
 vim /etc/fstab
 172.25.254.125:/dream  /mnt  nfs  defaults  0 0

可以发现生成的文件的uid和gid都为1001
这里写图片描述
虚拟机IP:172.25.254.125(服务器)

 vim /etc/exports
 /dream  172.25.254.0/24(sync) 172.25.254.225(rw,anonuid=1001,anongid=1001,no_root_squash)         ######no_root_squash存在时,前面的uid无效
 exportfs -rv

测试

虚拟机IP:172.25.254.225(客户端)
我可以发现生成的属主和用户主为当前用户环境的用户
这里写图片描述

自动挂载和卸载


虚拟机IP:172.25.254.225(客户端)

 yum install autofs.x86_64 -y
 systemctl start autofs
 systemctl enable autofs
 vim /etc/sysconfig/autofs
  13 TIMEOUT=3                                        ###为了测试方便,把时间改为3s
 systemctl restart autofs.service

 cd /net/
 cd 172.25.254.125
 cd dream/
 df                                                  ###可发现自动挂载成功
 cd
 等待3S
 df                                                  ###发现自动卸载

这里写图片描述

改变挂载点


虚拟机IP:172.25.254.225(客户端)

 vim /etc/auto.master
 7 /misc   /etc/auto.misc
 8 /mnt    /etc/auto.nfs                                
 vim /etc/auto.nfs
 redhat  -ro,vers=3.0    172.25.254.125:/dream
 systemctl restart autofs

 cd /mnt
 cd redhat
 df                                              ###发现自动挂载成功
 mount                                           ###查看挂载参数

这里写图片描述
172.25.254.125:/dream on /mnt/redhat type nfs (ro,relatime,vers=3,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,mountaddr=172.25.254.125,mountvers=3,mountport=20048,mountproto=udp,local_lock=none,addr=172.25.254.125)

这里写图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Wielun

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值