必备条件:服务器和客户端都要安装nfs-utils、rpcbind。
1. 查看是否安装nfs-utils、rpcbind
rpm -q rpcbind nfs-utils
2. 安装nfs-utils、rpcbind
yum install -y rpcbind nfs-utils
3. 设置共享目录
vim /etc/exports
**配置参数介绍 **
客户机地址可以是主机名、ip地址、网段地址、允许使用"*"、"?"通配符
“rw”表示允许读写,"ro"表示为只读;
"sync"表示同步写入到内存与硬盘中
"no_root\_squash"表示当客户机以root身份访问时赋予本地root权限,默认是"root_squash"
"root_squash"表示客户机用root用户访问更改共享目录时,将root用户映射成匿名用户。
4. 启动NFS服务程序
systemctl start rpcbind.service #开启rpcbind
systemctl start nfs #开启nfs
systemctl enable rpcbind.service #将rpcbind设为自启动
systemctl enable nfs #将nfs设为自启动
5.客户端配置
5.1 检查或操作上述1、2、4步骤
5.2 查看服务器共享目录
showmount -e [ip地址]
5.3 挂载目录
mount -t nfs 192.168.0.168:/home/file/ /home/file
5.4 设置自动挂载
vim /etc/rc.local #将5.3所述命令保存至此文件