NFS(Network File System):是在 UNIX(Linux)系统中最流行的网络文件系统,其功能是通过网络让不同的机器(或操作系统)可以共享彼此的文件或目录。
在使用 NFS 之前,服务端(提供共享文件或目录的一方)和客户端(使用共享文件或目录的一方)都需要先安装 rpcbind 和 nfs-utils 依赖组件。
rpm -qa | grep rpcbind
如果还没安装 rpcbind 依赖组件,请参考 CentOS-7离线安装rpcbind 。
rpm -qa | grep nfs-utils
如果还没安装 nfs-utils 依赖组件,请参考 CentOS-7离线安装nfs-utils 。
注意:在安装 nfs-utils 依赖组件之前,必须先安装 rpcbind 依赖组件;一般来说,CentOS-7 已默认安装 rpcbind 依赖组件,只需要 nfs-utils 依赖组件即可。
如上图所示,(本例)在服务端(提供共享文件或目录的一方)的根目录“/”,创建了一个目录,用于和客户端共享。
mkdir 共享目录名称
vi /etc/exports
共享目录路径 *(rw,no_root_squash,insecure,sync)
注意:如果需要进行网段限制,“*”改为对应网段,例如:
共享目录路径 192.168.56.0/24(rw,no_root_squash,insecure,sync)
参数 | 说明 |
---|---|
rw | 共享目录的访问权限为可读可写(read-write),实际权限还和文件系统的 rwx 权限以及用户身份有关 |
ro | 共享目录的访问权限为只读(read-only) |
no_root_squash | 允许客户端以 root 身份访问共享目录 |
root_squash | 客户端的 root 身份会被切换成和 anonymous 匿名用户身份一样的权限 |
insecure | 允许 nfs 服务使用比 1024 更大的端口号 |
secure | nfs 服务只能使用 1024 以内的端口号 |
sync | 数据同步写入到内存与硬盘中 |
async | 数据先暂存在内存当中,不直接写入硬盘 |
systemctl status rpcbind
命令 | 说明 |
---|---|
systemctl status rpcbind | 查看 rpcbind 服务运行状态 |
systemctl start rpcbind | 启动 rpcbind 服务 |
systemctl restart rpcbind | 重启 rpcbind 服务 |
systemctl enable rpcbind | 设置 rpcbind 服务开机自启动 |
systemctl restart nfs
命令 | 说明 |
---|---|
systemctl status nfs | 查看 nfs 服务运行状态 |
systemctl start nfs | 启动 nfs 服务 |
systemctl restart nfs | 重启 nfs 服务 |
systemctl enable nfs | 设置 nfs 服务开机自启动 |
firewall-cmd --add-service=nfs --permanent
firewall-cmd --reload
命令 | 说明 |
---|---|
nfsstat | 查看NFS的运行状态 |
rpcinfo | 查看rpc执行信息,可以用于检测rpc运行情况的工具,利用rpcinfo -p 可查看出RPC开启的端口所提供的程序 |
systemctl status rpcbind
命令 | 说明 |
---|---|
systemctl status rpcbind | 查看 rpcbind 服务运行状态 |
systemctl start rpcbind | 启动 rpcbind 服务 |
systemctl restart rpcbind | 重启 rpcbind 服务 |
systemctl enable rpcbind | 设置 rpcbind 服务开机自启动 |
systemctl start nfs
命令 | 说明 |
---|---|
systemctl status nfs | 查看 nfs 服务运行状态 |
systemctl start nfs | 启动 nfs 服务 |
systemctl restart nfs | 重启 nfs 服务 |
systemctl enable nfs | 设置 nfs 服务开机自启动 |
如上图所示,(本例)在客户端(使用共享文件或目录的一方)的“/root”目录下,创建了一个目录,用于挂载服务端的共享目录。
mkdir 共享目录挂载点名称
mount -t nfs 服务端IP地址:/服务端共享目录路径 客户端挂载点路径
注意:如果(普通用户)挂载共享目录时报错“mount.nfs: failed to apply fstab options”,则需要使用 sudo 权限执行该挂载命令。
如上图所示,已实现服务器之间的文件(目录)共享。
df -h
umount 客户端挂载点路径
【1】【Word哥】【Linux下NFS服务的安装与配置】【CSDN】【2020-08-05】
【2】【Jason_huawen】【NFS文件共享时报错的解决方法】【博客园】【2022-11-09】
【3】【我真的啥也不会】【NFS配置及开机自动挂载】【博客园】【2022-03-06】
本文来自博客园,作者:Javaer1995,转载请注明原文链接:https://www.cnblogs.com/Javaer1995/p/18590450
参与评论
手机查看
返回顶部