1.安装NFS所需要的插件与本体
yum install -y nfs-utils rpcbind
2.创建共享目录并设置权限
mkdir -p /data/share
chmod 777 /data/share
3.修改配置文件,指定目录权限(IP限定、只读、读写权限之类)
vim /etc/exports
/data/share 10.222.77.0/24(rw,sync,insecure,no_subtree_check,no_root_squash)
4.相关命令
4.1先启动RPC服务
$ service rpcbind start
# 或者使用如下命令亦可
$ /bin/systemctl start rpcbind.service
# 查看 NFS 服务项 rpc 服务器注册的端口列表
$ rpcinfo -p localhost
4.2启动NFS服务
# 启动 NFS 服务 $ service nfs start
# 或者使用如下命令亦可
/bin/systemctl start nfs.service
# 启动 NFS 服务后 rpc 服务已经启用了对 NFS 的端口映射列表
# rpcinfo -p localhost
4.3查看配置
$ showmount -e localhost
5.window挂载NFS
5.1 Windows Server 2008 R2 操作
打开“控制面板” → 点击“角色” → 点击“添加角色” → 点击“下一步” → 点击“文件服务” → 点击“下一步“ →点击”下一布” → 选择“网络文件系统服务” → 点击“下一步“ → 点击”安装“。
5.2其他window版本
控制面板 → 程序与功能 → 打开或关闭windows功能 → 勾选 NFS服务
配置项-附表:
参数 | 说明 |
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 用户具有根目录的完全管理访问权限 |
agonuid=xxx | 指定 nfs 服务器 /etc/passwd 文件中匿名用户的 UID |
agongid=xxx | 指定 nfs 服务器 /etc/passwd 文件中匿名用户的 GID |