NFS学习

  linux下搭建nfs服务:

  NFS是network filesystem的缩写,它可以通过网络,让不同的机器、不同的操作系统共享文件。

  NFS支持的功能比较多,默认端口也是随机的,基于远程调用服务(RPC)服务支持,rpc使用111端口监听,然后收到客户端请求后回复nfs工作的端口,客户端再拿着这个端口号去访问nfs共享。

  启动NFS之前,必须先启动RPC服务,否则NFS无法想RPC注册。nfs其实很简单,只是要基于rpc服务,所以要先安装rpc软件且运行后,才能运行nfs。这边我是学习,就不讲解具体原理了,如果看原理,请点击最下面的链接查看详情;

  系统环境:centos 7.6

  1、查看系统是否安装了nfs和rpc

[root@nfs01 ~]# rpm -qa | grep  rpcbind
rpcbind-0.2.0-47.el7.x86_64
[root@nfs01 ~]# rpm -qa | grep nfs
nfs-utils-1.3.0-0.61.el7.x86_64

  2、我这里已经安装了,如果没有安装,就安装nfs和rpc

[root@nfs01 ~]# yum install -y nfs-utils rpcbind

  3、服务端配置

在nfs服务器上创建共享目录,并给予权限

[root@nfs01 ~]# mkdir -p /share
[root@nfs01 ~]# chown nfsnobody.nfsnobody /share
[root@nfs01 ~]# ls -ld /share
drwxr-xr-x 2 nfsnobody nfsnobody 6 May 30 17:08 /share

  4、服务端启动rpc服务和nfs服务

[root@nfs01 ~]# systemctl start rpcbind
[root@nfs01 ~]# systemctl enable rpcbind
[root@nfs01 ~]# systemctl start nfs
[root@nfs01 ~]# ps -ef |grep nfs
[root@nfs01 data]# rpcinfo -p localhost

  5、编辑exports文件

[root@nfs01 ~]# vim /etc/exports
/share 172.16.1.0/24(rw,sync,all_squash)

常用all_squash参数,即将所有来访用户变成nfsnobody用户访问。

  6、重启nfs并检查挂载

[root@nfs01 ~]# systemctl restart nfs
[root@nfs01 ~]# showmount -e localhost
Export list for localhost:
/share 172.16.1.0/24

  7、客户端挂载

客户端必须安装rpcbind软件,最好也安装nfs服务,不然没办法运行showmount命令

客户端先检查服务共享目录,再进行挂载,最后查看挂载结果

[root@web01 ~]# showmount -e 172.16.1.31
Export list for 172.16.1.31:
/share 172.16.1.0/24
[root@web01 ~]# mount -t nfs 172.16.1.31:/share /share -o proto=tcp
[root@web01 ~]# df -h

  8、客户端测试

[root@web01 ~]# cd /share
[root@web01 share]# touch 123.txt

上述都是基于关闭防火墙的配置(iptables -F),服务端的nfs最好加入开机自启动,客户端开机自动挂载。

 详细过程及参考文献:https://www.cnblogs.com/liuyisai/p/5992511.html

 

  

转载于:https://www.cnblogs.com/zhanbing/p/10950949.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值