由于在Linux板子之间实现NFS文件系统挂载实现较为困难,所以改为sshfs文件系统挂载,下面一步步探索sshfs挂载的流程和实验。首先在2个虚拟机Linux系统之间测试sshfs相互挂载,然后使用buildroot编译sshfs下载到Linux板子中测试。
ubuntu 18.04
查看IP地址
logread@logread:~$ ifconfig ens33: flags=4163
mtu 1500 inet 192.168.201.132 netmask 255.255.255.0 broadcast 192.168.201.255 inet6 fe80::20c:29ff:fe38:3f29 prefixlen 64 scopeid 0x20
ether 00:0c:29:38:3f:29 txqueuelen 1000 (Ethernet) RX packets 7256 bytes (9.4 MB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1688 bytes (170.4 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
安装sshfs软件
logread@logread:~$ sudo apt-get install fuse-sshfs [sudo] password for logread: Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package fuse-sshfs logread@logread:~$ sudo apt-get install sshfs Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: sshfs 0 upgraded, 1 newly installed, 0 to remove and 64 not upgraded. Need to get 41.3 kB of archives. After this operation, 114 kB of additional disk space will be used. Get:1 https://mirrors.aliyun.com/ubuntu bionic/universe amd64 sshfs amd64 2.8-1 [41.3 kB] Fetched 41.3 kB in 0s (102 kB/s) Selecting previously unselected package sshfs. (Reading database ... files and directories currently installed.) Preparing to unpack .../archives/sshfs_2.8-1_amd64.deb ... Unpacking sshfs (2.8-1) ... Setting up sshfs (2.8-1) ... Processing triggers for man-db (2.8.3-2ubuntu0.1) ... logread@logread:~$
查看sshfs版本
logread@logread:~$ sshfs --version SSHFS version 2.8 FUSE library version: 2.9.7 fusermount version: 2.9.7 using FUSE kernel interface version 7.19
查看支持的sshfs文件系统
logread@logread:~$ cat /proc/filesystems nodev sysfs nodev rootfs nodev ramfs nodev bdev nodev proc nodev cpuset nodev cgroup nodev cgroup2 nodev tmpfs nodev devtmpfs nodev configfs nodev debugfs nodev tracefs nodev securityfs nodev sockfs nodev dax nodev bpf nodev pipefs nodev hugetlbfs nodev devpts ext3 ext2 ext4 squashfs vfat nodev ecryptfs fuseblk nodev fuse nodev fusectl nodev pstore nodev mqueue btrfs nodev autofs
CentOS 7.3
查看IP地址
[yubo.wang@localhost ~]$ ifconfig ens33: flags=4163
mtu 1500 inet 192.168.201.130 netmask 255.255.255.0 broadcast 192.168.201.255 inet6 fe80::890e:5af4:e734:af0d prefixlen 64 scopeid 0x20
ether 00:0c:29:33:16:9e txqueuelen 1000 (Ethernet) RX packets 15717 bytes (20.0 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 4633 bytes (432.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
安装sshfs软件
[yubo.wang@localhost ~]$ sudo yum install fuse-sshfs [sudo] password for yubo.wang: Loaded plugins: auto-update-debuginfo, fastestmirror Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast base | 3.6 kB 00:00:00 base-debuginfo | 2.5 kB 00:00:00 epel/x86_64/metalink | 9.4 kB 00:00:00 epel | 4.7 kB 00:00:00 epel-debuginfo/x86_64/metalink | 9.3 kB 00:00:00 epel-debuginfo | 3.0 kB 00:00:00 extras | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 (1/7): epel/x86_64/group_gz | 95 kB 00:00:00 (2/7): epel/x86_64/updateinfo | 1.0 MB 00:00:00 (3/7): extras/7/x86_64/primary_db | 165 kB 00:00:00 (4/7): epel/x86_64/primary_db | 6.8 MB 00:00:00 (5/7): epel-debuginfo/x86_64/primary_db | 803 kB 00:00:00 (6/7): updates/7/x86_64/primary_db | 7.6 MB 00:00:01 (7/7): base-debuginfo/x86_64/primary_db | 2.8 MB 00:06:33 Determining fastest mirrors * base: mirrors.aliyun.com * epel: mirrors.aliyun.com * epel-debuginfo: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com Resolving Dependencies --> Running transaction check ---> Package fuse-sshfs.x86_64 0:2.10-1.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved =================================================================================== Package Arch Version Repository Size =================================================================================== Installing: fuse-sshfs x86_64 2.10-1.el7 epel 50 k Transaction Summary =================================================================================== Install 1 Package Total download size: 50 k Installed size: 103 k Is this ok [y/d/N]: y Downloading packages: fuse-sshfs-2.10-1.el7.x86_64.rpm | 50 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : fuse-sshfs-2.10-1.el7.x86_64 1/1 Verifying : fuse-sshfs-2.10-1.el7.x86_64 1/1 Installed: fuse-sshfs.x86_64 0:2.10-1.el7 Complete! [yubo.wang@localhost ~]$ sshfs --version SSHFS version 2.10 FUSE library version: 2.9.2 fusermount version: 2.9.2 using FUSE kernel interface version 7.19
查看支持的文件系统
[yubo.wang@localhost ~]$ cat /proc/filesystems nodev sysfs nodev rootfs nodev ramfs nodev bdev nodev proc nodev cgroup nodev cpuset nodev tmpfs nodev devtmpfs nodev debugfs nodev securityfs nodev sockfs nodev pipefs nodev anon_inodefs nodev configfs nodev devpts nodev hugetlbfs nodev autofs nodev pstore nodev mqueue nodev selinuxfs xfs nodev rpc_pipefs nodev nfsd fuseblk nodev fuse nodev fusectl
ubuntu挂载centos
logread@logread:~$ sshfs root@192.168.201.130:/home/yubo.wang/sshfs-dir /home/logread/sshfs-dir The authenticity of host '192.168.201.130 (192.168.201.130)' can't be established. ECDSA key fingerprint is SHA256:cvXKQ2H2nAm+jgN8FjygG/BbubibbHxZridZwoh+FTU. Are you sure you want to continue connecting (yes/no)? yes root@192.168.201.130's password: logread@logread:~$
挂载查询
sshfs (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000) root@192.168.201.130:/home/yubo.wang/sshfs-dir 116G 99G 18G 85% /home/logread/sshfs-dir sudo umount /home/logread/sshfs-dir
挂载成功,写文件成功
centos挂载ubuntu
挂载测试
[yubo.wang@localhost ~]$ sshfs root@192.168.201.132:/home/logread/sshfs-dir /home/yubo.wang/sshfs-dir fuse: mountpoint is not empty【目录里面有a.c文件,不为空,难道不能挂载非空目录?】【-o nonempty】 fuse: if you are sure this is safe, use the 'nonempty' mount option [yubo.wang@localhost ~]$ sshfs root@192.168.201.132:/home/logread/sshfs-dir /home/yubo.wang/sshfs-dir The authenticity of host '192.168.201.132 (192.168.201.132)' can't be established.【不检查key:-o StrictHostKeyChecking=no】 ECDSA key fingerprint is 0c:8d:16:d2:ff:d0:9a:02:0b:f5:ab:92:a9:02:f4:e3. Are you sure you want to continue connecting (yes/no)? yes root@192.168.201.132's password: root@192.168.201.132's password: root@192.168.201.132's password: 【密码怎么会不对?】 read: Connection reset by peer [yubo.wang@localhost ~]$
难道是ubuntu不支持nfsd?不用root用户改为logread用户挂载成功
[yubo.wang@localhost ~]$ sshfs -o StrictHostKeyChecking=no logread@192.168.201.132:/home/logread/sshfs-dir /home/yubo.wang/sshfs-dir logread@192.168.201.132's password: [yubo.wang@localhost ~]$ logread@192.168.201.132:/home/logread/sshfs-dir on /home/yubo.wang/sshfs-dir type fuse.sshfs (rw,nosuid,nodev,relatime,user_id=1002,group_id=1002) logread@192.168.201.132:/home/logread/sshfs-dir 49G 40G 7.1G 85% /home/yubo.wang/sshfs-dir
读写文件成功,卸载成功
fusermount -u /home/yubo.wang/sshfs-dir
卸载Ubuntu的fuse
logread@logread:~$ sudo apt-get remove fuse Reading package lists... Done Building dependency tree Reading state information... Done The following packages will be REMOVED: fuse ntfs-3g sshfs 0 upgraded, 0 newly installed, 3 to remove and 64 not upgraded. After this operation, 1,620 kB disk space will be freed. Do you want to continue? [Y/n] y (Reading database ... files and directories currently installed.) Removing ntfs-3g (1:2017.3.23-2ubuntu0.18.04.2) ... Removing sshfs (2.8-1) ... Removing fuse (2.9.7-1ubuntu1) ... update-initramfs: deferring update (trigger activated) Processing triggers for man-db (2.8.3-2ubuntu0.1) ... Processing triggers for initramfs-tools (0.130ubuntu3.8) ... update-initramfs: Generating /boot/initrd.img-4.15.0-96-generic logread@logread:~$
fuse依然存在,sshfs命令消失,说明只卸载了sshfs命令,不能挂载其他设备,但能被挂载
logread@logread:~$ cat /proc/filesystems nodev sysfs nodev rootfs nodev ramfs nodev bdev nodev proc nodev cpuset nodev cgroup nodev cgroup2 nodev tmpfs nodev devtmpfs nodev configfs nodev debugfs nodev tracefs nodev securityfs nodev sockfs nodev dax nodev bpf nodev pipefs nodev hugetlbfs nodev devpts ext3 ext2 ext4 squashfs vfat nodev ecryptfs fuseblk nodev fuse nodev fusectl nodev pstore nodev mqueue btrfs nodev autofs
挂载是否成功:也能挂载,能看到文件
[yubo.wang@localhost ~]$ sshfs -o StrictHostKeyChecking=no logread@192.168.201.132:/home/logread/sshfs-dir /home/yubo.wang/sshfs-dir logread@192.168.201.132's password: [yubo.wang@localhost ~]$
重启ubuntu后也能被挂载。
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/228924.html原文链接:https://javaforall.net
