NFS介绍
NFS 是 Network FileSystem 的缩写,顾名思义就是网络文件存储系统,它最早是由 Sun 公司发展出来的,也是 FreeBSD 支持的文件系统中的一个,它允许网络中的计算机之间通过 TCP/IP 网络共享资源。通过 NFS,我们本地 NFS 的客户端应用可以透明地读写位于服务端 NFS 服务器上的文件,就像访问本地文件一样方便。简单的理解,NFS 就是可以透过网络,让不同的主机、不同的操作系统可以共享存储的服务。
主要是针对近期的视频文件上传提供服务。
安装前准备
机器准备
1
2
310.0.101.73(NFS服务端)
10.0.101.123(NFS客户端)
*.*.*.*(NFS客户端)检查机器是否已安装
1
2
3
4如果出现以下信息,则表示已经安装了对应的nfs 与 rpcbind
[root@localhost share]# rpm -qa nfs-utils rpcbind
nfs-utils-1.3.0-0.65.el7.x86_64
rpcbind-0.2.0-48.el7.x86_64
安装
服务端安装配置
1
yum install -y nfs-utils rpcbind
客户端安装配置
1
yum install -y nfs-utils
配置使用
服务端创建共享目录 /mnt/share
1
2mkdir -p /mnt/share
chmod 666 /mnt/share服务端修改/etc/exports配置共享客户端信息
1
2
3
4
5vim /etc/exports
内容如下 表示共享/mnt/share 目录给到对应的123这台机器,并且配置相对应的权限
/mnt/share 10.0.101.123(rw,async,no_root_squash)
执行以下命令生效
exports -r说明一下,这里配置后边有很多参数,每个参数有不同的含义,具体可以参考下边。此处,我配置了将 /mnt/share 文件目录设置为允许 IP 为该 10.0.101.123 的客户端挂载。
| 参数 | 说明 |
| ———————— | —————————————————————————————— |
| ro | 只读访问 |
| rw | 读写访问 |
| sync | 所有数据在请求时写入共享 |
| async | nfs 在写入数据前可以响应请求 |
| secure | nfs 通过 1024 以下的安全 TCP/IP 端口发送 |
| insecure | nfs 通过 1024 以上的端口发送 |
| wdelay | 如果多个用户要写入 nfs 目录,则归组写入(默认) |
| no_wdelay | 如果多个用户要写入 nfs 目录,则立即写入,当使用 async 时,无需此设置 |
| hide | 在 nfs 共享目录中不共享其子目录 |
| no_hide | 共享 nfs 目录的子目录 |
| subtree_check | 如果共享 /usr/bin 之类的子目录时,强制 nfs 检查父目录的权限(默认) |
| no_subtree_check | 不检查父目录权限 |
| all_squash | 共享文件的 UID 和 GID 映射匿名用户 anonymous,适合公用目录 |
| no_all_squash | 保留共享文件的 UID 和 GID(默认) |
| root_squash | root 用户的所有请求映射成如 anonymous 用户一样的权限(默认) |
| no_root_squash | root 用户具有根目录的完全管理访问权限 |
| anonuid=xxx | 指定 nfs 服务器 /etc/passwd 文件中匿名用户的 UID |
| anongid=xxx | 指定 nfs 服务器 /etc/passwd 文件中匿名用户的 GID |服务端启动服务rpcbind
1
2
3service rpcbind start
或者使用如下命令亦可
systemctl start rpcbind.service服务端启动nfs服务
1
2
3
4启动 NFS 服务
service nfs start
或者使用如下命令亦可
systemctl start nfs.service服务端检查挂载信息
1
2
3
4
5
6
7
8[root@localhost share]# showmount -e localhost
Export list for localhost:
/mnt/share 10.0.101.123
[root@localhost share]# showmount -e 10.0.101.73
Export list for 10.0.101.73:
/mnt/share 10.0.101.123
[root@localhost share]#客户端挂载服务端目录信息
1
2
3
4
5
6
7
8
9
10
11首先创建目录用于建立对服务器的挂载映射
mkdir -p /mnt/share
挂载服务器目录信息并且映射本地的目录 udp
mount 10.0.101.73:/mnt/share /mnt/share
tcp
mount 10.0.101.73:/mnt/share /mnt/share -o proto=tcp -o nolock
查看挂载服务端信息
[root@localhost video]# df -h | grep 10.0.101.73
10.0.101.73:/mnt/share 44G 2.6G 42G 6% /mnt/share
[root@localhost video]#验证测试
服务端:
客户端:
总结
好了,上边简单介绍了 NFS 安装及配置使用,使用它我们可以很方便的透过网络,让不同的主机、操作系统实现共享存储。