Linux下安装NFS
摘要
服务端安装
1 | yum -y install nfs-utils rpcbind |
配置参数
1 | vi /etc/exports |
1 | /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用户具有根目录的完全管理访问权限
配置生效
1 | exportfs -r |
启动
1 | systemctl start rpcbind && systemctl start nfs-server |
查看 RPC 服务的注册状况
1 | rpcinfo -p localhost |
容器启动
1 | docker run -d \ |
客户端使用
安装nfs-utils客户端
1 | yum -y install nfs-utils |
查看服务器抛出的共享目录信息
1 | showmount -e 172.19.232.122 |
创建挂载目录
1 | mkdir /data/expfile |
为了提高NFS的稳定性,使用TCP协议挂载,NFS默认用UDP协议
1 | mount -t nfs 172.19.232.122:/data/tmpfile/export /data/tmpfile -o proto=tcp -o nolock |
开启自动挂载,在 /etc/fstab 下加上如下配置
1 | 172.19.232.122:/data/tmpfile/export /data/tmpfile nfs defaults 0 0 |
卸载
1 | umount /data/tmpfile |