SSHFS(Secure SHell FileSystem)是一个客户端,可以让我们通过 SSH 文件传输协议(SFTP)挂载远程的文件系统并且在本地机器上和远程的目录和文件进行交互
yum install epel-release
yum install sshfs
挂载远程目录
创建普通用户
useradd fsuser
passwd fsuser
密码登录挂载
sshfs -o rw,nosuid,nodev,allow_other,reconnect,nonempty,port=63210 fsuser@192.168.1.126:/data/abc /mnt/abc
密钥免登陆挂载
ssh-keygen
ssh-copy-id -i /home/fsuser/.ssh/id_rsa.pub fuser@192.168.1.126
sshfs -o rw,nosuid,nodev,allow_other,reconnect,nonempty,port=63210,IdentityFile=/home/fsuser/.ssh/id_rsa fsuser@192.168.1.126:/data/abc /mnt/abc
卸载挂载点
fusermount -u /mnt/abc
永久挂载远程文件系统
vim /etc/fstab
sshfs#fsuser@192.168.1.126:/data/abc /mnt/abc fuse defaults,rw,nosuid,nodev,allow_other,reconnect,nonempty,port=63210,IdentityFile=/home/fsuser/.ssh/id_rsa 0 0
挂载点健康监测
vim checkmount.sh
#!/bin/bash
MOUNT1=/mnt/abc
MOUNT2=/mnt/123
if (mountpoint -q $MOUNT1 && mountpoint -q $MOUNT2);then
echo "mount is ok!"
else
mount -a
fi