我正在运行一个 autossh 脚本,使用 upstart 为我的 postgresql 数据库建立 ssh 隧道/端口转发。它看起来像这样:
# Remote server role: database-master
# Remote hostname: srv-08.aa.com
# Local/remote port: 5432
# autossh startup Script http://www.async.fi/2013/07/autossh-with-ubuntu-upstart/
description "autossh tunnel for role database-master to srv-08.aa.com:5432"
start on (local-filesystems and net-device-up IFACE=eth0)
stop on runlevel [016]
respawn
respawn limit 5 60 # respawn max 5 times in 60 seconds
exec autossh \
-M 0 \
-N \
-L 5432:localhost:5432 \
-o "ServerAliveInterval=60" \
-o "ServerAliveCountMax=3" \
-o "BatchMode=yes" \
-i /home/the_user/.ssh/id_rsa \
[email protected]
我一般认为转发工作正常。但是有时,例如当远程服务器重新启动 postgresql 服务时,隧道会变得无用(无法通过它连接),并且/var/log/upstart/autossh-master-db-tunnel.log
我看到发出以下错误:
channel 2: open failed: administratively prohibited: open failed
channel 2: open failed: administratively prohibited: open failed
channel 2: open failed: administratively prohibited: open failed
channel 2: open failed: administratively prohibited: open failed
channel 2: open failed: administratively prohibited: open failed
channel 2: open failed: administratively prohibited: open failed
这种情况会一直持续,直到我做了sudo restart autossh-master-db-tunnel
之后一切才会恢复正常。
哪里出了问题?我该如何解决?或者一开始就更聪明一点?