Send_linux 发表于 2013-05-30 09:20

使用 autossh 自动重启 SSH 会话和通道

autossh 是一个用来启动 ssh 并进行监控的程序,可在需要时重启 ssh,例如程序挂掉或者是网络出现问题。其灵感和机制来自于 rstunnel (Reliable SSH Tunnel). autossh 1.2 的方法已经改变:autossh 使用 ssh 来构造一个 ssh 重定向循环(本地到远程和远程到本地),然后发送测试数据并获得返回结果。

autossh 1.3 增加了一个新的方法:可指定远程 echo 服务的端口用于返回测试数据发送结果。这个避免握手阶段以及所有远程机器端口的冲突问题。而老的 loop-of-forwardings 方法依然可用。

在 Ubuntu 上安装 autossh


打开终端窗口并运行以下命令
            
sudo apt-get install autossh
            
Autossh 语法
            
autossh [-V] [-M port[:echo_port]] [-f]
            
在启动时启动 ssh 通道
我们可以使用 upstart 来在 Ubuntu 下启动 ssh 通道,只需要将如下 autossh.conf 文件放在 /etc/init 目录即可。
            
            # autossh startup Script
            description "autossh daemon startup"
            start on net-device-up IFACE=eth0
            stop on runlevel
            respawn
            respawn limit 5 60 # respawn max 5 times in 60 seconds
            script
            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 -i SSH_KEY_FILE_PATH
            end script

   
英文原文:Automatically restart SSH sessions and tunnels Using Autossh


本文来自ChinaUnix新闻频道,如果查看原文请点:http://news.chinaunix.net/opensource/2013/0529/2785792.shtml

东方蜘蛛 发表于 2013-05-30 10:17

板凳:hug::hug:
页: [1]
查看完整版本: 使用 autossh 自动重启 SSH 会话和通道