NFS 文件共享

备注:NFS 文件共享需设置两部分:服务端和客户端

一、服务端设置

1.1、查看nfs包是否安装,未安装则重新安装

[root@localhost ~]# rpm -qa|grep rpcbind
rpcbind-0.2.0-42.el7.x86_64
[root@localhost ~]# rpm -qa|grep nfs-utils
nfs-utils-1.3.0-0.48.el7.x86_64

-------------------------------------------------

yum -y install nfs-utils rpcbind 

1.2、创建共享目录并赋予权限

[root@localhost home]# mkdir /home/{gong,xiang}
[root@localhost home]# chmod -R 755 /home/gong/ /home/xiang/

1.3、修改共享配置文件

格式为:【 共享路径   客户端主机 (选项)  】 或 【共享路径   客户端主机1 (选项)   客户端主机2 (选项)  】

[root@localhost home]# vi /etc/exports
/home/gong 192.168.43.11(rw,no_root_squash)
/home/xiang  *(ro,sync)

1.4、启动NFS服务,若不成功则执行 service nfs restart

[root@localhost home]# systemctl start rpcbind
[root@localhost home]# systemctl start nfs-utils

 

二、客户端部分设置

2.1、通过showmount查看共享信息,若报错则重启nfs服务(centos7.4以后适用)

[root@localhost ~]# systemctl restart nfs-utils
[root@localhost ~]# showmount -e 192.168.43.12
clnt_create: RPC: Program not registered
[root@localhost ~]# 
[root@localhost ~]# service nfs restart
Redirecting to /bin/systemctl restart nfs.service
[root@localhost ~]# 
[root@localhost ~]# showmount -e 192.168.43.12
Export list for 192.168.43.12:
/home/xiang *
/home/gong  192.168.43.11

2.2、在客户端设置挂载目录,最好是相同的,方便记忆。也可以是不同的

格式为:mount NFS服务器IP:共享目录  本地挂载点目录

[root@localhost ~]# mount 192.168.43.12:/home/gong/  /home/gong/
[root@localhost ~]# mount 192.168.43.12:/home/xiang/  /home/xiang/

2.3 查看共享信息

[root@localhost home]# ls /home/gong/ /home/xiang/
/home/gong/:
ifcfg-ens33

/home/xiang/:
ifcfg-ens33

 

 

3、常见问题分析:

3.1、防火墙问题

系统会提示:xxxx:errno 113 (No route to host) 说明端口被防火墙屏蔽,需开放2049端口

[root@localhost ~]# showmount -e 192.168.43.12
clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)

3.2、挂载错误

系统提示No such file or directory,说明服务器上没有相应的挂载点,检查挂载点

 

----------结束

 

posted on 2019-07-26 21:22  wangzy-Zj  阅读(533)  评论(0编辑  收藏  举报