0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WSLのAlmaLinuxでSFTP putが遅い時の解決策

Posted at

※ この記事は、Claude sonnetが100%書きました。

問題の概要

WSL2環境でAlmaLinuxを使用していると、SFTPでのファイル転送(特にputコマンド)が異常に遅くなることがあります。数百MBのファイルが数十KB/sでしか転送されない、といった症状です。

原因

WSL2のネットワーク仮想化層とAlmaLinuxのデフォルト設定により、以下の問題が発生します:

  • IPパケットのQoS設定が最適化されていない
  • TCP/IPスタックの設定がファイル転送に適していない
  • ネットワークバッファサイズが小さすぎる

解決策

1. SSH設定でIPQoSを最適化

~/.ssh/configに以下を追加します:

Host *
    IPQoS throughput
    Compression yes
    TCPKeepAlive yes
    ServerAliveInterval 60

IPQoS throughputの効果:

  • パケットをスループット重視モードに設定
  • ネットワーク機器に「大容量データ転送用」と指示
  • 遅延よりも帯域幅を優先

2. SFTPコマンドのオプション調整

# バッファサイズと同時リクエスト数を最適化
sftp -C -B 262144 -R 16 username@hostname

# 圧縮を無効化する場合(既に圧縮されたファイルなど)
sftp -o "Compression=no" -B 262144 -R 16 username@hostname

3. システムレベルのTCP設定調整

# /etc/sysctl.confに追加
sudo tee -a /etc/sysctl.conf << EOF
net.core.rmem_max = 134217728
net.core.wmem_max = 134217728
net.ipv4.tcp_rmem = 4096 87380 134217728
net.ipv4.tcp_wmem = 4096 65536 134217728
net.ipv4.tcp_window_scaling = 1
EOF

# 設定を反映
sudo sysctl -p

設定例

完全な~/.ssh/config設定例

# ファイル転送用サーバー
Host fileserver
    HostName your-server.com
    User username
    Port 22
    IPQoS throughput
    Compression yes
    TCPKeepAlive yes
    ServerAliveInterval 60
    ServerAliveCountMax 3
    Ciphers aes128-ctr,aes192-ctr,aes256-ctr
    MACs hmac-sha2-256,hmac-sha2-512

# すべてのサーバーに適用
Host *
    IPQoS throughput
    Compression yes
    TCPKeepAlive yes

使用例

# 設定後の転送コマンド
sftp -C -B 262144 fileserver
sftp> put large_file.zip

効果の確認

設定前後の速度比較

# テスト用ファイル作成
dd if=/dev/zero of=test_100mb.bin bs=1M count=100

# 設定前
time sftp username@hostname <<< "put test_100mb.bin"

# 設定後
time sftp -C -B 262144 username@hostname <<< "put test_100mb.bin"

期待される改善

  • 設定前: 50-100 KB/s
  • 設定後: 10-50 MB/s(環境により異なる)

代替案

rsyncを使用する場合

# SFTPより高速な場合が多い
rsync -avz --partial --progress -e "ssh -C -o IPQoS=throughput" file username@hostname:/path/

並列転送

# 複数ファイルを並列転送
find . -name "*.zip" | parallel -j 4 scp -C -o IPQoS=throughput {} username@hostname:/path/

注意点

  1. ネットワーク環境に依存:企業内ネットワークなどQoS対応環境で効果が高い
  2. 暗号化のオーバーヘッド:非常に高速なネットワークでは暗号化処理がボトルネックになる場合がある
  3. ファイルサイズ:小さなファイルでは効果が限定的

トラブルシューティング

SELinuxの影響確認

# SELinuxが影響している場合
getenforce
sudo setenforce 0  # 一時的に無効化してテスト

firewalldの影響確認

# firewalldが影響している場合
sudo systemctl status firewalld
sudo systemctl stop firewalld  # 一時的に停止してテスト

まとめ

WSLのAlmaLinuxでSFTP転送が遅い場合、IPQoS throughput設定が最も効果的な解決策です。これにより、ネットワーク機器にスループット重視の処理を指示し、大幅な速度改善が期待できます。

設定は簡単で副作用も少ないため、WSL環境でのファイル転送に困っている方はぜひ試してみてください。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?