Linux下部署NFS服务 (  ̄︶ ̄)_华为云linux nfs挂载 failed, reason given by server no

97 阅读6分钟

extras/primary_db                             

六  、在服务端 创建共享目录/data/nfs/,并且属主和属组都为:nfsnobody,其中nfsnobody是安装nfs服务时默认的用户;

[root@NFS ~]# mkdir -p /data/nfs/
[root@NFS ~]#  chown -R nfsnobody.nfsnobody /data/nfs/
[root@NFS ~]# chmod 666 /data/nfs/
[root@NFS ~]# ll /data/
总用量 4
drw-rw-rw-. 2 nfsnobody nfsnobody 4096 6月  27 06:17 nfs

七、编辑配置 NFS 配置文件 ;

[root@NFS ~]# cat >>/etc/exports<<EOF 

/data/nfs 172.16.1.0/24(rw,sync)
EOF
[root@NFS ~]# cat /etc/exports 
/data/nfs 172.16.1.0/24(rw,sync)
[root@NFS ~]# 

其中:/data/nfs 是服务器端共享的目录 
172.16.1.0/24共享目录的客户端ip地址 
(rw,sync) ,其中rw代表拥有读写的权限,sync代表数据同步写入NFS服务器端的硬盘中。
也可以用async,async是大数据时使用,是先写到缓存区,再写到磁盘里。

[root@NFS ~]# exportfs -r                           #让配置文件生效 

八、启动RPC 和 NFS 服务 ;

[root@NFS ~]# /etc/init.d/rpcbind start          # 先启动rpc  
[root@NFS ~]# /etc/init.d/nfs start                  #启动NFS
[root@NFS ~]# /etc/init.d/rpcbind status        #查看一下 rpc 的运行状态 
rpcbind (pid  27193) 正在运行...
[root@NFS ~]# /etc/init.d/nfs status               #查看一下 nfs 的运行状态 
rpc.mountd (pid 27337) 正在运行...
nfsd (pid 27353 27352 27351 27350 27349 27348 27347 27346) 正在运行...
[root@NFS ~]# 

 九、查看NFS服务是否向rpc注册端口信息,主端口号是:111 

   [root@NFS ~]# rpcinfo -p localhost
program vers proto   port  service
100000    4   tcp    111  portmapper
100000    3   tcp    111  portmapper
100000    2   tcp    111  portmapper
100000    4   udp    111  portmapper
100000    3   udp    111  portmapper
100000    2   udp    111  portmapper
100005    1   udp  46776  mountd
100005    1   tcp  58319  mountd
100005    2   udp  45857  mountd
100005    2   tcp  40719  mountd
100005    3   udp  48297  mountd
100005    3   tcp  56860  mountd

选项与参数:

-p :针对某 IP (未写则预设为本机) 显示出所有的 port 与 porgram 的信息;

-t :针对某主机的某支程序检查其 TCP 封包所在的软件版本;

-u :针对某主机的某支程序检查其 UDP 封包所在的软件版本;

十 、在NFS设定妥当之后,可以先在服务端自我测试一下是否可以联机!利用 showmount 这个指令来查看!

[root@NFS ~]# showmount -e localhost

Export list for localhost:

/data/nfs 172.16.1.0/24

[root@NFS ~]# 

选项与参数:
-a :显示目前主机与客户端的 NFS 联机分享的状态;
-e :显示某部主机的 /etc/exports 所分享的目录数据。
参数说明:
#rpcinfo  -p     检查nfs服务是否有注册端口信息
#showmount -e    检查共享目录信息 

十一 、设置服务为开机自启 ;

[root@NFS ~]# chkconfig nfs on
[root@NFS ~]# chkconfig --list nfs
nfs            0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
[root@NFS ~]# chkconfig --list rpcbind
rpcbind        0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
[root@NFS ~]# 

[root@NFS ~]# tail -2 /etc/rc.local           #加入到开机自启中 
/etc/init.d/rpcbind start 
/etc/init.d/nfs  start
[root@NFS ~]# 

==========================客户端配置=============================

一 、查看系统中是否有 nfs 和rpc  

[root@rsync ~]#  rpm -qa nfs-utils rpcbind

rpcbind-0.2.0-13.el6.x86_64

nfs-utils-1.2.3-75.el6.x86_64、

二 、进行安装服务,并启动服务  ;

