NFS使用记录
# macos# 通过上面的网站下载安装macfuse和sshfs
# centos服务端yum install -y nfs-utils
# Ubuntu/Debiansudo apt install -y nfs-common
# 启动并启用 NFS 服务systemctl start nfs-serversystemctl enable nfs-serversystemctl status nfs-server配置 NFS 共享目录
Section titled “配置 NFS 共享目录”# 编辑 /etc/exports 文件vim /etc/exports
# 示例# 格式:共享目录 客户端IP(选项)/data/nfs_share 192.168.1.0/24(rw,sync,no_root_squash)
# /data/nfs_share:要共享的目录(需提前创建)。# 192.168.1.0/24:允许访问的客户端 IP 范围(* 表示所有客户端,但不推荐)。# rw:读写权限(ro 表示只读)。# sync:同步写入(async 表示异步,但可能丢失数据)。# no_root_squash:允许客户端 root 用户保持 root 权限(谨慎使用,可能带来安全风险)。# root_squash(默认):客户端 root 用户映射为 nobody 用户。
# 创建共享目录mkdir -p /data/nfs_sharechmod 755 /data/nfs_share# 可选,NFS 默认用户chown nfsnobody:nfsnobody /data/nfs_share# 导出 NFS 共享# 运行以下命令使配置生效:exportfs -ra# 查看当前共享情况:exportfs -v配置防火墙(如果启用)
Section titled “配置防火墙(如果启用)”# 如果 CentOS 启用了防火墙(firewalld),需要放行 NFS 相关端口:sudo firewall-cmd --permanent --add-service=nfssudo firewall-cmd --permanent --add-service=mountdsudo firewall-cmd --permanent --add-service=rpc-bindsudo firewall-cmd --reload# 或者直接放行 NFS 默认端口(不推荐,可能影响安全性):sudo firewall-cmd --permanent --add-port={2049/tcp,2049/udp}sudo firewall-cmd --reload测试 NFS 服务
Section titled “测试 NFS 服务”# 在服务器上测试showmount -e localhost挂载 NFS 共享
Section titled “挂载 NFS 共享”# 确保客户端目录权限chmod 755 /Users/xx/mount/sshfs
mount -t nfs 192.168.1.100:/data/nfs_share /mnt/nfs# (192.168.1.100 是 NFS 服务器 IP,/mnt/nfs 是客户端挂载点)# 使用 mount_nfs(macOS 原生命令)sudo mount_nfs -o resvport xx.intranet.company:/data/nfs_share/dev /Users/xx/mount/sshfs/xx.intranet.company
# 检查是否挂载成功:df -h | grep nfs# 如果看到类似 /dev/nfs 的挂载信息,说明成功。# /mnt/nfs 是客户端挂载点umount /mnt/nfs# 客户端无法挂载
# 检查 /etc/exports 配置是否正确。# 确保防火墙放行了 NFS 相关端口。# 检查 rpcbind 服务是否运行(CentOS 7+ 默认启用):sudo systemctl status rpcbind
# 权限问题
# 确保共享目录的权限正确(chmod 755)。# 如果使用 no_root_squash,确保客户端 root 用户有权限。- macos挂载显示没权限的问题
macOS 的 NFS 服务由 launchd 管理,不能直接运行 nfsd start。你需要: