sshfs가 잠기면 자동으로 재설정되며 수동으로 수행하지 않으면 다시 마운트가 실패합니다.

sshfs가 잠기면 자동으로 재설정되며 수동으로 수행하지 않으면 다시 마운트가 실패합니다.

원격 서버에 마운트된 내 서버에 2개의 로컬 디렉토리가 있습니다. 로컬은 autossh -M 23 -R 24:localhost:22 user@serverdirs-sshfs.sh를 사용하여 원격 마운트하는 동안 연결을 유지합니다.

sshfs -o reconnect,ServerAliveInterval=15,ServerAliveCountMax=3,cache_timeout=3600 [email protected]:/mnt/localdir1/ /home/user/dir1/ -p 24
sshfs -o reconnect,ServerAliveInterval=15,ServerAliveCountMax=3,cache_timeout=3600 [email protected]:/mnt/localdir2/ /home/user/dir2/ -p 24

잠기면 sshfs-restart.sh를 사용하여 연결을 재설정합니다.

pkill -kill -f "sshfs"
fusermount -uz dir1
fusermount -uz dir2
./dirs-sshfs.sh

모두 잘 작동하지만 1) 잠겨 있는지 확인하고 2) 수동으로 재설정해야 합니다.

이것을 까다롭게 만드는 것은 잠기면 홈 디렉토리의 ls도 재설정될 때까지 무한정 잠긴다는 것입니다. 이 때문에 원격 서버 측에서 관리하는 것을 포기했습니다. autossh 연결이 유지되는 로컬 서버 측에는 거의 작동하는 다음 스크립트가 있습니다. 이는 실패할 때 이를 포착하고 연결을 재설정하려고 시도하지만 마운트 해제 후 다시 마운트되지 않습니다. ssh-restart.sh 안에 dirs-sshfs.sh 콘텐츠를 넣으려고 시도했지만 포함된 run-sshfs-restart.sh 원격 서버 측에서도 ./sshfs-restart.sh &작동하지 않았습니다. 테스트 스크립트(testsshfs2.sh)에는 ls; echo; ls dir1; echo; ls dir2; echo; date; echo모든 것이 마운트/작동하는지 확인하는 빠르고 쉬운 방법으로 작성된 스크립트가 포함되어 있습니다.

이것은 sshfsmanager.sh이며, sleep 명령을 사용하여 while 루프 내부의 로컬 서버에서 실행됩니다. 미래에는 아마도 그것을 cronjob으로 옮길 것입니다

sshout=$(timeout 300 ssh user@host ./testsshfs2.sh)
# timeout duration probably doesnt need to be that long, but sometimes it does take 90+ sec to ls
# the remote dirs as they are network shares mounted to a vm that are then mounted across a ssh
# tunnel. Once this is working, that duration would be fine tuned. Also 100 is just an arbitrary
# number larger than ls | wc -l would provide. It should be updated to where it would catch if
# either of the mounts fail instead of only when both do. This timeout method is the only way
# ive found to get around the infinite ls lock.

if [ `echo "$sshout" | wc -l` -le 100 ]; then
  echo "$sshout" | wc -l
  ssh user@host ./sshfs-restart.sh
  #adding a "&& sleep 60" or using the run-sshfs-restart.sh script did not work

  echo sshfs restarted
else
  echo sshfs is fine
  echo "$sshout" | wc -l
fi

대부분의 스크립트에는 여기에 넣을 때 제거된 로깅이 있습니다(포트 변경 및 사용자/호스트 제거 포함). 대부분의 모든 로깅 라인은 날짜 >> sshfsmanager.log입니다.

로컬 VM은 우분투 18.04.5를 실행하고 원격 서버는 젠투 5.10.27을 실행하는 공유 VPS입니다.

관련 정보