首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过SSH隧道的连接开始缓慢

通过SSH隧道的连接开始缓慢
EN

Server Fault用户
提问于 2022-03-08 21:14:19
回答 1查看 696关注 0票数 1

我已经构建了一个运行在基于阿尔卑斯的容器中的SSH隧道服务,该服务基于这里概述的方法:https://github.com/cagataygurturk/docker-ssh-tunnel

该服务通过IdentityFiles连接,并设置多个ControlSockets和隧道。

我正在一个Amazon平台上测试这个问题,通过隧道进入一个PostgreSQL数据库。

SSH登录和隧道创建是正确的,隧道可以使用,但似乎有一个超时某处。

  • 如果隧道(可能是整个目标SSH服务器的连接)被闲置5分钟,然后连接到该隧道,则连接进程挂起30秒,然后成功地继续。
  • 在第一个连接之后的隧道连接是快速-次秒。
  • 让隧道/服务器空闲5分钟,30秒的延迟就回来了。

以下是证据:

客户端ssh-config

代码语言:javascript
复制
Host my-bastion
    HostName 99.99.99.99
    User ec2-user
    IdentityFile ~/.ssh/key.pem

Host *
    ControlMaster auto
    ControlPath ~/.ssh/controlmasters/cp_%r_%h
    ControlPersist yes
    StrictHostKeyChecking no
    ServerAliveCountMax 60
    ServerAliveInterval 30
    TCPKeepAlive no
    ForkAfterAuthentication yes
    StdinNull yes
    ExitOnForwardFailure yes
    IPQoS 0x00

测试工作流

以前使用ControlSocket建立的隧道。

使用验证失败的psql请求进行测试,但执行隧道操作。

在测试期间,psql通过隧道进行2次连接。

第一次访问后,至少5分钟空闲。

代码语言:javascript
复制
# date && time psql "host=localhost port=5430 dbname=xxx user=UUU password=X"
Tue Mar  8 12:10:57 PST 2022
psql: error: FATAL:  password authentication failed for user "UUU"
FATAL:  password authentication failed for user "UUU"

real    0m32.497s - slow!

客户端日志-vv

代码语言:javascript
复制
1st psql request

[2022-03-08 20:10:57] debug1: Connection to port 5430 forwarding to xxx.us-east-1.rds.amazonaws.com port 5432 requested.
[2022-03-08 20:10:57] debug1: channel 3: new [direct-tcpip]

30 sec Delay here
[2022-03-08 20:10:57] debug2: channel 3: open confirm rwindow 2097152 rmax 32768

[2022-03-08 20:11:29] debug2: channel 3: read<=0 rfd 7 len 0


2nd psql request

[2022-03-08 20:11:29] debug1: Connection to port 5430 forwarding to xxx.us-east-1.rds.amazonaws.com port 5432 requested.
[2022-03-08 20:11:29] debug1: channel 4: new [direct-tcpip]

subsecond response on channel 4

[2022-03-08 20:11:29] debug2: channel 4: open confirm rwindow 2097152 rmax 32768

[2022-03-08 20:11:29] debug2: channel 4: read<=0 rfd 8 len 0

第一次之后立即进入。

代码语言:javascript
复制
# date && time psql "host=localhost port=5430 dbname=xxx user=UUU password=X"
Tue Mar  8 12:11:41 PST 2022
psql: error: FATAL:  password authentication failed for user "UUU"
FATAL:  password authentication failed for user "UUU"

real    0m0.874s - fast!
user    0m0.021s
sys     0m0.016s

1st psql request

[2022-03-08 20:11:41] debug1: Connection to port 5430 forwarding to xxx.us-east-1.rds.amazonaws.com port 5432 requested.
[2022-03-08 20:11:41] debug2: fd 7 setting TCP_NODELAY
[2022-03-08 20:11:41] debug2: fd 7 setting O_NONBLOCK
[2022-03-08 20:11:41] debug1: channel 3: new [direct-tcpip]

Subsecond response to request

[2022-03-08 20:11:41] debug2: channel 3: open confirm rwindow 2097152 rmax 32768

[2022-03-08 20:11:42] debug2: channel 3: read<=0 rfd 7 len 0

...

2nd psql request

[2022-03-08 20:11:42] debug1: Connection to port 5430 forwarding to xxx.us-east-1.rds.amazonaws.com port 5432 requested.
[2022-03-08 20:11:42] debug1: channel 4: new [direct-tcpip]

[2022-03-08 20:11:42] debug2: channel 4: open confirm rwindow 2097152 rmax 32768

我曾在这个问题上找过其他人,但没有发现有人在谈论这个问题。我尝试过来自https://jrs-s.net/2017/07/01/slow-ssh-logins/的建议,并将IpQos=0x00设置为解决任何潜在的路由器问题。

EN

回答 1

Server Fault用户

发布于 2022-03-16 12:09:04

问题在于我所使用的服务。Serverless的默认设置是在有5分钟不活动时暂停群集。当一个新连接出现时,服务需要30秒左右才能重新启动。

因此,5分钟后缓慢的连接是Serverless服务重新启动,根本不是SSH问题:-/

票数 0
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/1095698

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档