1. 装置nfs和rpcbind

yum install nfs-utils rpcbind
个别默认都有装置, 如果已装置能够跳过

2. 创立服务端共享目录

# 创立目录mkdir -p /www/share_files# 配置权限chmod -R 777 /www/share_files

这里的/www/share_files就是服务端分享进去的目录

3. 配置nfs的配置文件

vi /etc/exports
文件中配置一行:

# /www/share_files 示意共享目录# 192.168.1.4改成本人的IP# (rw,sync,no_root_squash) 示意权限/www/share_files 192.168.1.4(rw,sync,no_root_squash)

权限可选值参考:

rw:read-write,可读写; 留神,仅仅这里设置成读写客户端还是不能失常写入,还要正确地设置共享目录的权限,参考问题7ro:read-only,只读;sync:文件同时写入硬盘和内存;async:文件暂存于内存,而不是间接写入内存;no_root_squash:NFS客户端连贯服务端时如果应用的是root的话,那么对服务端分享的目录来说,也领有root权限。显然开启这项是不平安的。root_squash:NFS客户端连贯服务端时如果应用的是root的话,那么对服务端分享的目录来说,领有匿名用户权限,通常他将应用nobody或nfsnobody身份;all_squash:不管NFS客户端连贯服务端时应用什么用户,对服务端分享的目录来说都是领有匿名用户权限;anonuid:匿名用户的UID值,通常是nobody或nfsnobody,能够在此处自行设定;anongid:匿名用户的GID值。

4. 刷新配置

exportfs -r

5. 启动nfs和rpcbind服务

# 查看服务状态systemctl status rpcbindsystemctl status nfs-server# 启动服务systemctl restart rpcbindsystemctl restart nfs-server# 设置开机自启systemctl enable rpcbind systemctl enable restart

6. 检测服务器的nfs状态

服务端查看:
showmount -e

[root@iZxe4Z share_files]# showmount -eExport list for iZgw839moiwhkboospwxe4Z:/www/share_files *

客户端查看:
showmount -e 192.168.1.4

[root@ip-192.168.1.3 centos]# showmount -e 192.168.1.4Export list for 192.168.1.4:/www/share_files *

7. 挂载服务端的共享目录

# 192.168.1.4:/www/share_files 服务端IP:目录# /www/jump_share_files 客户端目录mount -t nfs 192.168.1.4:/www/share_files /www/jump_share_files

常见问题

挂载失败

失败场景一:

第7步中如果挂载呈现谬误提醒:clnt_create: RPC: Program not registered

[centos@ip-192.168.1.3 ~]$ showmount -e 192.168.1.4clnt_create: RPC: Program not registered

解决办法:

  1. 在服务器上先进行rpcbind,
    systemctl stop rpcbind
  2. 而后在进行nfs
    systemctl stop nfs
  3. 最初在重启rpcbind和nfs,肯定要按程序启动和进行

    systemctl start rpcbindsystemctl start nfs

失败场景二:

第7步中如果挂载呈现谬误提醒:mount.nfs: access denied by server while mounting 192.168.1.4:/www/share_files

查看具体失败起因:
cat /var/log/messages | grep mount

Sep 23 17:52:20 iZj6cdspheuw91fen9pcvrZ rpc.mountd[20419]: refused mount request from 192.168.1.4 for /www/share_files (/www/share_files): unmatched host

解决办法:
反复第三步vi /etc/exports , 将IP改为*
/www/share_files *(rw,sync,no_root_squash)