Linux NFS文件系统挂载

一般情况下,都是虚拟机Linux系统挂载开发板方便进行应用程序的调试,或者反过来进行挂载。但是我们需要开发板之间相互挂载进行数据传输。

虚拟机之间挂载

环境:Ubuntu 18.04与CentOS 7之间挂载

方法:CentOS作为 NFS 客户端透明地读写位于Ubuntu 端 NFS 服务器上的文件,就像访问本地文件一样。

Ubuntu 服务端

sudo apt-get install nfs-kernel-server #安装 NFS 服务

查看内核是否支持nfs

查看nfs进程是否启动,主要看nfsd

卸载nfs-kernel-server后nfsd进程会关闭掉,其他的配置不会变化

扫描二维码关注公众号,回复: 6747169 查看本文章


接着用管理员权限(sudo)打开 ubuntu 中/etc/exports 文件,在末尾添加:/home/user/ *(rw,sync,no_root_squash)

sudo /etc/init.d/nfs-kernel-server restart #重启 NFS 服务,使之前配置生效【这里需要被挂载的目录存在否则会服务不能启动】

showmount -e #查看修改是否生效

查看ubuntu ip地址

CentOS 客户端

mkdir /mnt/nfs #建立一个名为“nfs”的目录,用于挂载 ubuntu 共享的 nfs 文件夹
挂载命令:

[yubo.wang@localhost ~]$ sudo mount -t nfs -o nolock 192.168.201.131:/home/logread/nfs /mnt/nfs

查看挂载:

192.168.201.131:/home/logread/nfs on /mnt/nfs type nfs4 (rw,relatime,vers=4.1,rsize=262144,wsize=262144,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.201.130,local_lock=none,addr=192.168.201.131)

虚拟机和开发板之间挂载

草稿

8、安装NFS
	apt-get purge rpcbind
	apt-get install nfs-kernel-server nfs-common
 	
	vim /etc/exports
	加入/home/yubo.wang/nfsroot *(rw,sync,no_root_squash,no_subtree_check)	
		
	mkdir nfsroot
	sudo /etc/init.d/nfs-kernel-server restart
		[sudo] password for yubo.wang: 
		 * Stopping NFS kernel daemon                                                                                                            [ OK ] 
		 * Unexporting directories for NFS kernel daemon...                                                                                      [ OK ] 
		 * Exporting directories for NFS kernel daemon...                                                                                        [ OK ] 
		 * Starting NFS kernel daemon                                                                                                            [ OK ]

	yubo.wang@ubuntu:~$ showmount -e
	Export list for ubuntu:
	/home/yubo.wang/nfsroot *
	
	开发板挂载服务器:
	mount -t nfs -o nolock 192.168.1.50:/home/yubo.wang/nfsroot /yubo.wang
		 
	问题:	 
		 服务器不能ping通开发板WAN/LAN0,能ping通电脑无线网卡,不能ping通互联网和电脑有线网卡
	原因:
		有线网络和无线网共存时,ping默认是走有线网络,所以需要把无线网络禁用
		
root@ubuntu:~# ifconfig 
eth0      Link encap:Ethernet  HWaddr 00:0c:29:34:4b:95  
          inet addr:192.168.1.50  Bcast:192.168.1.255  Mask:255.255.255.0
		  
root@ZhuoTK:/# ifconfig 
br-lan    Link encap:Ethernet  HWaddr 00:CA:2F:07:0F:C6  
          inet addr:192.168.1.251  Bcast:192.168.1.255  Mask:255.255.255.0

以太网适配器 以太网:
   连接特定的 DNS 后缀 . . . . . . . :
   本地链接 IPv6 地址. . . . . . . . : fe80::f0f0:40f7:a883:6c2%14
   IPv4 地址 . . . . . . . . . . . . : 192.168.1.123
   子网掩码  . . . . . . . . . . . . : 255.255.255.0
   默认网关. . . . . . . . . . . . . : 192.168.1.1

   
root@ZhuoTK:/# mount -t nfs -o nolock 192.168.1.50:/home/yubo.wang/nfsroot /yubo.wang
	
192.168.1.50:/home/yubo.wang/nfsroot on /yubo.wang type nfs (rw,relatime,vers=3,rsize=131072,wsize=131072,namlen=255,hard,nolock,proto=tcp,timeo=600,retrans=2,sec=sys,mountaddr=192.168.1.50,mountvers=3,mountproto=tcp,local_lock=all,addr=192.168.1.50)
		
192.168.1.50:/home/yubo.wang/nfsroot
                         47.1G     22.0G     22.7G  49% /yubo.wang
		 
	
开发板挂载服务器:
mount -t nfs -o nolock 192.168.1.251:/yubo.wang /root/nfs


 < >   NFS client support
 < >   NFS server support

nodev	nfs

root@ZhuoTK:/# ps |grep nfs
  630 root         0 SW<  [nfsiod]
 1398 root      1488 S    grep nfs
root@ZhuoTK:/# ps |grep rpc
  609 root         0 SW<  [rpciod]
  820 root      1568 S    /sbin/rpcd
 1400 root      1488 S    grep rpc


root@ZhuoTK:/# opkg install /tmp/nfs-kernel-server_1.3.2-3_ramips_24kec.ipk 
Installing nfs-kernel-server (1.3.2-3) to root...
Collected errors:
 * satisfy_dependencies_for: Cannot satisfy the following dependencies for nfs-kernel-server:
 * 	libwrap * 	libblkid * 	librpc * 	kmod-fs-nfsd * 	portmap * 
 * opkg_install_cmd: Cannot install package nfs-kernel-server.
	
	
	
