我已经启动了我的 autossh,轮询时间为 30 秒:
AUTOSSH_POLL=30 AUTOSSH_LOGLEVEL=7 autossh -M 0 -f -S none -f -N -L localhost:34567:localhost:6543 user1@server1
Run Code Online (Sandbox Code Playgroud)
它工作正常:
Sep 5 12:26:44 serverA autossh[20935]: check on child 23084
Sep 5 12:26:44 serverA autossh[20935]: set alarm for 30 secs
Run Code Online (Sandbox Code Playgroud)
但是如果我物理移除网线,这意味着隧道不能再工作了,autossh 不会终止 ssh 守护进程。为什么?我知道如果链接断开,autossh 将无法执行任何操作,但我认为它应该尝试执行以下操作:
check on child ...
)这就是我运行 autossh 的原因:如果隧道出现问题(无论是软件还是硬件问题),它应该尝试重新启动它。相反,它只是在等待 ssh 进程死亡。即使没有希望重新建立连接,它不应该尝试重新启动它吗?
什么样的检查正在做 autossh?只是验证 ssh 是否已启动并正在运行?它不做任何类型的远端检查吗?
根据要求,我添加了 ssh 配置的相关部分:
# (see http://aaroncrane.co.uk/2008/04/ssh_faster)
# The ServerAliveInterval tells SSH to send a keepalive message every 60 seconds while the connection is open;
# that both helps poor-quality NAT routers understand that the NAT table entry for your connection should
# be kept alive, and helps SSH detect when there’s a network problem between the server and client.
ServerAliveInterval 60
# The ServerAliveCountMax says that after 60 consecutive unanswered keepalive messages, the connection should
# be dropped. At that point, AutoSSH should try to invoke a fresh SSH client. You can tweak those
# specific values if you want, but they seem to work well for me.
ServerAliveCountMax 60
TCPKeepAlive yes
Run Code Online (Sandbox Code Playgroud)
小智 18
但是如果我物理移除网线,这意味着隧道不能再工作了,autossh 不会终止 ssh 守护进程。为什么?
autossh 在您的客户端机器上运行,因此它不能直接终止服务器上的 ssh 守护进程。但是,您可以在服务器上为ClientAliveInterval
in指定一个非零值/etc/ssh/sshd_config
(请参阅man sshd_config
参考资料)并重新启动服务器上的 sshd 服务以应用配置更改。然后在网络断开的情况下,ssh 守护进程将在ClientAliveInterval * ClientAliveCountMax
几秒钟后被杀死(但不会被 autossh杀死)。
现在,如果您要问“为什么 autossh 不终止 ssh 客户端进程?” ,您已指定-M 0
. 从 autossh 手册页:
Setting the monitor port to 0 turns the monitoring function off, and autossh will only restart ssh upon ssh's exit
.
您不是使用 autossh 来监视连接,而是等待 ssh 在超时ServerAliveCountInterval * ServerAliveCountMax
几秒钟后退出。您已在 ssh 退出之前请求了 60 次服务器活动检查,其中间隔 60 秒间隔连续检查,因此您将在 ssh 客户端退出前等待一个小时。
您还应该强烈考虑ExitOnForwardFailure
在客户端使用该选项(请参阅man ssh_config
参考资料),以便 ssh 在无法建立隧道时退出,然后 autossh 可以再次尝试启动 ssh。
归档时间: |
|
查看次数: |
12206 次 |
最近记录: |