• home
  • about
  • 全ての投稿
  • ソフトウェア・ハードウェアの設定のまとめ
  • 分析関連のまとめ
  • ヘルスケア関連のまとめ
  • 生涯学習関連のまとめ

sshfs

date: 2020-05-21 excerpt: sshfs

tag: sshfsssh


sshfs

概要

  • 2023年現在、メンテナンスが終了し、アーカイブされたので代替が必要になる可能性がある
  • sshのプロトコルを用いた簡易的なnfsのように使えるファイルシステム
  • fuseを利用する
  • macOSで使用したい場合、/macFUSE/が必要
    • macFUSEのAPIを介したアクセスになるので細かい点でlinuxのsshfsと操作感が異なる

パフォーマンス

  • デフォルトでは nfs より遅い
  • パフォーマンスチューニングすると、nfsと同じか一部早くなるなど、実用性が高い

コマンドによるマウント

一般的なマウント

$ sshfs -o <option-args> <source> <target>
  • オプション凡例
    • follow_symlinks
      • 接続先でシンボリックリンクを追うかどうか
    • compression=<yes|no>
      • データの圧縮の有無
      • 圧縮しないほうが早い
    • Ciphers=<method>
      • 暗号化方式
      • 暗号化がロバストなほど通信が遅くなる
    • cache=<yes|no>
      • cacheを使用するかどうか
    • dir_cache=<yes|no>
      • ディレクトリの情報をキャッシュするか
    • max_conns=<num>
      • 同時に接続するsshの数
      • プロセスもその分必要となる
    • reconnect
      • 接続が切断された際に再接続するかどうか
    • StrictHostKeyChecking=<yes|no>
      • 接続先のフィンガープリントの検証を行うかどうか
    • identityfile=<path-to-secret>
      • 秘密鍵を明示的に指定

パフォーマンスを考慮したマウントオプションスニペット

$ sshfs -o StrictHostKeyChecking=no,reconnect,cache=yes,max_conns=64,dir_cache=yes,follow_symlinks <source> <target>

パフォーマンスを考慮したオプションのベンチマーク

  • CrystalDiskMark互換の/fio/ベンチマーク

デフォルト

Sequential Q32T1 Read: 111MB/s IOPS=13
Sequential Q32T1 Write: 111MB/s IOPS=13

4KB Q8T8 Read: 108MB/s IOPS=27708
4KB Q8T8 Write: 110MB/s IOPS=28198

4KB Q32T1 Read: 109MB/s IOPS=27956
4KB Q32T1 Write: 110MB/s IOPS=28209

4KB Q1T1 Read: 16MB/s IOPS=4238
4KB Q1T1 Write: 4MB/s IOPS=1192

パフォーマンス考慮オプション

Sequential Q32T1 Read: 111MB/s IOPS=13
Sequential Q32T1 Write: 111MB/s IOPS=13

4KB Q8T8 Read: 107MB/s IOPS=27473
4KB Q8T8 Write: 110MB/s IOPS=28228

4KB Q32T1 Read: 108MB/s IOPS=27715
4KB Q32T1 Write: 110MB/s IOPS=28177

4KB Q1T1 Read: 16MB/s IOPS=4270
4KB Q1T1 Write: 106MB/s IOPS=27363

fstabを用いた接続

  • /fstab/を用いてマウントを自動化できる

具体例

<username>@<remote>:/home/<username> /home/<username>/.mnt/<remote> fuse.sshfs StrictHostKeyChecking=no,reconnect,identityfile=/home/<username>/.ssh/privatekey 0 0

カーネルパラメータによるパフォーマンス向上

カーネルパラメータを調整する

  • /etc/sysctl.confに以下を追記する
net.core.netdev_max_backlog = 3000
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_moderate_rcvbuf = 0
net.ipv4.tcp_no_metrics_save = 1
net.ipv4.tcp_rmem = 131072 1048576 16777216
net.ipv4.tcp_wmem = 131072 1048576 16777216

トラブルシューティング

mvコマンドを使用するとmv: failed to preserve ownership for ...と表示される

  • 原因
    • 所有者グループ情報が不完全なので起きる問題
    • sshfs以外のファイルシステムでも起きる可能性もある
  • 対応
    • mvではなくcp + rmで代替する
  • 参考
    • How to move a file without preserving permissions


sshfsssh Share Tweet