以前用 autossh 的时候,只是简单的用了一个 -N 参数。结果遇到一开始没联上网或者中途断网都还是起不到重连的作用。

后来在这儿
http://www.oschina.net/translate/automatically-restart-ssh-sessions-and-tunnels-using-autossh
看了才知道原来要加一些参数的。

export AUTOSSH_PIDFILE=/var/run/autossh.pid
export AUTOSSH_POLL=60
export AUTOSSH_FIRST_POLL=30
export AUTOSSH_GATETIME=0
export AUTOSSH_DEBUG=1
autossh -M 0 -4 -N USER@HOSTNAME -D 7070 -o \
"ServerAliveInterval 60" -o
"ServerAliveCountMax 3" -o BatchMode=yes \
-o StrictHostKeyChecking=no
-M 0 的意思在 man 里面是这样写的:

Setting the monitor port to 0 turns the monitoring function off, and autossh will only restart ssh upon ssh's exit. For example, if you are using a recent version of OpenSSH, you may wish to explore using the ServerAliveInterval and ServerAliveCountMax options to have the SSH client exit if it finds itself no longer connected to the server. In many ways this may be a better solution than the monitoring port.

大概意思是这是一种比较好的用法。。
————————————————
版权声明:本文为CSDN博主「leifurong6」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/leifurong6/article/details/42408211

发表评论

邮箱地址不会被公开。 必填项已用*标注