root@ZhuoTK:/tmp# opkg install nfs-kernel-server_1.3.2-3_ramips_24kec.ipk 
Installing nfs-kernel-server (1.3.2-3) to root...
Configuring nfs-kernel-server.
exportfs: /etc/exports [1]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/mnt/nfs/".
  Assuming default behaviour ('no_subtree_check').
  NOTE: this default has changed since nfs-utils version 1.0.x

exportfs: /mnt/nfs does not support NFS export
Collected errors:
 * resolve_conffiles: Existing conffile /etc/exports is different from the conffile in the new package. The new conffile will be placed at /etc/exports-opkg.
	
	no_subtree_check
/mnt    *(ro,all_squash,insecure,sync,no_subtree_check)
	
	
root@ZhuoTK:/tmp# opkg install nfs-kernel-server_1.3.2-3_ramips_24kec.ipk 
Installing nfs-kernel-server (1.3.2-3) to root...
Configuring nfs-kernel-server.
exportfs: /mnt does not support NFS export 【这个错误怎么解?难道没有关系,查看ipk已经安装成功了的】
Collected errors:
 * resolve_conffiles: Existing conffile /etc/exports is different from the conffile in the new package. The new conffile will be placed at /etc/exports-opkg.
	
/mnt    *(ro,all_squash,insecure,sync,no_subtree_check)
	
 * resolve_conffiles: Existing conffile /etc/exports is different from the conffile in the new package. The new conffile will be placed at /etc/exports-opkg.
	
	挂载失败
root@ubuntu:~# mount -t nfs -o nolock 192.168.1.251:/yubo.wang /root/aa
mount.nfs: access denied by server while mounting 192.168.1.251:/yubo.wang

	vi /etc/hosts
	127.0.0.1 localhost

root@ubuntu:/home/yubo.wang# mount -t nfs -o nolock 192.168.1.251:/yubo.wang /root/nfs
mount.nfs: access denied by server while mounting 192.168.1.251:/yubo.wang
	
root@ZhuoTK:~# nfsstat 
Server rpc stats:
calls      badcalls   badfmt     badauth    badclnt
1          1          1          0          0       

Server nfs v3:
null         getattr      setattr      lookup       access       readlink     
1       100% 0         0% 0         0% 0         0% 0         0% 0         0% 
read         write        create       mkdir        symlink      mknod        
0         0% 0         0% 0         0% 0         0% 0         0% 0         0% 
remove       rmdir        rename       link         readdir      readdirplus  
0         0% 0         0% 0         0% 0         0% 0         0% 0         0% 
fsstat       fsinfo       pathconf     commit       
0         0% 0         0% 0         0% 0         0% 

Client rpc stats:
calls      retrans    authrefrsh
15         0          15      

Client nfs v3:
null         getattr      setattr      lookup       access       readlink     
0         0% 6        42% 0         0% 0         0% 1         7% 0         0% 
read         write        create       mkdir        symlink      mknod        
0         0% 0         0% 0         0% 0         0% 0         0% 0         0% 
remove       rmdir        rename       link         readdir      readdirplus  
0         0% 0         0% 0         0% 0         0% 0         0% 1         7% 
fsstat       fsinfo       pathconf     commit       
0         0% 4        28% 2        14% 0         0% 
	
	有连接过来,但是失败了,难道是防火墙导致问题的吗?
	
root@ZhuoTK:~# /etc/init.d/firewall stop
Warning: Unable to locate ipset utility, disabling ipset support
 * Flushing IPv4 filter table
 * Flushing IPv4 nat table
 * Flushing IPv4 mangle table
 * Flushing IPv4 raw table
 * Flushing IPv6 filter table
 * Flushing IPv6 mangle table
 * Flushing IPv6 raw table
 * Flushing conntrack table ...

启用SYN-flood防御  关闭
	
	不行
 
 /etc/init.d/firewall disable
 
Sat May 25 14:55:07 2019 daemon.notice rpc.mountd[1277]: authenticated mount request from 192.168.1.50:936 for /yubo.wang (/yubo.wang)
Sat May 25 14:55:07 2019 daemon.warn rpc.mountd[1277]: Cannot export /yubo.wang, possibly unsupported filesystem or fsid= required

Sat May 25 21:22:45 2019 daemon.notice rpc.mountd[1277]: authenticated mount request from 192.168.1.50:971 for /yubo.wang (/yubo.wang)
Sat May 25 21:22:45 2019 daemon.warn rpc.mountd[1277]: Cannot export /yubo.wang, possibly unsupported filesystem or fsid= required

 
查看nfs server的/var/log/message:
Mar 30 14:53:07 sysimages mountd[6936]: Cannot export /panfs, possibly unsupported filesystem or fsid= required
Mar 30 14:54:04 sysimages kernel: Removing netfilter NETLINK layer.

在NFS server的 /etc/exports文件里做如下改动 fsid = 0:

/sdc                           *(rw,insecure,sync,insecure_locks,no_root_squash)
/panfs                           *(fsid=0,rw,insecure,sync,insecure_locks,no_root_squash)
	依然没用,重启还没用

挂载卡住不动说明网络没有通,服务端rpc没有看到连接

参考:openwrt系统,作为路由器使用,跨网段nfs挂载共享目录【NO】

/etc/exports下最后行新增一行,不要修改原来的内容【NO】

网络连接方式改为桥接方式【已经是桥接方式】

开发板之间挂载

从了解到放弃

猜你喜欢

转载自blog.csdn.net/TSZ0000/article/details/90511560