
网络文件系统(英语:Network File System,缩写为NFS)是一种分布式文件系统协议,最初由Sun Microsystems公司开发,并于1984[1]
年发布。其功能旨在允许客户端主机可以像访问本地存储一样通过网络访问服务器端文件。 NFS和其他许多协议一样,是基于开放网络运算远程过程调用(ONC RPC) 协议之上的。

NFS场景描述
-
服务端实现 NFS 守护进程, 默认运行 nfsd, 用来使得数据可以被客户端访问.
-
服务端系统管理员可以决定哪些资源可以被访问, 导出目录的名字和参数, 通常使用 /etc/exports配置文件和exportfs命令。
-
服务端 安全-管理员 保证它可以组织和认证合法的客户端.
-
服务端网络配置保证可以跟客户端透过 防火墙 进行协商.
-
客户端请求导出的数据, 通常调用一个 mount
命令. (The client asks the server (rpcbind) which port the NFS server is using, the client connects to the NFS server (nfsd), nfsd passes the request to mountd) -
如果一切顺利, 客户端的用户就可以通过已经挂载的 文件系统 查看和访问服务端的文件了.
-
NFS网络文件系统一般用来存储共享附件等静态资源文件,一般是把网站用户上传的文件都放到NFS共享里.
让我们用一个一个示例,更详细地说明NFS部署细节吧!(暂时关闭iptables selinux等)
1. NFS环境
NFS-Server: 172.18.20.96(CentOS7.2)
NFS-Client: 172.18.20.69(CentOS7.2)
Server端配置
2. 安装相关软件包
[root@thinkpad ~]#yum -y install rpcbind nfs-utils # CentOS6以后用rpcbind 取代了portmapper,谨慎的话可以再测试软件是否正确安装
3. 创建共享目录
[root@thinkpad ~]#mkdir -p /data/nfs_storage
[root@thinkpad ~]#chmod 755 /data/nfs_storage/ # 这个应该默认就是755权限
4. 导出共享目录设置
[root@thinkpad ~]# vi /etc/exports
[root@thinkpad ~]# cat /etc/exports
/data/nfs_storage 172.18.20.69/24(rw,sync,no_root_squash,no_all_squash)
5. 启动rpcbind nfs服务,[设置其为开机自启]
[root@thinkpad ~]#systemctl start rpcbind.service
[root@thinkpad ~]#systemctl start nfs-server.service
[root@thinkpad ~]#[systemctl enable rpcbind.service]
[root@thinkpad ~]#[systemctl enable nfs-server.service]
ss -lntu #
Client端配置
6. 安装rpcbind nfs-utils软件包
yum -y install rpcbind nfs-utils
[root@thinkpad ~]# systemctl enable rpcbind
[root@thinkpad ~]# systemctl start rpcbind
[root@thinkpad ~]# systemctl start nfs
7. 创建挂载目录
[root@thinkpad ~]# mkdir -pv /data/nfs_shared
8. 查看Server端的exports 列表内容,如下图
[root@thinkpad ~]#showmount -e 172.18.20.96

9. 挂载NFS-Server
[root@thinkpad ~]# mount -t nfs 172.18.20.96:/data/nfs_storage /data/nfs_shared
[root@thinkpad ~]#mount # 查看是否挂载成功
此时即可在Client端像访问本地存储设备一样访问Server端的指定目录里的内容了.
网友评论