NFS为网络文件系统,是Network File System的缩写,它的主要功能是通过网络让不同的主机系统之间可以共享文件或目录,NFS的客户端(一般为应用服务器,例如web)可以通过挂载(mount)的方式将NFS服务器共享的数据目录挂载到NFS客户端中

  NFS在文件传送过程中依赖与RPC(远程过程调用)协议。NFS本身是没有提供信息传送的协议和功能的,但是能够用过网络进行图片,视频,附件等分享功能。只要用到NFS的地方都需要启动RPC服务,不论是NFS的服务端还是客户端。

  NFS和RPC的关系:可以理解为NFS是一个网络文件系统,而RPC是负责信息的传输。

一般情况下centos7 系统中默认已经装上了NFS服务,我们可以检查一下,若是没有装的话,通过yum install nfs-utils命令安装NFS服务,若是已经安装,就不用进行其他操作了。

[root@localhost ~]# yum install nfs-utils     
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
file:///media/cdrom/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /media/cdrom/repodata/repomd.xml"
正在尝试其它镜像。
软件包 1:nfs-utils-1.3.0-0.68.el7.x86_64 已安装并且是最新版本
无须任何处理        #证明NFS服务是在centos7系统中默认安装的
[root@localhost ~]# iptables -F   #清空防火墙默认策略
[root@localhost ~]# service iptables save    #保存当前防火墙的状态
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ 确定 ]
[root@localhost ~]# mkdir /nfsfile      #创建NFS服务的共享目录

[root@localhost ~]# chmod -Rf 777 /nfsfile    #修改共享目录的权限,让任何人都可以编写

[root@localhost ~]# echo "i like you linux" > /nfsfile/readme      #在共享目录下写入共享文件

[root@localhost ~]# vim /etc/exports     #NFS服务程序的默认文件为空,要为其写入配置文件

写入内容如下图所示

[root@localhost ~]# systemctl restart rpcbind     #重启rpcbind服务,因为NFS服务在进行共享之前需要RPC服务将NFS服务器的IP地址,端口信息等发送到客户端。
[root@localhost ~]# systemctl enable rpcbind     #将RPC服务加入开机自启动项中
[root@localhost ~]# systemctl start nfs-server     #启动NFS服务
[root@localhost ~]# systemctl enable nfs-server  #将NFS服务加入开机自启动中

Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.

客户端配置

[root@web1 ~]# showmount -e 192.168.146.100   #查询NFS服务的远程共享信息
Export list for 192.168.146.100:
/nfsfile 192.168.146.*
[root@web1 ~]# mkdir /nfsfile    #在客户端建立一个挂载目录
[root@web1 ~]# mount -t nfs 192.168.146.100:/nfsfile /nfsfile     #将服务器上共享目录下的文件挂载到本地文件系统
[root@web1 ~]# cat /nfsfile/readme   #在本地查看服务器上的文件
i like you linux

[root@web1 ~]# vim /etc/fstab   #若想永久挂载,则可将挂载信息写入/etc/fstab 文件中
[root@web1 ~]# mount -a      #挂载上面文件中的所有信息

 结束啦!!!



posted on 2021-05-17 08:32  与所有美好不期而遇  阅读(163)  评论(0)    收藏  举报