NFS 网络文件系统(Network File System) 是由Sun公司1984年发布的分布式文件系统协议。它允许客户端上的用户像访问本地文件一样地访问网络上的文件。
用途
NFS在日常工作中有很多用途:
- nfs-client可以做日志查看终端,开发和运维不用逐个登陆服务器查看日志;
- 通过nfs-client可以让前端开发自己上传发布文件,类似FTP一样;
安装
客户端和服务端都只需要安装nfs-util包。yum安装即可。
强烈建议在所有节点机上使用如ntp之类的时间同步守护进程以保持客户端/服务器之间的时间同步,如果各个节点上没有精确同步的时钟,NFS可能产生非预期的延迟。建议采用网络时间协议守护进程并使用互联网上的高精度 NTP 服务器同步服务端和客户端的时钟。
注意:
nfs-utils for Arch Linux ARM starting with update 1.3.2-4 (possibly earlier) has been reported by one user to behave differently from the x86_64 or i686 package. See the discussion page for a recipe for client mounts.
配置
Linux_Server和Linux_Client
用途:看日志
Linux_Server配置:
- 权限:只读
- 配置:
[root@pszqtizZ ~]# cat /etc/exports /usr/local/apache-tomcat-qq-nfs/ nfs-client.baidu.com(ro,sync,fsid=0,all_squash) server端共享目录 允许客户端地址 其他配置
Linux_Client配置:
- mount挂载即可:
[root@hyk7fj3Z ~]# cat /etc/fstab | grep nfs nfs-qq.baidu.com:/usr/local/apache-tomcat-qq-nfs /data/apache-tomcat-qq-nfs nfs defaults 0 0
Linux_Server和Windows_Client
用途:传文件
Linux_Server配置:
- 权限:读写
- 配置:
[root@pszqtj5Z ~]# cat /etc/exports /usr/share/nginx/wap/ nfs-client2.baidu.com(rw,no_root_squash)
Windows_Client配置:
- mount挂载即可:
cmd > mount web-qq.baidu.com:/usr/local/apache-tomcat-web/webapps/ d:
- windows如果要配置开机启动自动挂载则可在“资源管理器”中添加 “ 映射网络驱动器 ” 。
启动nfs服务
systemctl start rpcbind
systemctl status rpcbind
systemctl start nfs
systemctl status nfs
/etc/exports配置加载
- 如果服务运行时修改了 /etc/exports 文件, 你需要重新加载使其生效。
exportfs -ra