我通过ssh隧道(转发2端口)在本地机器转发远程nfs端口,使用autossh进行持久连接:
[email protected]:~#autossh -v -M 0 -q -f -N -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -R 2049:localhost:2049 [email protected] [email protected]:~#autossh -v -M 0 -q -f -N -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -R 2059:localhost:2059 [email protected]
现在我已经在local.machine远程nfs端口监听local.machine:
[email protected]:~# netstat -ntpl Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:2049 0.0.0.0:* LISTEN 27882/sshd: tunnel tcp 0 0 127.0.0.1:2059 0.0.0.0:* LISTEN 27881/sshd: tunnel
在/ etc / fstab中使用此configurationconfiguration远程nfs挂载点:
localhost:/var/pub /mnt/remote.machine nfs tcp,rsize=8192,wsize=8192,rw,bg,intr,noatime,nosuid,noauto,vers=3,port=2049,mountport=2059 0 0
并将其挂载到/mnt/remote.machine/中:
[email protected]:~# mount /mnt/remote.machine [email protected]:~# mount -lt nfs localhost:/var/pub on /mnt/remote.machine/ type nfs (rw,nosuid,noatime,tcp,rsize=8192,wsize=8192,bg,intr,vers=3,port=2049,mountport=2059,addr=127.0.0.1)
那么现在远程nfs文件系统可以作为本地目录访问…
问题:
当在remote.machine NFS服务停止和/或SSH隧道坏了,如何从local.machinetesting这个条件? 我使用这个系统自动化(与crond)从local.machine备份到remote.machine
我想到了运行简单的testing:
[email protected]:〜#[-d /mnt/remote.machine/remote/backups] && ./run-backups.sh
但是当我运行它,命令冻结而remote.machine回到网上! 和自动化失败!
如果有人有一个更好的主意,例如使用rsync或其他,请提出。 条件是备份必须从local.machine执行到remote.machine(它有一个dynamicIP)出于安全原因和权限问题。
编辑:使用选项进行安装:retrans = 1,timeo = 1,soft,fg,retry = 1,tcp,vers = 3或:retrans = 1,timeo = 1,soft,bg,retry = 1,tcp,vers = 3问题仍然存在,并冻结任何文件系统命令(例如:ls,test -d),并在2分钟后:50秒打印“input/输出错误”
您需要添加soft装载选项 ,否则NFS客户端会重试请求。
它仍然需要timeo * retrans作为超时的尝试,默认是3min。
您可以在备份过程之前检查安装点是否可见
timeout 10 ls /mountpoint >& /dev/null && /backup/script
像这样,它不会挂起挂载点是陈旧的。