Linux下安装NFS

摘要

bash

yum -y install nfs-utils rpcbind

配置参数

bash

vi /etc/exports

bash

/data/tmpfile *(rw,sync,no_root_squash)

/data 表示需要共享的目录。 IP 表示允许哪个客户端访问。 IP后括号里的设置表示对该共享文件的权限。 ro 只读访问 rw 读写访问 sync 所有数据在请求时写入共享 all_squash 共享文件的UID和GID映射匿名用户anonymous,适合公用目录。 no_all_squash 保留共享文件的UID和GID(默认) root_squash root用户的所有请求映射成如anonymous用户一样的权限(默认) no_root_squash root用户具有根目录的完全管理访问权限

配置生效

bash

exportfs -r

启动

bash

systemctl start rpcbind && systemctl start nfs-server
systemctl enable rpcbind && systemctl enable nfs-server

查看 RPC 服务的注册状况

bash

rpcinfo -p localhost

安装nfs-utils客户端

bash

yum -y install nfs-utils

查看服务器抛出的共享目录信息

bash

showmount -e 172.19.232.122

创建挂载目录

bash

mkdir /data/expfile
chown -R nginx.nginx expfile

为了提高NFS的稳定性,使用TCP协议挂载,NFS默认用UDP协议

bash

mount -t nfs 172.19.232.122:/data/tmpfile/export /data/tmpfile -o proto=tcp -o nolock

开启自动挂载,在 /etc/fstab 下加上如下配置

bash

172.19.232.122:/data/tmpfile/export /data/tmpfile nfs defaults  0 0

卸载

bash

umount /data/tmpfile

相关内容