[root@rsync ~]# yum -y install nfs-utils rpcbind
已加载插件:fastestmirror
设置安装进程
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.huaweicloud.com
* updates: mirrors.aliyun.com
base                                                                                                                         | 3.7 kB     00:00     
extras                                                                                                                       | 3.4 kB     00:00     
updates                                                                                                                      | 3.4 kB     00:00     
包 1:nfs-utils-1.2.3-75.el6_9.x86_64 已安装并且是最新版本

解决依赖关系

[root@rsync ~]# /etc/init.d/rpcbind start
[root@rsync ~]# /etc/init.d/nfs start
启动 NFS 服务:                                            [确定]
启动 NFS mountd:                                          [确定]
启动 NFS 守护进程:                                        [确定]
正在启动 RPC idmapd:                                      [确定]

三 、创建挂载目录  ;

[root@rsync]# mkdir -p /data/nfs

四 、查看客户端是否可以收到服务端的共享信息 ;

[root@rsync nfs]# showmount -e 172.16.1.9
Export list for 172.16.1.9:
/data/nfs 172.16.1.0/24
[root@rsync nfs]# 

五 、进行nfs 共享目录的挂载 ;

[root@rsync nfs]# mount -t nfs 172.16.1.9:/data/nfs /mnt

[root@rsync nfs]# df -h
Filesystem        Size  Used Avail Use% Mounted on
/dev/sda2          20G  2.7G   16G  15% /
tmpfs             931M     0  931M   0% /dev/shm
/dev/sda1         190M   39M  141M  22% /boot
172.16.1.9:/data/nfs    20G  2.7G   16G  15% /mnt

服务端 ;

[root@NFS nfs]# echo "nfs" > test.txt

客户端创建一个文件 ;

[root@rsync data]# cat /data/nfs/test.txt

nfs

########################### nfs常见问题排错思 ############################### 
nfs共享目录权限相关因素
①. 配置文件中的权限指定
②. 共享目录本身的权限,有w权限
③. 共享目录本身的所属用户与所属组的权限指定

######################  NFS客户端挂载排错思路 

客户端排查三部曲
①. 检查服务端房源信息是否还在
rpcinfo -p 172.16.1.9
②. 检查服务端共享目录信息是否存在
showmount -e 172.16.1.9
③. 直接进行目录挂载测试
mount -t nfs 172.16.1.9:/data /mnt

#########################  服务端排查三部曲  ################################# 
①. 检查服务端房源信息是否还在
rpcinfo -p localhost
如果没有注册的房源信息了,会是什么情况?
①. nfs服务没有启动
②. nfs服务于rpc服务启动顺序不正确
②. 检查服务端共享目录信息是否存在
showmount -e localhost
①. nfs配置文件编写格式错误
③. 直接进行目录挂载测试
mount -t nfs 172.16.1.9:/data /mnt

实现nfs客户端开机自动挂载方式

①. 将挂在命令追加到/etc/rc.local开机自启动文件中
②. 编写fstab文件,并且需要配合netfs服务使用,实现开机自动挂载

nfs常见问题排错 

示例1:客户端挂载报错“No such file or directory”
[root@nfs-client ~]# showmount -e 172.16.1.9
Export list for 172.16.1.9:
/data    172.16.1.0/24
[root@nfs-client ~]# mount -t nfs 172.16.1.9:/data /mnt
mount.nfs: mounting 172.16.1.9:/data failed, reason given by server: No such file or directory
解答:原因是NFS服务器端没有共享目录/data,创建即可。命令如下:
[root@nfs-server ~]# mkdir /data

示例2:NFS服务器端启动失败,如下:
[root@nfs-server ~]# /etc/init.d/nfs start
Starting NFS services: [  OK  ]
Starting NFS quotas: Cannot register service: RPC: Unable to receive; errno = Connection refused
rpc.rquotad: unable to register (RQUOTAPROG, RQUOTAVERS, udp).
[FAILED]
Starting NFS mountd: [FAILED]
Starting NFS daemon: rpc.nfsd: writing fd to kernel failed: errno 111 (Connection refused)
rpc.nfsd: unable to set any sockets for nfsd
[FAILED]
解答:这是因为RPC服务没有在NFS前面启动,需要先启动RPC服务再启动NFS,解决方法为,按顺序启动rpcbind及NFS,命令如下:
[root@nfs-server ~]# /etc/init.d/rpcbind restart

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

img img

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新 详情docs.qq.com/doc/DSmdCdUNwcEJDTXFK